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 ("google.com", "bing.com") as a tag using add_tags:
Retreaver.configure({ host: 'api.routingapi.com', prefix: document.location.protocol == 'https:' ? 'https' : 'http' }); var campaign = new Retreaver.Campaign({campaign_key: 'YOUR_CAMPAIGN_KEY'});
// Get the referrer domain, for ex: 'google.com', 'bing.com', etc
function referrerDomain() {
var url = domain.referrer;
return url.split('/')[2];
}
campaign.request_number(function (number) {
// Store referrer domain as a tag
number.add_tags({
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.
Comments
Please sign in to leave a comment.