Two Google Analytics Codes - both not collecting correctly - google-analytics

I have inherited a site which has two GA-UA codes.
These are setup like this
// first code
ga('create', 'UA-XXXXXXXX-1', 'auto');
ga('send', 'pageview');
//second code
ga('create', 'UA-XXXXXXXX-1', {'name':'second'});
ga('second.send', 'pageview');
I have no idea why they are setup like this and indeed do not understand the syntax of the second tracking code
The following can be observed
THE FIRST CODE
Custom events working and being successfully collected
Linked successfully to Adwords
Only has a few months of data and therefore we don't want to use this
THE SECOND CODE
Does not record custom events
Can't link to Adwords
Has years of data attached to it that we want to use
The plan is to just use the second code
For complete brevity custom events are being triggered like this
ga('send', 'event', 'Contact', 'contact-form', 'Goals');
My questions is this
"Because it has lots of historical data we wish to use code two but it is not collecting custom events. How do I get the second code to collect custom events so we can retire the first code? "

If you use two trackers on one site you need to give a name to at least one of them, else the first tracker is overwritten when the second one is initialized.
Thus the syntax for your second piece of tracking code - when the tracker is initialized it is assigned a name, in your example "second".
If you want to send data to that tracker you need to prepend the assigned tracker name to the send call, in your example:
ga('second.send', 'event', 'Contact', 'contact-form', 'Goals');
That is why the second tracker does not receive your event tracking calls, they are only being sent to the first "unnamed" tracker (actually if a tracker name is not assigned it defaults to t0).
Also do not think you can link an Adwords account to two different Google Analytics accounts, so. you'd need to unlink the first account and then link the second one.

Related

Which is the best method to set up event tracking for new account signup steps in GA4?

Currently I'm using the following analytics.js method to track different funnels/goals and these get triggered on each specific page.
ga('send', 'pageview', '/ConversionEvents/Step1_MembershipPlan');
ga('send', 'pageview', '/ConversionEvents/Step2_AccountInformation');
ga('send', 'pageview', '/ConversionEvents/Step3_PaymentInformation');
ga('send', 'pageview', '/ConversionEvents/Step4_AccountConfirmation');
ga('send', 'pageview', '/ConversionEvents/Step5_ThankYou');
However, now that I switched to gtag.js I'm seeing what the best method would be to set these up. I came up with the following 3 options.
Option 1:
gtag('event', 'sign_up', {'step_name': 'step1_membership_plan'});
Option 2:
gtag('event', 'pageview', {'step_name': 'step1_membership_plan'});
Option 3:
gtag('event', 'step1_membership_plan');
I'm leaning towards using option 3 because it would be easier to view these events in GA4 since it will be listed as a different event name and it would be easier to create funnels.
From reading online, they say it's better to use the recommended/automatic events like sign_up and pageview for this but I'm not sure if then I can set up events to track the different parameters (e.g. step_name) that I set up for each step.
Which option would be the best to go with?
Thank you!
Personally, I would not clutter my GA4 with too many distinct event names.
But that's a matter of taste: If I understand Google's limits page correctly, web properties do not currently have a limit on distinctly named events, whereas app properties are limited to 500.
Ref.: https://support.google.com/analytics/answer/9267744?hl=en)
Instead, I would send the following events:
sign_up, when a user has completed the registration, aka visits the thank you page.
sign_up_step_complete, when a user has completed a step in the registration process. Sending the custom dimension step_name for each step.
(That is assuming that each step is just a virtual page view and does not actually send a page_view event to Google. If it does send a page_view, you can create the sign_up_step_complete event server-side based on the URL or not create an event at all and just use the page_view.)
This way, you're using the dafault sign_up event which might show up in a default GA report while also tracking intermediate steps in a separate custom event.
Finally, I would visualize the data in a free-form exploration funnel analysis.

Custom reports are empty in Google Analytics receiving data from Google Tag Manager

I want to create a custom report with custom dimensions and custom metrics, so I've created them as admin in GA and both have index 1.
I've added them in the dataLayer in my code:
var dataLayer = {'dimension1':'Custom Dimension 1','metric1':123456}
And after setting in GTM, I've checked data is being sent right in live mode:
But custom reports are empty, but activity on site is being registered.
This is the entire code of my site. I have tried adding both Google Tag Manager and Google Adwords codes but does not work in any case:
<body>
<script>
var dataLayer = [{
'dimension1':'My Custom Dimension 1',
'metric1': 123456
}]
</script>
<!-- Google Tag Manager -->
<!-- End Google Tag Manager -->
<h1>Nuevo alojamiento</h1>
<script>
//GA CODE
ga('create', 'UA-76206495-2', 'auto');
ga('send', 'pageview');
</script>
</body>
Pushing those values with those standard reference names in to GTM will not associate them with your hits, or make them show up in your reports. In GTM you need to grab the value of your CD and CM from the dataLayer. In this case you need to create dataLayer type variables that will give you access to dimension1 and metric1, although I would advise to rename them to something else other than the standard GA reference names, ie. dimensionX and metricX because that could be confusing. Then you need to pass the index and value for that CD and CM into whichever tag (page view, event, etc.) using those new names.
Edit: note that data won't show up in your standard reports until they have been processed, which takes up to 24 hours or so.
As nyuen told me, I have to set those values in GTM, it was done bescause, if it wouldn't, data would not been sent. These are my settings
This sends the CD and CM in all pages. Custom vars are already set.
Preview mode of CTM displays this, it was fired:
And de dataLayer contains the data (I'm going to follow you advice and use another name):
So if I leave the preview mode and publish in GTM, I'm sure information is being sent, that is the GET request I placed before. Those values era in the URL as params (cd1 and cm1), so that is the reason why I'm pretty sure information is being sent to GA
Hope this extra information helps
UPDATE 1
I've changed dataLayer values to dim1 and met1 and now met1 is set to 123456789. Also, verified UA is right.
With those changes, chain sent to Google Analytics is the same (params are cd1 and cm1 with the appropiate values)

What is the correct syntax to set a custom dimension in Google Analytics?

I'd like to send some custom dimensions back to GA with every blog post that is read on my website - author and category.
When I set up the custom dimensions in GA I got this code to use:
var dimensionValue = 'SOME_DIMENSION_VALUE';
ga('set', 'dimension2', dimensionValue);
However, in the GA docs it specifies a different syntax using "send" rather than "set".
https://developers.google.com/analytics/devguides/collection/analyticsjs/custom-dims-mets
ga('send', 'pageview', { 'dimension4': '<?=$categories?>'});
We are using universal google analytics, but this conflicting information means I'm not sure which syntax to use.
Thanks in advance
The first code block is how you set the custom dimension (CD) that can be sent with any hit: event, pageview, transaction, etc.
The second code block is how you set the CD and send it with a pageview. So it's a specific example of the first method.
Both are valid, it's just that the second example is more complete.
When sending data to CDs, don't forget to create and define them in the GA configuration as well.

CustomDimension send via ga('set',...)

I have two buttons, to set gender.
For each gender button I've set up a customDimension like ga('set', 'dimension1', 'male'); or ga('set', 'dimension1', 'female');
In the Javascript Console from FireBug I see that the ga() command is executed without errors. In GoogleAnalytics I have set a customDimension
Must I send this data specific via ga('send',...... or is this not needed??
If yes, which parameters do I have to set?
I can't see any received Data in GoogleAnalytics GUI and I have waited about 48 hours.
Custom Metrics and Dimensions must always be sent with an interaction hit, else they will not get recorded.
In addition, fields set with ga('set'... must be followed by an interaction hit - "set" in this case literally means "set this field for subsequent use in interaction hits". The difference between using set and passing the custom dimensions via the configuration object of an interaction hit (pageviews, events etc) is that "set" will affect all following hits while passing the custom dimension/metric as a parameter to a hit will only affect that specific hit.
So if you use ga('set', 'dimension1', 'male') and you have after that one pageview and two events the dimension will be recorded three times (not so much a problem with custom dimensions, potentially a big problem with custom metrics).
If you do instead:
ga('send', 'pageview', {
'dimension1': 'male'
});
the dimension will be send only once.
But no matter how you do it, the data will only be sent along hit data, so you need a pageview, event or transaction if you want any results.

Google Analytics universal is not tracking page views nor events when user-id is set

Recently we update our system to work with google analytics universal. We migrated the property to use universal analytics, and a few days later, we made the code changes according to the guide: https://developers.google.com/analytics/devguides/collection/upgrade/guide
We made the change to also use the User-ID functionality. Every event or page view is tracked normally, but the goals completions (which are in the end when a user reaches a specific page).
We introduced the user-id on the midday of the August 6th, and as you can see, the day after the goals were 0 (although because of our database, I can tell was about 25). Day after (8th), the goals (as said before, pageviews with the user-id set) were tracked normally again. Day 9th only a few (and were much more). From that day on, not at all are tracked.
In the beginning I believed that it takes longer to analytics to put the data together because of the user-id, but it seems to me very strange.
The code i am using is:
<!-- Google Analytics Universal-->
<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-xxxxxxx-y', {
'cookieDomain': 'xxxxxxx.xx',
'siteSpeedSampleRate': 25
});
{% if userId is set %}
ga('set', '&uid', userId);
{% endif %}
ga('send', 'pageview');
Everything pretty straightforward, and I am also using the google analytics debug tool to check if all the data is sent, and yes, it's sent. In addition to that, if I reach a page that tracks a goal myself, I can see my session in the real time, so data is sent to analytics.
That's why I am thinking that I am missing some configuration from the google analytics side. I already created a user-id view and the data there contains the same information, but only from 6th august, when user-id functionality was started to be used.
Anyone has an idea or has the same trouble?
Thanks!
If you're using a debug tool and have verified that the user ID is in fact being sent as part of the hit to Google Analytics, then that means you're doing everything correctly on your end.
I copied your exact code, replaced the userId variable with the string 'foobar', and I was also able to verify that the hit was sent correctly, including the string 'foobar'. Here's what it looked like:
http://www.google-analytics.com/collect?
v=1&
_v=j25&
a=1335799492&
t=pageview&
_s=1&
dl=http%3A%2F%2Flocalhost%2Ftest.html&
ul=en-us&
de=UTF-8&
sd=24-bit&
sr=2560x1440&
vp=1605x611&
je=1&
fl=14.0%20r0&
_u=cACAAET~&
cid=2022234602.1393626891&
uid=foobar&
tid=UA-XXXX-Y&
z=304825725
If the data is not properly showing up in your reports, and you're sure that everything is set up correctly for your userId-enabled view, then it could be a bug, and if so, the best thing to do is simply report it to Google.
The best place to report the bug is here:
https://code.google.com/p/analytics-issues/issues/entry
UPDATE (08/26/2014)
It looks like there's already a bug entered for this issue. You can star it here to be notified of fixes/updates: https://code.google.com/p/analytics-issues/issues/detail?id=477
ga('set', '&uid', userId);
Is that printing a literal userId or does that actually work? Try:
ga('set', '&uid', '{%=escape(userId)%}');
have you tried? ga('create', 'UA-XXXX-Y', { 'userId': 'USER_ID' });
information directly from the documentation found at User_id

Resources