Custom Dimension in Google Analytics not showing in my queries - google-analytics

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.

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!

Adding a key for "read time" to datalayer for tracking in Google Tag Manager/Analytics

With a WP plugin, I'll be adding "read time" to each article. NOTE: Read time simply shows how long it takes to read the article, not how long a user has read my article.
I want to pull this value into Google Analytics as a custom dimension. I'd like to compare how long people are on the page (avg. time on pg.) against how long it should take to read the whole article (read time).
I understand I need to add a key for "read time" to the data layer, and pull that key into GTM. However, the documentation does not make it clear what key to add to data layer for a value like read time. Or how to create a key for it that Google Analytics will understand if that is possible.
Any possible solutions?
The key can be anything you like. Assuming this info should be available when the article loads, you can push information to the dataLayer from the page code, or from a custom HTML tag in GTM using a window loaded page view trigger.
<script>
// Example of getting the read time value from a
// DOM element with a class "read-time"
var readTime = document.querySelector('.read-time').innerText;
dataLayer.push({
// Give an event name so that we know exactly when
// the data becomes available in the dataLayer.
event: "Article Viewed",
// Add the data
article: {
readTime: readTime,
title: "How to write a blog post",
// other useful article-related properties
}
});
</script>
When you have your dataLayer push working successfully, you can add a dataLayer variable in GTM to make read time available to other tags. The dataLayer key in my code example is article.readTime.
To send this value to GA as a custom dimension:
Add a custom dimension to GA. Set the scope to "hit" and make note of the index for later.
In GTM, add a Universal Analytics tag and set "Track Type" to Event. "Event category" could be "article," "event action" could be "article viewed" and "event label" could be the GTM built-in variable for Page URL or Page Path.
This is important: set "non-interaction hit" to "True."
"Google Analytics Settings" should be your GA settings variable. Check the "Enable overriding settings in this tag" box. Expand "More Settings" and "Custom Dimensions."
Click "Add Custom Dimension" and input the index of the custom dimension that you defined in GA for this purpose. Then, in the value field, put your dataLayer variable for read time.
Add a trigger of type "Event." In the "Event Name" field, put the event name of your dataLayer push ("Article Viewed" in my example). Save the trigger and make sure it's added to the tag.
Save the tag and test it in preview mode.

Use google tag manager install GA4 for SPA but the field page is not work

I use Google Tag Manager to install GA4 for SPA (single page application).
I search a lot of articles about setting SPA and it seems like I need to add a page field.
I tried to put the value as below but not one succeeded. I used Google Tag Manager debug mode to check the page view event was hit.
{New History Fragement}
{Page Path}{New History Fragement}
{Page Path}#{New History Fragement}
constant like /testGTM
custom javascript like below
function() {
  return window.location.pathname + window.location.search + window.location.hash;
}
Even I put the constant like testGTM, I still can not see the data contain testGTM. The page view data is collected but the URL is not the same as I expected. 
Did anyone meet the same problem? Or the field page doesn't work anymore.
Thank you.
Sample Setting GA4 in Google Tag Manager
I found out how to solve this problem.
First, click 「event」->「All event」.
Second, click「custom definition management」.
Last, click 「create custom dimension」and enter "page" in the parameter name.
After the above instruction, we can get the "page" data as normal.
How to Check
There are 3 ways to check
1.Engagement -> Event -> + custom(event scope)
2.Engagement -> Event -> click each event -> see past 30mins event's parameters
3.Engagement -> Event -> click each event -> scroll down to see parameter
P.S. I use the Japanese version so maybe the translations are different.

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:

Custom Dimension value alway showing up as not set

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.

Resources