Some website have multiple Google Analytics tracking scripts running at the same time. With this script you can define the specific tracking ID to capture the correct Google Client ID.
Our default script assumes there is only a single GA tracking ID installed on your website. With the script below you can specify the tracking ID you would like to capture the client id for if you are running multiple properties.
Ensure that you replace the tracking ID (UA-111111111-1) with the specific one you want to target:
<!-- START Google Client ID Capture analyticsamplifier.io -->
<script>
//Get the Google Client ID
function getClientId() {
try {
var trackers = ga.getAll();
var i, len;
for (i = 0, len = trackers.length; i < len; i += 1) {
if (trackers[i].get('trackingId') === "UA-111111111-1") {
return trackers[i].get('clientId');
}
}
} catch(e) {}
return '';
}
window.onload = function() {
var clientId = getClientId();
document.querySelector("input[name='google_client_id']").value = clientId;
if (window.jQuery) {
var $=jQuery.noConflict();
$('input[name="google_client_id"]').val(clientId).change();
}
};
</script>
<!-- END Google Client ID Capture analyticsamplifier.io -->