Skip to content

Instantly share code, notes, and snippets.

@smhmic
smhmic / allowlinker-ga.js
Last active October 22, 2020 00:26 — forked from sahava/allowlinker-ga.js
This script reproduces Google Analytics' (analytics.js) allowLinker/autolinker logic, resulting in a function that returns the GA client id, but only if the autolinker parameter is valid. Uses the "old" linker plugin format. You can also pass a string as an argument to check if that string is a valid linker parameter.
// Mirrors analytics.js logic to validate autolinker param, and returns cid if valid.
// Returns false if autolinker param found, but invalid.
// Otherwise returns undefined.
var getCidFromAutolinker = function(str) {
var joiner = function (cidGid, offset) {
var a = new Date,
b = window.navigator,
c = b.plugins || [];
var d = [cidGid, b.userAgent, a.getTimezoneOffset(), a.getYear(), a.getDate(), a.getHours(), a.getMinutes() + offset];