Tracking Persistent User Data Across Your Website with Cookies

by | Mar 26, 2019 | 0 comments


Google Tag Manager

How to setup your own personal cookie to store important marketing related information about the website visitor.

In moments that could only be described as Deja Vu I came across a solution to a problem I was having and it turns out – I’m not the only one who was having that kind of problem. I was sending website traffic to one of many of the company’s websites from a paid platform and I was not getting the conversion return that I expected. I tested, changed, and tweaked for weeks finding a new low in my acquisition confidence when I tried explaining the situation to a friend of mine.

He very meekly invited me to explain what I was doing and I gave him the ELI-5 treatment (explain it like I’m five years old). As the words came out of my mouth I realized that I was not tracking website visitors who navigated away from my landing page. I mean, they were tracked, but they weren’t attributed. I knew about Google’s multi-channel tracking capabilities and decided to see what the report would hold.

If I had a screen shot of that report it would look like a rainbow because all of the channels were color coded and my user reports were all over the place (in terms of channels). [See an example below from the Demo analytics account]

I remember that the top converting channel combination was simply, “Direct” and after that it was an average of 9 channels per conversion. I was in the, “Assisted Conversions” report and saw that although my advertisements were fighting to break even in the first month from last-click conversions they were more then carrying their weight by assisting future conversions.

So Google knows in one of it’s reports that my paid ads are generating conversions but not always in the ‘last-click attribution’ window of time. Using this information I realized that on average (at least 9 channels worth) I could get a conversion from nine interactions. Not that any of those nine conversions were valuable but it did tell me that my paid channels were generating value and I wanted that information passed into my CRM.

Here was the problem: how do I store and pass marketing attribution data into my CRM from those channels that simply assisted in the conversion to prove their value?

So let’s break this down into the elements of the question that we would need to solve for in order to correctly answer it:

  1. How do I store marketing attribution data from the varying channels?
  2. How do I pass that data into my CRM?
  3. How can I make sense of the data to award credit to the proper channels in order to prove the worth of my paid acqusition efforts?
where utm parameters go

“How do I work with this in my situation?”

The first element to solve is to figure out how to store marketing attribution data from varying channels. There are likely many ways to solve this but I will show you how to create your own cookie in order to accomplish it that way. GDPR does not want anyone storing PPI data but the beauty of this is that you can store data related to the channels (UTM values) and this does not necessarily constitute PPI data. As long as you aren’t storing data that can lead back to a single customer you are not violating GDPR (call me on this if I’m wrong?).

So what information do we want to store?

Staying away from PPI we only need to store data right above the consumer level and the UTM parameters are exactly right above that. In terms of granular data I would use the UTM basics: the Campaign, the Source, the Medium, the Content (Ad Group/Ad Set), and the Keyword. None of those have PPI data in them as long as you do not add it yourself. In addition to the UTM parameters you will want to store this differently in your CRM by loading the values into fields in your CRM that correspond to the first time that those values were created and possibly the most recent time they were collected.

For example if the fields are empty, then populate them with the UTM values (call it first campaign, or first source, etc), however… if they are populated then populate another field (call it last campaign, or last source, etc) and append the value there regardless of there being a value in that field.

Here’s what you will be storing (feel free to customize this to however you want):

  • utm_campaign
  • utm_source
  • utm_medium
  • utm_content
  • utm_term
  • gclid
  • msclkid

The values with ‘utm’ in them will denote the UTM values each time the data is detected and the cookie is created. This will create the effect of a last-click attribution model. Every time a user visits from a different channel with UTM values in the url the values will update. You could forseeably add any data from a web visit or from a web parameter that you wanted but make sure you clean up your urls in Google Analytics with filters (that’s for another blog article).

Here’s what you need in order to store this data in a cookie:

  • Google Tag Manager with admin access.
  • The code scripts, variables, and any relevant tags published in GTM to deploy this.
  • I also recommend a preview environment in order to test it.
where utm parameters go

Custom Cookie Installation Instructions:

  1. Login into the correct Google Tag Manager.
  2. Enter the appropriate container (like a property).
  3. Create a new tag.
  4. Set the trigger to fire across ‘All Pages’ (unless you need a specific page-case).
  5. Set the tag configuration to be a Custom HTML tag type.
  6. In the HTML whitespace, you add the code below.
  7. Name the tag to comply with your taxonomy structure in GTM and Save it.
  8. At the top, click preview and then view the website where your container will fire.
  9. In the web page, at the bottom (by default) you will see the preview mode, and make sure you see your tag name in the list of Tags Fired on This Page.
  10. Next, tap the F12 on your keyboard (on windows) or open up the developer console (I’m using Google Chrome). Then hit the tab for Application, and on the left open the view for Cookies and select your domain.
  11. When you look at the alphabetical list on the right you won’t see your utm fields and values… wait why? Because you must put the utm parameters into the url.
  12. Now, try reloading the URL but first add the following parameter text to the end of your page’s URL (?utm_campaign=test) so it will look like (
  13. Now when you scroll down in the application > cookies > domain view on the right you should see the field of utm_campaign and on the right of it, the value of ‘test’ – you did it!
  14. Back in Google Tag Manager you can save or play around before you finally publish the changes to your live site.
  15. Last, if you have a requirement to tell your visitors what data you collect, make sure you consult with your legal team what you need to add to your privacy policy and cookie policy.
where utm parameters go

Step 2: Collecting that data from cookie and storing it into your CRM

I can’t begin to know what CRM you use or if you even are using a CRM (you know who you are) but if you have digital conversions such as form fills, phone calls, chats, etc then you can collect this information. At the moment of filling out a form, making a call, initiating a chat, or whatever is the point where the data you have been storing in the cookie will be associated with that conversion.

I cannot cover a how-to for every type of conversion but I will detail the form because it’s the simplest and can be applied to the other conversion methods depending on what you do. You will capture this information using hidden form fields that will pull the data out of the cookie and store the information into your CRM at the point that the form is submitted. I would also make sure to add the information you are gathering to your privacy policy or at least make a mention below the form that you are gathering marketing data for the purposes of serving them a better experience.

Some form builders have built-in tools to pull data from a cookie or proprietary methods to get data that could require customized javascript or jquery (I just have the basics). For example I know Marketo has a hidden field that can pull from the cookie which makes it very easy for you to set this up. If you use HTML or have form fields that can be populated from a jquery snippet (and your web page accepts those languages) then you can use this method:

Add this script to your form, page, or to your form/landing page however you can:

$('input[name=INSERT FIELD NAME]').val($.cookie("INSERT COOKIE NAME"));

Step 3: Making sense of all this data to paint a better picture of multi-channel attribution

The use cases are many, bringing me back to my Deja Vu. In the past few years since I figured this out I’ve run into dozens of fellow marketers struggling with a problem that this could solve. Not every solution ended up with them slapping together their own cookie but it was relief for them to figure out that there was a solution if they are willing to go through with it.

So here’s my warning: don’t make this, set this up, and then forget about it. You need to have an applicable use case for how you are going to use the data. Even if I tell you, this is amazing if you do it because it helped me do X, Y, or Z… you still need to know how it’s going to benefit you.

Knowing the attribution of your conversions is only half the picture. The other half is how you can impact the conversion for your higher-value customers. You should use this data to help you better understand the differences in your customers. Do not use the data to look at your customers in aggregate without considering that your customers fall into different segments. Users that turn into high-value, long retention, and high frequency buyers will be your best customers and so spend the effort (extra effort required) to understand them and where they come from.

Slice your customer data by value segments or retention segments and then take a look at your attribution channels to see what you find.

Optional Cookie Code I’ve Seen:

Why use the datalayer? You could use the datalayer across domains… and there are other reasons if you want to dig around.

Kevin Profile Shot

Kevin Dieny

Marketing Professional

Here is a great resource for you if you want to learn more about the DataLayer:

Tracking Persistent User Data Across Your Website with Cookies
Article Name
Tracking Persistent User Data Across Your Website with Cookies
How to setup your own personal cookie to store important marketing related information about the website visitor
Publisher Name
Firm Fixed Ideas
Publisher Logo