-1

I want to store the Referer in a cookie (using GTM) so that I can recall this on my lead form and input the information into a hidden field so the info is stored on my CRM.

I want the referer to provide the Full URL

I want the information to be saved on the first visit and not overwritten as they navigate the website.

I need help with the GTM part and writing this information into the Cookie and not overwriting it with every new page that's loaded on our site.

Sabeel
  • 13
  • 2
  • https://stackoverflow.com/help/how-to-ask – Matus Apr 23 '18 at 11:34
  • Hi Sabeel, I removed the unnecessary bits from the question - rules on stackoverflow strongly suggest to get straight to the point and dispense with any pleasantries (also the happy days when search engines transmitted the keyword in the referrer are long past). – Eike Pierstorff Apr 23 '18 at 13:33
  • Thanks, Eike for the update / tidying it up! I removed a couple extra bits as you mentioned they weren't possible. – Sabeel Apr 23 '18 at 15:18

2 Answers2

0

You can check document.referrer - if it does not contain the hostname of your own site then you are on a landing page (something like if document.referrer.indexOf('mydomain.com') == -1).

That way you can (reasonably well) determine if this is the first page in the visit, in which case you trigger the tag that sets the cookie.

This is not 100% foolproof, since technically browsers are under no obligation to provide a referrer (also it can be easily spoofed), but AFAIK it works on all major browsers, I don't think there is a better way, and it's quite easy to implement.

Eike Pierstorff
  • 31,996
  • 4
  • 43
  • 62
0

Lunametrics have created a brilliant way of recreating he utm cookie which will help you store all of this information. Just upload the details in to your GTM

https://www.lunametrics.com/labs/recipes/utmz-cookie-replicator-for-gtm/

Im not attributed to them in any way