Google Analytics UserID Tracking Code - google-analytics

I'm setting up UserID tracking in Google Analytics. Google's documentation displays this piece of code to push UserIDs into analytics:
ga('create', 'UA-XXXX-Y', { 'userId': 'USER_ID' });
ga('send', 'pageview');
However, when I'm in my Google Analytic's settings area, it displays the following piece of code to include UserIDs.
ga(‘set’, ‘&uid’, {{USER_ID}}); // Set the user ID using signed-in user_id.
What is the difference between set and create? Do they both achieve the same result?

Both of them should work. Including the user id in the 'create' call includes setting it as well.
ga('create', 'UA-XXXX-Y', {'userId': 'USER_ID'});
ga('send', 'pageview');
is equivalent to
ga('create', 'UA-XXXX-Y');
ga('set', '&uid', {{USER_ID}}); // Set the user ID using signed-in user_id.
ga('send', 'pageview');
If you do copy and paste provided in GA, then you will need to change the smart quotes to straight quotes, because smart quotes will break GA.

Related

why form submit data in Google Analytics and how to remove it?

I wonder why GA is tracking this link:
/de/shop/pizza.html?tx_pizza_basket[action]=addToCart&tx_pizza_basket[controller]=Basket&cHash=fae9b7812f842f543hgf0ac374e9a978ca0
This URL (domain is removed here so it's not the full path) opens the basket with some pizzas added to it :)
I wonder why GA is tracking this exact path and how to stop GA from tracking this sort of form submit URLs.
Here is my GA Code:
# JavaScript für Google Analytics
temp.google.analytics = TEXT
temp.google.analytics.value (
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-87654123-1', 'auto');
ga('send', 'pageview');
</script>
)
Regards,
M.
By default, Google Analytics records the value of document.location.href when it is executed. If you don't wish to record the URL parameters for this page, you have 2 options:
Create a set of advanced filters for the reporting view that excludes parameters tx_pizza_basket[action] and tx_pizza_basket[controller]. Additionally set your view's Exclude URL Parameters setting to include cHash
For this particular page, change ga('send', 'pageview') to ga('send','pageview', document.location.pathname)

Google analytics userId configuration

currently want to track unique users in GA (remember their session, etc). Having the problem of where to place the userId code inside the tracking code?
Is it correct to place it in between create and send? or does it matter? will it have a negative effect if I place it before create or after send?
ga('create', 'UA-XXXXX-Y', 'auto');
ga('send', 'pageview');
Beginner level with GA.
You can put it in the create command via the optional fieldsObject, or you can set it on the tracker after it's created (but before the pageview is sent).
You cannot put it before the create command, and if you put it after the pageview is sent, it'll be too late and won't apply to that hit.
In other words, either of these two variations will work:
ga('create', 'UA-XXXXX-Y', 'auto', {userId: USER_ID});
ga('send', 'pageview');
or:
ga('create', 'UA-XXXXX-Y', 'auto');
ga('set', 'userId', USER_ID);
ga('send', 'pageview');

Cross domain tracking (universal analytic) is not working

We tried to implement auto link cross domain but it doesn't seems to work. Here is the case:
We have 2 different domains:
source.com
destination.com
When user visits source.com and click on Submit button, he is automatically redirected to the destination.com (the redirection is on the server side and not the client).
We want to have the ability to track the user action on both domains and treat it as the same user.
We have the following code on the source.com domain:
ga('create', 'UA-XXXXXX-X', 'auto', {'allowLinker': true});
ga('create', 'UA-XXXXXX-X', {'name': 'newTracker'});
ga('newTracker.send', 'pageview');
ga('send', 'pageview');
ga('require', 'linker');
ga('linker:autoLink', ['destination.com'], true, true);
And this code on the destination.com domain:
ga('create', 'UA-XXXXXX-X', 'auto', {
'allowLinker': true
});
ga('send', 'pageview');
This code is not working. we tried to use the same UA id for both but the client id seems to change between the domains and therefore I move from source.com to destination.com I see in analytics 2 different users.
We also tried to pass ourselves the _ga parameter but it also doesn't seems to work
Can anyone please advice? We can't understand what we are doing wrong.
It can be great if you can show an example code and not just reference (:

Tracking Visits on a Roll Up Account with Google Analytics Universal

I am just looking for some help setting up a single view of all the sites we have. I can find lots of help for the old analytics tracking code but not for the new universal analytics.
I've got 5 sites each with their own tracking code in place but i'd like to create a roll up account that allows me to look at an overview of all the sites in a single view. Just wondering what i need to add to the code to do this?
It's currently;
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXX', 'auto');
ga('require', 'linkid', 'linkid.js');
ga('require', 'displayfeatures');
ga('send', 'pageview');
</script>
And I would just like to know what i need to add in to be able to include the numbers in a roll up account too? I think it's possible to simply edit this code with the UA of the roll up account but I'm not sure of the correct way to format this.
Any help would be appreciated,
Thanks
Roxi
It works rather like it did with asynchronous analytics, only you pass the name of the tracker in the (optional) configuration object:
ga('create', 'UA-XXXXX-X', {
'name': 'firstTracker',
});
ga('create', 'UA-XXXXX-Y', {
'name': 'secondTracker',
});
ga('firstTracker.send', 'pageview');
ga('secondTracker.send', 'pageview');
Any other options (e.g cookie domain, which is the third parameter if you don't use a configuration object) are set as key-value pairs in the configuration object. You find this in the documentation under Advanced Configuration.

Is it possible to update the google Analytics Tracking object?

I create a google analytics tracking object like this:
ga('create', 'UA-10303525-4', 'auto'); // Replace with your property ID.
ga('send', 'pageview');
Later on, without loading the page, I want to update the tracking object with a userID:
ga('create', 'UA-10303525-4', { 'userId': response.data });
This doesn't seem to work. Is it possible to update or destroy/recreate the tracking object somehow?
You might try the set method.

Resources