Press enter to see results or esc to cancel.

How to remember visitors’ parameters

Sometimes you may want to display or hide ads (or show some content) when the visitor comes from a specific website (direct visit, search engine, Facebook, ad campaign, …). This can be easily configured using black or white lists (using referrer or url parameter for example). However, this will normally work only for the first page visited. When the visitor will click any link on your website, the referrer will become the current page and any url parameter in the url will be lost. However, this can easily be solved with a cookie in which you can save the status. Here we’ll show an example on how to use a cookie to remember visitor’s status: referrer, url parameter or any other value specific to the visitor.

For this example we’ll use two blocks. The first one will be used to create a cookie when specific conditions are met – in this case we’ll disable ads for direct visitors (no referrer):

<script>
  var hours = 1;
  var date = new Date();
  date.setTime(date.getTime() + (hours * 60 * 60 * 1000));
  document.cookie = 'ai-hide-ads=1; expires=' + date.toUTCString () + "; path=/";
</script>

This Javascript code is inserted in the page Footer (and executed) only when there is no referrer (# in the referrer list is whitelisted). The code creates cookie named ai-hide-ads with expiration time 1 hour. You can adapt the code according to your needs. Alignment is set to No wrapping as this is only (invisible) Javascript code.

ad inserter set cookie

The second block will be the actual ad that will not be inserted for direct visitors. The dummy banner is NOT inserted for direct visitors (blackisted # as no referrer for the first visit when the cookie is not created yet) and when cookie with name ai-hide-ads is present (url query parameter list is used also for cookies).

ad inserter check cookie

The settings can easily be adapted for other purposes. For example, to hide ads for visitors coming with url containing, for example, ad-campaign=facebook url parameter, we only need to change the following:

  • In the first block we need to whitelist url parameter ad-campaign=facebook so the cookie will be created only when coming with this url parameter
  • In the second block (actual ad) we need to blacklist two url parameters (works also for cookies): ad-campaign=facebook,ai-hide-ads – ad-campaign=facebook will hide ad for visitors coming with this url parameter (when the cookie is not set yet) and ai-hide-ads will hide ad for visitors that have this cookie set (which came with the url parameter)