Redirection

 

Foreword

Before starting your implementation, please make sure you have initialised the AT Internet JavaScript Tracker and selected your chosen plugins from within the Tag Composer interface.

 

Principle

Placing a redirect tag on a site involves tagging the page which carries out the redirection (and which is normally transparent) in order to enable the retrieval of data, such as the page preceding the page to be displayed.

Several methods can be considered, depending on your site’s possibilities and setup. Here, we’ll look at a case in which the site’s home page is an automatic redirection (JavaScript) to a specific page.

 

Tagging

 

Configuration

Redirect tagging is done via the configuration during initialisation:

var tag = new ATInternet.Tracker.Tag({redirect: true});
  • The “redirect” variable allows for the forcing of the redirect mode (true: mode enabled, false: mode disabled; false by default).

In order for the preceding page to be effectively processed, you must have already selected the Contextual information plugin ahead of time from within the Tag Composer interface. Other data can be processed in the same way as the preceding page, such as identified visitor data, or campaign ROI data. Depending on your measurement needs, you must add the plugins Identified Visitors and Campaigns to the Tracker.

All data collected on the redirect page is saved in cookies whose lifetime is limited to 30 seconds by default (adjustable). These cookies are then processed automatically on the destination page containing the tagging code with the corresponding plugins.

 

Redirect method

The Tracker contains a “setLocation” utility method enabling you to carry out a redirect.

var tag = new ATInternet.Tracker.Tag({redirect: true});
var contextObj = {
    location: 'final.html',
    target: 'target'
};
ATInternet.Utils.setLocation(contextObj);

To use this method, you must replace the ‘home.html’ value with the URL of your homepage, and replace the ‘target’ value with the desired HTML tree level (‘document’, ‘parent.document’, etc.).

 

Redirection to a different domain name

This particular case requires a technical implementation on the page carrying out the redirect. As the domain names are different, the redirect cookies will not be readable from the destination page.

You must therefore find a way to transmit the desired variables in the URL of the called page. The transmitted parameters will be processed by the Tracker present on this page.

Example

var getQueryString = function (name) {
    var href = document.location.href;
    var reg = new RegExp( '[?&]' + name + '=([^&#]*)', 'i' );
    var string = reg.exec(href);
    return string ? string[1] : '';
};
var atref = '?xtref=' + document.referrer;
var ator = '&xtor=' + getQueryString('xtor');
var atat = '&xtat=' + getQueryString('xtat');
var atan = '&xtan=' + getQueryString('xtan');
document.location.href = 'http://site.html' + atref + ator + atat + atan;

It is not necessary to insert the tag code.

 

Was this post helpful?

Last update: 30/01/2018