Reputation: 63
How to set client Id from URL "site.com/?clientId=1576731351.1495454236"
I try to use in
ga('create', 'UA-XXXXX-Y', 'auto', {
'clientId': getClientIdFromUrl()
});
But error:
Uncaught ReferenceError: getClientIdFromUrl is not defined
How to set clientId? How to define getClientIdFromUrl? I get this code from official google page https://developers.google.com/analytics/devguides/collection/analyticsjs/cross-domain#setting_the_client_id_on_the_destination_domain
Upvotes: 1
Views: 1442
Reputation: 22832
This seems to come straight from the example on the comm docs. This function is not defined you are supposed to define it yourself. Here's an example definition from this other StackOverflow question.
function getClientIdFromUrl() {
var url = window.location.href;
var regex = new RegExp("[?&]clientId(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
That being said this is fairly unusual in Google Analytics implementations. You haven't shared much about your use case, but if all you are trying to do is pass clientIds from one domain to the other I would instead take a look at the Linker plugin.
Upvotes: 3