Can i set google analytics user id multiple time? - google-analytics

<script async src="https://www.googletagmanager.com/gtag/js?id={{ $account_id }}"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());
gtag('config', 'XXXXX');
</script>
here gtag('config', 'XXXXX'); and $account_id can be same of different?

They have to be the same but you can add other config row with different Property ID (note: the value is Property ID, not Account ID) to send hits simultaneously to several properties.

Related

Google Analytics 4 - persistent values are not sent when configured using the 'set' command

I want to configure an event parameter that will be sent automatically with every event I send to GA4.
Including the page_view event and all other "Automatically collected events".
This is my setup configuration:
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXX"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
gtag('js', new Date());
// Doesn't work!!
gtag('set', {
'parameter_key': 'parameter_value'
});
gtag('config', 'G-XXXXXXXX');
</script>
When I'm using the set command, the param_key event parameter is not sent with any event. It's totally ignored.
However, when I move this object into the config command, it does work:
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXX"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
gtag('js', new Date());
// Works!
gtag('config', 'G-XXXXXXXX', {
'parameter_key': 'parameter_value'
});
</script>
I want to use the set command because I have multiple properties, and I want this parameter to be used for all properties.
Anybody knows why it's not working and how to make it work?
Thanks!

Google Analytics 4 gtag Custom dimension not set

<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXX"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'XXXX',{
'user_id' : 'sfId11111',
'custom_map': {
'dimension1': 'user_type'
}
});
gtag('set', 'user_properties', {
user_type: 'user type from user prop'
});
gtag('event', 'page_view', { 'user_type': 'user type from custom dimension' } );
gtag('send', 'page_view');
</script>
I am trying to pass custom user scope dimensions with Gtag.js (user_type) but this always comes as "not set".
I have added it as a dimension as well as user properties. I have waited a couple of days to reflect the value.. but it always comes as not set
The value is available in Debugger

How to get custom events in GA4

My website is static pages.
Using this gtag.js:
<script async src="https://www.googletagmanager.com/gtag/js?id=G-measurementid"></script>
<script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'G-measurementid'); </script>
Under Admin I turned off the Enhanced Measurement setting "File Downloads" to allow for my custom event.
Using this event handler:
Print this page
But at analytics.google.com my custom event doesn't show. Both Realtime and in next day's report.
You can use this syntax:
gtag('event', 'login', {
'method': 'Google'
});
https://developers.google.com/analytics/devguides/collection/ga4/events

This hit starts a new session, most likely because the client ID changed. where is the mistake?

i have site1 and site2...
in the site1:
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-хххх"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-ххх', {
'linker': {
'domains': ['site1', 'site2']
}
});
</script>
in the site2:
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-хххх"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-ххх', {
'linker': {
'domains': ['site1', 'site2']
}
});
</script>
site1: source domain
site2: destination domain
I have two sessions displayed
displays: This hit starts a new session, most likely because the client ID changed. This is caused by an improper tracking code implementation.
what could be the problem?
You need to add site2 to "Referral Exclusion List" in Google Analytics account for these sites.
Property Settings --> Tracking Info --> Referral Exclusion List

Google Analytics script doesn't send tracking beacons

In jspx file I have js script for tracking sign in providers (user are signing in by email, facebook or twitter).
var statsAnalytics = "${jndiSettings['statsAnalytics']}";
var _gaq = _gaq || [];
_gaq.push(['_setAccount', statsAnalytics]);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
var providerId = '${providerId}';
if (providerId) {
_gaq.push(['_trackEvent', 'Sign in', providerId, 'Signed in with ' + providerId]);
}
After debugging with GA debugger for Chrome I'm getting:
_gaq.push processing "_setAccount" for args: "[UA-xxxxxxx-x]": [VM] ga_debug.js (9935):24
_gaq.push processing "_trackPageview" for args: "[]": [VM] ga_debug.js (9935):24
Track Pageview [VM] ga_debug.js (9935):24
_gaq.push processing "_trackEvent" for args: "[Sign in,facebook,Signed in with facebook]": [VM] ga_debug.js (9935):24
Track Event
Why doesn't my script send tracking beacons?
I disabled blocking adds with AddBlock and now it works!

Resources