NB!
We now have automatic cross-site tracking in place for Safari, so this script is no longer needed.
NB!
Background and motivation
Apple has introduced domain isolation for both Local Storage and file cache in Safari 7 and up. This effectively stops cross-site tracking of users using the latest Safari browsers on iPhone, iPad and Macs. New users and users that clear their cookies are no longer tracked cross site.
Resolution
The problem of domain isolation can be resolved by redirecting all new users into the cxense.com domain, generating an unique ID there and setting this ID as a first party cookie. This method gives 100% coverage of users in all browsers.
Method break down
-
A new type of tag is added to the <head> part of all pages
-
This tag checks if the browser is Safari and that we have not already done the redirect (redirect status stored in a cookie)
-
If we have not done the redirect and the browser is Safari, the real referrer is temporarily stored in sessionStorage and the browsers is redirected to a webpage on the cxense.com domain.
-
The page on the cxense.com domain tries to read a user id cookie. If it is set, the client is redirected back immediately. If it is not set, create a random id. This is set as a fist party cookie on the cxense.com domain. Finally redirect back to the your page, with a flag indicating that the cookie have been etablished.
-
Your page loads again, and this time the URL includes the redirect to token. The script also reads back the real referrer from sessionStorage and stores its value in cX.documentReferrer.
-
In any other case, the script stores the current referrer document.referrer in cX.documentReferrer, so that in all cases, the real referrer can be read from cX.documentReferrer.
-
At some point later, cx.js loads and a sendPageViewEvent() call is made
-
3rd party cookies will now work because they are set in a 1st party context and read in a 3rd party context.
|
Required changes for other scripts on the page
To get the correct real referrer reported to other scripts on the page, they must be changed to read the cX.documentReferrer instead of document.referrer. This is done automatically by cx.js.
Example on how to update Google Analytics. Add this one line:
|
Minified version of the script
This is the same script as on the top of this page, but it has been minified. In some situations a smaller script is preferred. The same requirements apply;
-
This tag must be placed just after the opening <head> tag for the best user experience and to give precise analytics reports
-
When using this tag, the referrer must be read with cX.documentReferrer (and not document.referrer)
-
The 'tld =' line should be replaced with 'tld="your-top-level-domain"', e.g. 'tld="http://mydomain.com "' to reduce the number of redirects required.
|