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

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.

Related

Cannot create reports for custom dimensions/metrics GA4

I have implemented a feedback star rating on my website at the bottom of each page. They can select one to five stars and optionally send free-form comments. I have implemented gtag.js to send the star rating integer and comments to my GA4 dashboard. Code snippet is below; I have omitted the JavaScript which allows the user to set the variables, but this is working.
<script async src="https://www.googletagmanager.com/gtag/js?id=MEASUREMENT_ID"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'MEASUREMENT_ID', {
'custom_map': {
'rating_dimension': 'rating_key',
'comments_dimension': 'comments_key'
},
'rating_key': 'this.value',
'comments_key': 'commentsValue',
});
</script>
gtag('event', 'rating_event', {'rating_key': this.value });
gtag('event', 'comments_event', {'comments_key': commentValue });
I went under Configure>Custom definitions and added the dimensions under the Event scope.
The data is being sent as an event, because this is something the user can optionally do on a page. I have verified that the data is sent to GA, I have the Google Chrome GA Debugger, and can see that it is arriving in the Realtime report under Events.
I would like to build a report which shows the page title/URL, the number of views, the length of time spent, along with its average star rating and any comments. I would like to have some adjustable controls so that I can configure this to be shown for a specified length of time. For example, if the page is modified, I can see the average rating before and after the change. Unfortunately, I am not able to build even the most rudimentary view of this data in the new GA web interface. I tried to modify various existing reports to include my custom dimensions, but they don't offer this option. I went under Explore and tried to add a Freeform report, but I can't get the data to show up there either, it only counts the number of times the event has occurred, which is not what I care about at all.
I have gone to a lot of effort to send the data to GA and had expected to be able to access the data and build a basic report.
Is it that you are unable to add custom dimensions and metrics to the free form exploration? Or when you want to add dimensions or metrics, they don't even show up in the custom section?
Normally you have to wait more or less (some say up to) 24 hours before being able to use custom definitions (metrics and dimensions) in any report.
this might not be your case, but I found your post looking for an answer to my problem, which is the custom metrics and dimensions are there, I am just unable to add them to the report, it looks like a bug, I click the + button, check the custom dimensions and nothing happens.

Tracking sign_up event as a Goal in Google Analytics

I wanted to create a Sign up goal in Google Analytics. Adding an event for signup is simple enough:
gtag('event', 'sign_up', { method: 'Direct' });
This successfully created events
However when I try to configure the goal as such:
Nothing happens, the Goal conversion is not counted for the events shown above.
I am trying to follow instructions from here https://developers.google.com/analytics/devguides/collection/gtagjs/events
However I found very little documentation on tracking events as goals.
How do I configure a goal based on the standard engagement events in Google Analytics?
Try to set only Action equal to sign_up without value in Category.
I figured this out. The "Use the Event value as the Goal Value for the conversion" is the problem. Because my event is not sending a value, GA assumes it has zero value and zero value goals are not counted as a conversion.
I fixed this by choosing No for the option and entering 2.5 as the value. Now anyone sending the event counts as a conversion worth $2.5.

Using a Google Analytics custom dimension for pageview statistics widget

I have a custom dimension that is being set with a gtag tracking code. I can actually see that the values are being send to GA and can, for example, make dashboard widgets with it.
The odd thing is that when I make a widget with sessions and the dimension it works well, but if I want to make a widget with pageviews and the dimension it returns no data at all.
This is my tracking code:
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-0000000-0', {"anonymize_ip":true,"custom_map":{"dimension1":"premium"}});
gtag('set', 'premium', {'premium': 'premium post and not subscribed'});
I've also, instead of using 'set' tried using 'event' but this did not solve the issue. It looks like the custom dimension is not being collected with pageviews, but with sessions only.
Does anyone know if I have to configure it differently to also make it work for pageviews?
Since your custom dimension is configured at the hit level it needs to be associated with either an event or pageview hit. Your code looks like it simply sets the custom dimension value, but it's not followed by a pageview hit call. Try swapping the idea of your calls instead:
gtag('set', 'premium', {'premium': 'premium post and not subscribed'});
gtag('config', 'UA-0000000-0', {"anonymize_ip":true,"custom_map":{"dimension1":"premium"}});

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

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.

Resources