CustomDimension send via ga('set',...) - google-analytics

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.

Related

(not set) values from session_start events appearing for custom dimensions/parameters

We just added GA4 tracking to our website, along with custom parameters on events that were then configured as custom dimensions to be used in reports. After, we noticed "(not set)" values appearing when breaking out by a custom dimension. It appears as 0 Views, but roughly double the Total Sessions.
When filtered to "(not set)" for the custom dimension, and looking at the events, it seems these are mostly recorded as "session_start" and "first_visit" events.
Moreover, when filtering out "(not set)" for the custom dimension, the Sessions count for the page_view event does not add up to total, which leads me to think that there are Sessions with no page_view events - though I can't think of how this could happen on our site, and we don't have an app/any app tracking set up.
We compared and we get the same results from the API too.
Here is the code on our site (following the gtag guide here):
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXX"></script>
<script>
var ga4ParamsObject = JSON.parse(`{"classification":"Standard","example1":"value1","example2":"value2","example3":"value3"}`);
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-XXXXXXXXX', ga4ParamsObject);
</script>
Questions:
Is something incorrect or missing from our implementation that's resulting in (not set) values appearing on custom dimensions?
Are we not "linking" session_start and first_visit events to page_view events within the session?
What can explain the Total Sessions being higher than the count of sessions with a page_view event?
It would appear that multiple parameters within the same session are counted twice when breaking out by these parameters (custom dimensions) - is that expected in GA4 or again something incorrect with our set up?
Additional notes:
We are running analytics.js in parallel
We've upgraded to 360
"Collect UA events in GA4" setting is turned off in Admin config
The GA4 property is connected to GAM, we serve ads on the page, and some advertisers do use gtag.js too, but I checked multiple times and our specific G- measurement ID only appears in the snippet I shared above
Here's an example page
Thanks to anyone reading this.
Custom parameters are currently not tracked with the session_start and first_visit automatically collected events which is why your custom parameters are (not set) with these two events.
Unfortunately this can impact your reporting depending on the metrics you use. E.g. if you use the views metric only and assuming your custom parameter is always set you will not see the (not set) value in your report. However if you use the users metric you will see the (not set) value as users will include events such as session_start where the custom parameter is not populated.

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.

Measuring Page Load Time of single-page app with GA

I'm using Google Analytics in an SPA. For any virtual page redirects (like an AJAX call to refresh the body of the page), I'm getting a page load time of 0ms. Is there a way to track how long that takes, just as if it was a full page refresh? I'm hoping to include how long it takes for the AJAX call and also the time to download and display images that are loaded as a result.
As you have found, Google Analytics will not provide page timings for SPA's. This includes if you increase the site speed sample rate to 100. This is because Google Analytics calculate the page timings using the Navigation Timing API.
For example, DOM loaded would be:
$(document).ready(console.log((Date.now() -
performance.timing.domComplete)/1000))
To over come this problem, you will need to use custom metrics. The solution has three steps.
1) Set up a custom metric in GA.
Go to Admin > Property > Custom Definitions > Custom Metric.
Create a new Custom Metric, with the scope of Hit and the formatting type of time. Note: Specify time in seconds, but it appears as hh:mm:ss in your reports.
2) Set up a timer.
You will need to capture the time when you want to start the measurement of page load time.
An example solution to this might be by decorating all of your internal links, e.g:
$('a[href*="stackoverflow"]').click(function(){
time1 = Date.now()
})
3) Send the time eclipsed (in sec) to Google Analytics on the virtual pageview event.
When the virtual pageview event occurs (which triggers your virtual pageviews), retrieve the difference between the current time (Date.now()) and the time which the timer was started (time1).
Using Google Tag Manager, a custom javascript variable can be created as below:
function(){
return (Date.now() - time1)/1000
}
This value then needs to be sent with the pageview, against the custom metric index set up in step1.
ga('send', 'pageview', {
'metricX': pageLoadSpeed
});
Using the custom metric along with calculated metrics (e.g. {{virtualPageTimings}}/{{pageViews}}, you will be able to calculate your average virtual page timings.
Bonus:
To make the measurement more accurate, set up a secondary custom metric to count the number of virtual pageviews. This will make sure that pageviews which users are directly navigating to are not taken into consideration.
To do this, create a custom metric with the scope hit and the formatting integer.
Then with every virtual pageview, send the value 1 against the custom metric index. E.g:
ga('send', 'pageview', {
'metricX': pageLoadSpeed,
'metricX': 1
});
This allows for the calculated metric:
{{virtualPageTimings}}/{{virtualPageViews}}
If you checkout the Google Analytics docs, you can find out about the siteSpeedSampleRate option, which basically allows you to turn on your site tracking beacons for a percentage of your users.
By default this value is at 1, but I'm assuming you might want to turn it to 100. It might affect a bit in term of network usage since it will have to transfer more data to GA, so take that into account depending on your users and how they access your website (through mobile, bad coverage in some countries...).
You'll have to modify your tracking code to integrate something like the following:
ga('create', 'UA-XXXX-Y', { siteSpeedSampleRate: 10 })
You can send the timing manually, As everything on Google Analytics. But it's a little bit tricky to do,if I'm honest I would no do it unleast it's necessary. All the data on the time report are based on a hit called timing, this hit is send after the pageView and contains the following information.
If you can see my example, I forced the tool to send the hit, just after the pageview goes another hit with a special list of parameters.
plt : Specifies the time it took for a page to load. The value is in milliseconds.
pdt : Specifies the time it took for the page to be downloaded. The value is in milliseconds.
dns : Specifies the time it took to do a DNS lookup.The value is in milliseconds.
rrt : Specifies the time it took for any redirects to happen. The value is in milliseconds.
srt : Specifies the time it took for the server to respond after the connect time. The value is in milliseconds.
tcp : Specifies the time it took for a TCP connection to be made. The value is in milliseconds.
dit : Used to send a random number in GET requests to ensure browsers and proxies don't cache hits. It should be sent as the final parameter of the request since we've seen some 3rd party internet filtering software add additional parameters to HTTP requests incorrectly. This value is not used in reporting.
clt : pecifies the time it took for the DOMContentLoaded Event to fire. The value is in milliseconds.
More info of this parameters on : https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters and
You can see more info of this hit on
https://developers.google.com/analytics/devguides/collection/analyticsjs/user-timings
So what happens now?, if I launch another pageview in this SPA, the second pageview on the same page will not carry this hit and you will ever get 0 of loadtime. You can use the command as the official documentation but if you use it you will notice that is not the same hit (i have to double check that). Other option is send it manually using the command 'send' and attaching the desire information. Check your pageview hit structure to be sure that your timming is actually attaching to your previous hit.
The comand to send the timming after the pageview is send will be something like that, use the &dl parameter or 'dp' parameter to attach the timming to the ajax page.
ga('send', {
hitType: 'timing',
'&plt': 1,
'&pdt': 1,
'&dns': 1,
'&rrt': 1,
'&srt': 1,
'&dit': 1,
'&clt': 1,
'&dl': 'http://cl.edreams.com/',
});
Now all the values '1' needs to be updated for the correct one, now how to determine the time of each parameter not sure at all. Also remember that the sampling by default is only for the 1% of the sessions, send this hit only in a few cases.
Disclaimer : This is a very experimental implementation, we are forcing the Js to send unexpected information. Test it well before to pass it to a final project
Greetings

Two Google Analytics Codes - both not collecting correctly

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.

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.

Resources