Forwarding Tracking Cookies Between Different Domains

THIS ARTICLE WILL HELP YOU:

Understand Tracking Cookies and Different Domains or Devices

When there are multiple domains or devices where a test needs to run or where the conversions need to be tracked, things get a little bit complicated. A common scenario would be when you have pages spread across two domains. You have the main site that hosts all the products but the actual checkout happens on another domain.

In this situation, without forwarding the convert cookie data to the checkout domain, the conversions will not be tracked.
Cookies that are stored and accessed under a specific domain cannot be accessed from a page hosted on another domain. Therefore, the cookie data has to be passed along when leaving one domain and going to the other one. Convert Experiment does this by default when it finds page links for the domains listed on the Active Domains in the Project Settings and form submissions between the domains inside the same projects. This is done on document ready by modifying the submit and click handlers for forms and links respectively. Sometimes, due to dynamic content being added via JavaScript, this process does not work and the site owner needs to pass the convert cookies inside their scripts. 

There are two cookies in which data has to be passed as GET or POST parameters to the page in the other domain.

  • _conv_v - is the visitor level cookie that holds data that describes visitor's activity
  • _conv_s - session level cookie;

Their data needs to be passed in the URL as GET parameters, under the same names. To get their value, we make the following available:

convert.getCookie(name);

If the outgoing URL is http://www.mysite.com/,page.html then the final destination URL, put together with JavaScript code, would be something like this:


"http://www.mysite.com/page.html?_conv_v="+encodeURIComponent(convert.getCookie("_conv_v"))+"&_conv_s="+encodeURIComponent(convert.getCookie("_conv_s"))

Of course, the destination page needs to have converted the experiment's code installed correctly for this to work.

When the form cannot be modified but you can add hidden fields

There are occasions when the jump from one domain to another is done via a form submission. To transfer the cookie data, it can be passed via hidden form inputs. This is usually done automatically. However, when this does not happen automatically you can modify the form to add this information to hidden input fields. The code can be added via the Experiment Global Javascript, the Project Global Javascript, or through a Custom Javascript of a Deploy experience targetted to the form page. 

The code that you add can be the following:

convert.$( document ).ready(function() {
convert.$("<input>").attr({ name: "_conv_v", type: "hidden", value: (convert.getCookie('_conv_v'))}).appendTo("form.header-booking-form");
convert.$("<input>").attr({ name: "_conv_s", type: "hidden", value: (convert.getCookie('_conv_s'))}).appendTo("form.header-booking-form");
});

When the form cannot be modified but you cannot add hidden fields. 

The only way to do this would be to transfer the cookie data via query parameters by calling a page on the second domain on an iframe when the page on the first domain loads. The only disadvantage with this approach is that a page visit to the page loaded in the iframe will be displayed every time they land on the form. Also, the first-page hit will load both pages' resources. 

The following code can be added via the Experiment Global Javascript, the Project Global Javascript, or a Custom Javascript of a Deploy experience targetted to the form page.

convert.$( document ).ready(function() {
convert.$('<iframe src="https://seconddomain.com/page1.html?' + '_conv_v=' + escape(convert.getCookie('_conv_v')) + '&_conv_s='+ escape(convert.getCookie('_conv_s')) + '" frameborder="0" scrolling="no" id="myFrame" style="display:none;"></iframe>').appendTo('body');
});