Skip to content

Help Center

Pull attribution data from the cookie

There are times when adding hidden fields to your forms isn’t the best approach for getting the attribution data from Attributer and into your CRM or database.

A common example of this is when you have a signup or registration form for a website or application that has social signin options (I.e. those buttons that allow you to signup to a website with your Facebook or Google account).

In this case, it’s possible to write some simple code to pull the attribution data from the cookie and pass it through to your CRM, database, etc as part of the signup flow.

How to access the attribution data stored in the cookie

On any page with the attribution script loaded you can access the attribution data in Javascript by using the document.FlareTrk.data attribute 

This has all the data usually accessible through hidden form fields. The structure is as follows:


 document.FlareTrk.data = {
   "firstVisitDate": DateTime,
   "referrerURL": URL,
   "landingURL": URL,   "lastReferrerURL": URL,
   "lastLandingURL": URL,
   "lastViewedURL": URL,
   "drillData": {
       "channel": string,
       "drillDown1": string,
       "drillDown2": string,
       "drillDown3": string,
       "drillDown4": string
   },
   "lastDrillData": {
       "channel": string
   },
   "landing_page_group": string
   
}


The information you’ll need to extract from the cookie is as follows:

Attributer Property NameField in Attribution Cookie
Channel“channel”: string,
Channel Drilldown 1“drillDown1”: string,
Channel Drilldown 2“drillDown2”: string,
Channel Drilldown 3“drillDown3”: string
Channel Drilldown 4“drillDown4”: string
Landing Page“landingURL”: URL,
Landing Page Group“landing_page_group”: string

Example Code

To help you get started, we have put together some sample Javascript code that extracts the data from the cookie and writes it into the console. You should be able to use this code as a starting point and customize it to send the data to wherever you require it.

(() => {
function waitForData() {
// Wait for data to be ready
if (!document.FlareTrk?.data) {
return window.requestAnimationFrame(waitForData);
}

// Channel and drill down data
console.log("channel: ", document.FlareTrk.data.drillData.channel);
console.log("drilldown1: ", document.FlareTrk.data.drillData.drillDown1);
console.log("drilldown2: ", document.FlareTrk.data.drillData.drillDown2);
console.log("drilldown3: ", document.FlareTrk.data.drillData.drillDown3);
console.log("drilldown4: ", document.FlareTrk.data.drillData.drillDown4);

// Id Data
console.log("gclid: ", document.FlareTrk.data.gclid);
console.log("fbclid: ", document.FlareTrk.data.fbclid);
console.log("id: ", document.FlareTrk.data.id);

// Landing page data
console.log("landing_page", document.FlareTrk.data.landing_url);
console.log("landing_page_group", document.FlareTrk.data.landing_page_group);

// Custom data
for (var dp = 0; dp < document.FlareTrk.settings.customFields.length; dp++) {
const key = document.FlareTrk.settings.customFields[dp];
console.log(key + ": ", document.FlareTrk.data["customFields"][key]);
}
}
waitForData();
})();

Can't find the answer you need? Contact us!

Our team are available to answer any questions you have

Support Images