Custom dimension error - In about 10~15% of value is missed - google-analytics

Please understand that I am not good at English.
I set up the 'Custom dimension' to get user-ID.
var customerCode = ''; // This is going to be inserted when user log in.
gtag('config', 'UA-00000000-0', {
'optimize_id': 'GTM-XXXXXXX',
'user_id': customerCode,
'custom_map': {'dimension1': 'userId'}
});
gtag('event', 'userId_dimension', {'userId': customerCode, 'non_interaction': true});
However, in about 10~15% of all sessions, user-ID are always missed.
But all other index of Custom dimension are being 100% collected.
I checked it in BigQuery.
So, to figure out the cause of the problem, I set up to push the Event value that is same with 'Custom dimension'.
gtag('event', 'event', {
'event_category' : 'cdTest',
'event_action' : customerCode,
'event_label' : '',
'non_interaction' : true
});
As a result, The Event was 100% collected, but user-ID for Custom dimension was still missed in about 10~15%.
How can I fix this problem?

Related

Google Analytics 4: custom dimensions in gtag.js

I am trying to send some custom dimension together with my event.
This is my code:
gtag('config', 'G-XXXXXXXXXX', {
'custom_map': { 'dimension1': 'age' }
});
gtag('event', 'age_dimension', {
'event_category': category,
'event_label': action,
'value': data(),
'nonInteraction': 1,
'age': '666'
});
This is my dimension on UI:
I am sending my events together with my custom dimension, on UI I see all my data as parameters in the event,
but when I try to make something with my dimension GA just says me that there is no data for this dimension.
I don't know, probably I configured the map incorrectly or probably something wrong with the dimension which I created.
So the question, is my configuration and dimension correct? and if no, what is wrong? thanks!

google analytic, set and get new variable

I wonder how to add new variable to analytic when user visit page.
ga('set', 'userId', 'HP2202'); // Set the user ID using signed-in user_id.
ga('_setCustomVar',
1,
'dimension1',
'Member',
2 // Sets the scope to session-level. Optional parameter.
);
ga('send', 'pageview', {
'dimension1': 'SKU12345'
});
How could I know it success or not?
I using google analytic addon stylesheet to get report. where option I should add ga:dimension1 to ?

How do I set appVersion for Google Analytics Event tracking

When I try to set the appVersion in google analytics, then my event tracking stops working. Specifically, I'm trying to include the app version with event tracking so I can know which version of the app caused an event.
I've tried setting the app version like this:
ga('set', 'appVersion', app.version);
I've tried like this:
ga('send',
'event',
eventCategory,
eventAction,
{'page': pageName, 'appVersion' : app.version });
And I've also tried the alternative syntax:
ga('send',
{'hitType' : 'event',
'eventCategory' : eventCategory,
'eventAction' : eventAction,
'page' : pageName,
'appVersion' : app.version});
If I include appVersion, then event tracking stops working. No events show in realtime and no show the next day in the Behavior/Events section. The PageViews still work though.
As requested in the comments, I am editing to add in my event tracking code. It's been through several variations while I tried solve this problem. Here's what it looks like currently.
var app = {
trackEvent: function (pageName, eventCategory, eventAction, optionalEventLabel, optionalEventValue) {
var eventObject = {
'eventCategory' : eventCategory,
'eventAction' : eventAction,
'optionalEventLabel' : optionalEventLabel,
'optionalEventValue' : optionalEventValue,
'page' : pageName,
};
console.log("app.trackEvent - " + JSON.stringify(eventObject));
ga('send', 'event', eventObject);
}
}
I call this method from many places using a call like:
app.trackEvent("PageNameValue", "EventCategoryValue", "EventActionValue", "EventLabelValueIfIHaveOne", AnIntegerValueIfIHaveOne);
Any help or suggestions will be greatly appreciated.
Edit...
I found the following bug report that seems to apply: https://code.google.com/p/analytics-issues/issues/detail?id=366
The bug reporter mentions solving this problem by setting up a custom dimension. I will give that a try.
This appears to be be a Google Analytics bug. See https://code.google.com/p/analytics-issues/issues/detail?id=366 for more information.
As suggested by the bug reporter, the workaround is to use a custom dimension that you define in the Admin / Custom Definitions / Custom Dimensions section of the Google Analytics console.
Click "New Custom Dimension"
Enter name ( I entered customAppVersion )
Choose scope ( I chose Hit )
Click Create
Google will then suggest code examples for you, like...
var dimensionValue = 'SOME_DIMENSION_VALUE';
ga('set', 'dimension1', dimensionValue);
The only thing in the code sample that you need to change is the value of 'dimensionValue'. So I ended up with the following code.
ga('create', 'UA-########-#', 'auto');
ga('set', 'checkProtocolTask', null); // Disable file protocol checking (so that GA will work on Android devices)
ga('set', 'dimension1', app.version);
ga('send', 'pageview');
After this, the custom dimension will be applied to each hit recorded by Google Analytics and you can use that custom dimension to filter your results in the Google Analytics console.
As per google
Since the appName field must be sent with all app hits, it's often
best to set that field on the tracker itself using the set command or,
alternatively, when the tracker is created:
ga('create', 'UA-XXXXX-Y', 'auto', {
'appName': 'myAppName'
});
// The `appName` field is now set on the tracker, so
// screenview hits don't need to include it.
ga('send', 'screenview', {appVersion: '1.2'});
// Sending multiple parameters
ga('send', 'screenview', {appName: 'com.company.app', appVersion: '1.2'});
More information here
It works if you set at least the "appName", it's a good practice to set "appName" and "appId" before to set "appVersion"
ga('set', 'appId', app.id);
ga('set', 'appName', app.id);
ga('set', 'appVersion', app.version);

Google Analytics Universal Tracking Events: not tracking

just want to check to make sure I have the correct syntax with the event tracking...
ga('send', {
'hitType' : 'event',
'eventCategory' : 'links',
'eventAction' : 'click',
'eventLabel' : 'sidebar-link',
'nonInteraction' : 1
});
This is used for links that open in a new tag. Also I've found that for links that do not open in a new tag, you can add the member:
'hitCallback': function() { document.location = 'http://link-to.com'; }
Is this all looking correct? Because I'm not receiving any tracking events on my pages. I checked in debugger, and the code is being called for sure, but nothing is coming up in GA. What's up?
I dont believe you have the correct syntax. Try this syntax
ga('send', 'event', 'button', 'click', 'nav buttons', 4); //USE THIS
ga(send, event, eventCategory, eventSction, eventLabel, eventValue) // VARIABLE NAMES
**** You do not need to include the event value parameter. All other event parameters are recommended.
Gonna answer my own question here as I got it working - also I want to provide an example for the alternate syntax, for those who might be confused about it like I was. **Edited for clarity
First off, it was a matter of waiting for a day for the results to show up, even in "Real Time" mode.
Second, this is what I went with:
For links that open in new tab:
//HTML
<a class='newtab' data-type='label-name' href='http://blah.com' target='_blank'>Link to blah</a>
//JS
$('.newtab').click(function(){
var label = $(this).attr('data-type');
ga('send', 'event', 'category-name', 'click', {
'eventLabel' : label,
'nonInteraction' : 1
});
});
For links that open in same tab:
//HTML
<a class='sametab' data-type='label-name' href='http://blah.com'>Link to blah</a>
//JS
$('.sametab').click(function(){
var linkTo = $(this).attr('href');
var label = $(this).attr('data-type');
ga('send', 'event', 'category-name', 'click', {
'eventLabel' : label,
'nonInteraction' : 1,
'hitCallback' : function() { document.location = linkTo; }
});
return false;
});
The part that threw me was in the example where it showed how to add either all attributes in an object or some attributes in the object, and which attributes were available. Anyway, voila :)

Hard code GA event with GTM

I want to be able to hard code some GA event such as below. I'm using GTM and I understand its not possible in this way. Is there a way round this?
ga('send', 'event', 'Mobile', 'Original', 'App');
This is a problem because GTM creates a randomly named tracker instead of the default tracker (t0). You can either use the set fields method on the "name" field to set the tracker name to a known values (i.e. "myTracker") and adapt your calls accordingly:
ga('myTracker.send', 'event', 'Mobile', 'Original', 'App');
Or you can use the ge function to send your event tracking calls to all trackers in the page:
ga(function() {
var trackers = ga.getAll();
for (var i=0; i<trackers.length; ++i) {
var tracker = trackers[i];
tracker.send('event', 'Mobile', 'Original', 'App');
}
});
which will probably create more headache than it's worth. However it is unlikely that there is a scenario that can't be covered without a need to hardcode events - the proper way would be to push a custom GTM event (and your GA event data) to the dataLayer and trigger an GA event tracking call from there.
So for hardcoding event, just don't.
To implement ga event use this syntax wit your onclick.
replace ga('send', 'event', 'Mobile', 'Original', 'App');
with this and it will work:
gtag('event', 'click', {'event_category' : 'Mobile',
'event_action' : 'Original', 'event_label' : 'App'});

Resources