Skip to content

Instantly share code, notes, and snippets.

@thyngster
Created September 15, 2022 21:42
Show Gist options
  • Save thyngster/188c8cc667a6f9883f044c14195d6aa6 to your computer and use it in GitHub Desktop.
Save thyngster/188c8cc667a6f9883f044c14195d6aa6 to your computer and use it in GitHub Desktop.
Grab GA4 "linkerParam"
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