Created
September 15, 2022 21:42
-
-
Save thyngster/188c8cc667a6f9883f044c14195d6aa6 to your computer and use it in GitHub Desktop.
Grab GA4 "linkerParam"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var getGa4LinkerParam = function() { | |
try { | |
if (!window.google_tag_data || !window.google_tag_data.glBridge) | |
return; | |
var cookies = {}; | |
('; ' + document.cookie).split('; ').forEach(function(ck) { | |
var name = ck.split("=")[0]; | |
var value = ck.split("=")[1]; | |
if (name && value && name.match(/^_ga$|^_ga_[A-Z,0-9]/)) { | |
cookies[name] = value.match(/[A-Z,0-9]\.[0-9]\.(.*)/)[1]; | |
} | |
if (name && value && name === "FPLC") { | |
cookies["_fplc"] = value; | |
} | |
}); | |
return "_gl=" + google_tag_data.glBridge.generate(cookies) | |
} catch (e) {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment