Due to this solution you will be able to identify one user through unlimited number of sites you own. Every user will receive unique client-id first time he/she/it visits your site. When you assign the user unique user-id from your database/CRM/eshop, you will be able to identify the same user on all your sites.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
LICENSE
README.md
parent.html
readme.pdf
uniqueid.html

README.md

Cross-browser-UserID-and-ClientID-solution-for-Google-Tag-Manager

Due to this solution you will be able to identify one user through unlimited number of sites you own. Every user will receive unique client-id first time he/she/it visits your site. When you assign the user unique user-id from your database/CRM/eshop, you will be able to identify the same user on all your sites.

How it works?

There are two files: parent.html and uniqueid.html (child). Child script is included in the parent as <iframe>. Due to window.postMessage() parent and child can communicate. Child script checks variables, create value of client-id, create and maintain cookies and send dataLayer value to parent. When values are sent, trackid event is fired.

  • First time user comes to any of your sites, cliend-id is assigned. Client ID is created from random number + timestamp + another random number. This ID is sent do dataLayer. You may use it in Google Tag Manager or anywhere else.
    Client ID
    Value is saved in cookie and loaded next time user visits the site.
  • When user visits a site and the site provides user-id, both client-id and user-id is sent to dataLayer. User-id is created as given user id + actual hostname
    User ID

That's all! Easy and working.

Limitations and possible problems

This solution has not been tested enough. It contains many conditions for several situations. Such as how should the script react if user-id is not set-up, how to react for the first time user-id is provided, how to react second and more times user visited the site etc. Script has not been tested on a heavy traffic website or on various types of mobile devices and browsers. The most testing was made in Google Chrome on desktop. If you notice any problem, please let us know on GitHub.

Debugging

You can use any tool that can read JavaScript variables and cookies, e.g. WASP, Chrome console or Google Tag Assistant for dataLayer.

Try demo at https://resources.marketingmakers.net/useriddemo/parent.html

Credits and Licence

This solution is published with courtesy of SvetZitrka.cz to whom the solution was originally created. Thank you for the permission! The solution was created by Marketing Makers, Czech performance marketing agency.

Feel free to use, change and replicate the solution. Please, always keep the credits of SvetZitrka.cz and MarketingMakers.net

Updated: 10/15/2016