AudienceTargetingBundle ======================= If you want to display different content on the same URL based on some characteristics of the visitor, you can use the AudienceTargetingBundle for that. It allows the content manager to define the audience target groups on his own. Each target group has one or multiple rules, which are used to determine the target group of the visitor. Installation ------------ Enable the bundle in `app/AbstractKernel.php`: .. code-block:: php 0) { set req.url = req.http.X-Sulu-Original-Url; unset req.http.X-Sulu-Original-Url; } unset req.http.Cookie; } sub vcl_deliver { if (resp.http.X-Sulu-Target-Group) { set req.http.X-Sulu-Target-Group = resp.http.X-Sulu-Target-Group; set req.http.Set-Cookie = "_svtg=" + resp.http.X-Sulu-Target-Group + "; expires=Tue, 19 Jan 2038 03:14:07 GMT; path=/;"; return (restart); } if (resp.http.Vary ~ "X-Sulu-Target-Group") { set resp.http.Cache-Control = regsub(resp.http.Cache-Control, "max-age=(\d+)", "max-age=0"); set resp.http.Cache-Control = regsub(resp.http.Cache-Control, "s-maxage=(\d+)", "s-maxage=0"); } if (req.http.Set-Cookie) { set resp.http.Set-Cookie = req.http.Set-Cookie; header.append(resp.http.Set-Cookie, "_svs=" + now + "; path=/;"); } } Finally you have to make sure that the bundle is correctly recognized by Symfony. This includes the following steps: * Clear the Symfony cache with the `cache:clear` command or manually deleting the cache folder * Rebuild the translations with the `sulu:translate:export` command * Install the new assets using the `assets:install --symlink` * Make sure that the users the feature should be enabled for have the correct permissions Manually set target group ------------------------- Sulu will try to determine a matching target group based on the rules the content manager defines. But it is also possible to set a target group manually. That might be useful if you want to divide visitors into separate target groups based on some behavior, e.g. filling out a form, starting a download, etc. Therefore we have introduced the `TargetGroupStore`. You can simply call its `updateTargetGroupId` method and Sulu will do the rest for you. This would like this in an action of a Controller: .. code-block:: php get('sulu_audience_targeting.target_group_store') ->updateTargetGroupId($targetGroupId); } } .. note:: The target group that will be set manually should have quite a high priority, otherwise another higher prioritized target group might override that based on its defined rule. Create custom rules ------------------- The cool thing about target groups are the rules you can define on them, which will automatically evaluated by Sulu. There are a few rules built-in, like a referrer rule, browser rule or a page rule. However, you might still have a very specific use case, which requires to implement your own custom rule. Luckily this possibility is also built-in into Sulu. First of all you have to write your own implementation of the `RuleInterface`: .. code-block:: php .. note:: Mind that the `alias` of the tag has to be unique. .. _Symfony Cache: http://symfony.com/doc/current/http_cache.html .. _Varnish: https://www.varnish-cache.org/ .. _varnish-modules: https://github.com/varnish/varnish-modules