Custom Dimension value alway showing up as not set - google-analytics

I am trying to create custom dimension using GTM, dataLayer and GoogleAnalytics.
In GTM, created a user defined variable.
UserVariable
I have something like this in my html page
<script>
function addCategory(){
dataLayer.push({
'category' : 'drama'
}
);
}
</script>
</head>
<body onload="addCategory()">
In Google analytics created custom dimension
Custom Dimension
In the GTM in tags section, associated the dimension that was created with the user defined variable.
Index - 2
Dimension Value - {{category}}
In the Preview and Debug mode i can see that value in the Variables section.
category Data Layer Variable string 'drama'
But in Google Analytics i always seeing that value as (not set).
What have i done wrong

Any custom definition should be sent with an existing hit. Can you confirm that a pageview or an event is fired after you defined the variable? Check this answer that is describing how to send a custom dimension with GTM. In step 3 it is described how to use the Universal Analytics tag to send the custom dimension to GA. I suspect that your custom dimension is never included in an analytics hit that is why you see (not set).
Also, I would advise against using variable names such as 'category' in GA because it is resembling a variable 'used' by enhanced ecommerce.

Related

Track Custom Dimension on Google Analytics 360 with GTM on Hybrid App

I want to track the push notification consent (opt-in) in Android and iOS with GTM and GA360. I have already created a custom dimension on GA360. Then, I created a variable with an Event Parameter. However, I am not sure what I need to add on the Event Parameter Key.
Then, I created a tag in the following way:
With the custom dimension from GA360:
Is this correct? Or am I doing something wrong?
THanks!

Google Tag Manager - custom event - category is undefined

I have started using Google Tag Manager recently and I don't understand why one of my variables remains undefined while everything seems to be set up correctly.
Here is first the code that I use to create my datalayer:
<script>
window.dataLayer = [{
'pageCategory': 'test1',
'Device' : 'test2',
'Manufacturer': 'test3'
}];
</script>
I have created custom dimensions based on those variables and I can find them in Google Analytics. So far, everything is all right.
I then want to track a click on a button that leads the users to an external link. I use the following code:
window.dataLayer.push({
'ShopURL': url,
'ShopName': shop_name,
'PriceOffer': price,
'event': 'ClickPrice'
});
I have checked the content of each variable with a console.log and they all display the correct values.
In GTM, I have created datalayer variable for each one of them, I have created a custom event to push them to Google Analytics. I have taken "ShopName" for event_category, "Device" for event_action, "PriceOffer" for event_label.
When I look at the data in Google Analytics I see that event_category is undefined while event_action has the correct value. It looks like the event is fired correctly because I can only see it in GA when I click on the button but somehow some variables are not populated correctly.
You can see it in action here: https://www.mobilemultimedia.be/en/nokia/price-nokia-8.1 (click on one of the "check offer" button to trigger the event)
With GTM preview in the browser I see all the correct values.
Any idea?
Additional info
Here is a screenshot of the variable configuration in GTM:
I'm sorry, it's in French but you can see the variable with the right name.
I believe you have your trigger set incorrectly.
I think it might be an element click trigger right now, but you need it to be a "custom event" trigger and you should have "ClickPrice" as the event name you use to trigger.
Like so:

GA/GTM Custom Dimension Error (Undefined)

kindly ask you to help me with custom dimensions, as i'm newbie for GA/GTM and did everything per manual.
1) So i created 3 new dimensions for ecommerce in GA:
here is dimensions from GA with indexes
2) I've created snipped in GA and added it into head section of my site:
<script> gtag('event', 'page_view', {
'send_to': 'AW-XXXXXXX',
'ecomm_pagetype': 'page_type',
'ecomm_prodid': 'product_ids',
'ecomm_totalvalue': 'total_value',
'user_id': ‘userId’ }); </script>
along with global site tag.
3) Finally i've created new variables in GTM:
for example for page_type
and in Tag itself.
but i constantly getting error on debug:
{index: '1', dimension:undefined}
screenshot is here
will really appreciate any help!
p.s. sorry for links with images instead embedding, i have not enough reputation here yet.
You clearly are mistaken the gtag which stands for global site tag with the tag manager code.
Instead of using gtag use dataLayer.push, this is the method to push information to Google Tag Manager.
An example:
dataLayer.push({
'ecomm_pagetype' : Variable1,
'ecomm_prodid' : Variable2,
'ecomm_totalvalue' : Variable3
});
Here you have the docs for further reference: docs
Remember to place this tag under the Tag Manager snippet. or remember to initialize an empty dataLayer as the doc states.
Code on page
On your page, before your GTM container snippet add the following (I've used sample values for type, id and value), your code should look like below:
<script>
dataLayer = [{
'ecomm_pagetype': 'MyPageType',
'ecomm_prodid': 'EXAMPLE0000001',
'ecomm_totalvalue': '4000',
}];
</script>
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-XXXXXX');</script>
<!-- End Google Tag Manager -->
GTM - Data Layer Variables
In GTM, create 3 data layer variables for "ecomm_pagetype", "ecomm_prodid", "ecomm_totalvalue" like so:
Type in the key(name) that's in the datalyer object, you can set a default value if you like, otherwise, it will be "undefined" for pages without this variable defined.
Next create a "Google Analytics Settings" variable, this is to simply GA tag configuration, we will link the custom dimensions here.
Put in your own GA property ID, under "More Settings" expand to "Custom Dimensions", click on "ADD CUSTOM DIMENSION". Put in "1" for to reference the index for "ecomm_pagetype" CD in GA. For value, use the variable we created earlier. Do this for all 3 CDs.
Now your Variables page should look something like this:
GTM - Tags, adding CDs to GA tag
Now for your tag. You should have a Google Analytics tag configured in GTM. Looks like you know how to do that, to add the custom dimensions by using the new "My GA Variable" under "Google Analytics Settings". Don't forget to have this trigger on "All pages" or pick your own trigger as you see fit.

Universal Analytics tag with custom event and custom variables

I want to create a Universal Analytics tag (with enhanced e-commerce enabled) in Google Tag Manager, firing on custom event, ex.: uaEvent with two custom variables, ex.: uaVar1 and uaVar2.
I already created Data Layer Variables (uaVar1 and uaVar2) and the custom event trigger uaEvent in my GTM container. I'm pushing following data:
dataLayer.push({
'event': 'uaEvent',
'uaVar1': 'value',
'uaVar2': 'value'
});
and firing uaEvent on form submit.
Question
How should I configure my tag in Google Tag Manager container so that 'uaVar1' and 'uaVar2' will be visible and connected to uaEvent in Universal Analytics panel ?
Custom variables have been deprecated in Universal Analytics, so you should now use and configure Custom Dimensions under the Properties column in the GA interface. You will need to define the index and scope. Once you have done that, then for the tag that you want to associate your custom data with in GTM, you will need to specify, under the Custom Dimensions section of that tag, the name of the dataLayer variable for your particular Custom Dimension as well as the index.

Custom Dimension in Google Analytics not showing in my queries

I am using a Custom Dimension to send my internal UserId to GA. What we need is to know which users are clicking on this button. But when I try to get reports using the Category and Event for this button click, and I include my dimension on the report, it won't show any result.
But, if I only request eventCategory or eventLabel, it will show for example 2 hits. Which is weird because I am sending the dimension value with each click event that I am tracking, and seems like I don't have values for this specific event.
How can I make sure I have information in GA for this event?
I had the same problem. You need to set custom dimension index on your google analytics console.
Once you login into your google analytics console, go to admin tab.
At bottom of the middle column you can see Custom Definitions.
Click on Custom Dimension under Custom Definitions and define Custom dimension name for your custom dimension index. Default scope is for hit, if you want that for session change the scope.
This is all for V4 version of the analytic.
Please try this code:
GoogleAnalytics analytics = GoogleAnalytics.getInstance(YourActivity.this);
Tracker tracker = analytics.newTracker("TRACKER ID");
tracker.setScreenName("SCREEN NAME");
tracker.send(new HitBuilders.AppViewBuilder()
.setCustomDimension(1, "VALUE")
.setCustomMetric(1,1)
.build());
Here is 1 in custom dimension and custom metric is the index.

Resources