How to track referrer as a tag in Retreaver.js? (,, etc)

In order to track the website your visitors are coming from as tags you'll need to use the 'advanced' code block for Retreaver.js.

The first step is getting the referring URL. This example will fetch the directly referring URL using document.referrer and save just the domain part ("", "") as a tag using  add_tags:

        host: '',
        prefix: document.location.protocol == 'https:' ? 'https' : 'http'

    var campaign = new Retreaver.Campaign({campaign_key: 'YOUR_CAMPAIGN_KEY'});

// Get the referrer domain, for ex: '', '', etc
function referrerDomain() {
var url = domain.referrer;
return url.split('/')[2];
campaign.request_number(function (number) {
// Store referrer domain as a tag
referrer: referrerDomain(),
}); });

Note: A more advanced implementation might want to track the original referring URL as a cookie as soon as the visitor arrives to your website. This allows the user to visit other parts of your website before reaching a particular landing page, while still keeping track of the source URL.

0 out of 0 found this helpful



Please sign in to leave a comment.