I have an area on my site where there are some dropdowns that filter a list of items based on what is selected. There is also a search bar that will search the list. What I would like to do is have a Custom Report in GA that tracks how many times each option from the dropdowns are selected, as well as what search terms people are entering.
My question, is how do I properly configure the event / dimensions / metrics to report on this data? I imagine a report like this:
Composer Hits
Mozart 102
Beethoven 83
Stravinski 72
So far I am collecting the items in custom dimensions (one per dropdown), which are triggered by an event, like this (angular / typescript):
(window as any).dataLayer.push({
'event': 'filter-guest-artist',
'GuestArtist': this.currentComposer
});
The tags are firing correctly in the GTM debugger, but my issue is I'm not sure if I should use a custom metric or event to track the hits. Right now in my custom report there's no data because I don't have a proper metric to track by. I've used custom dimensions in a similar way but they were collected on Page View and I used the Page View as my metric, but that isn't applicable here since these are triggered by events.
In your case I would go with an event. As I can infer from your description, the dropdown is used to filter the results. Every time a user selects one of your dropdown values and filters the results, fire an event with event label as the name of the filter. For example
event category: {{title of the list}}
event action: 'filter'
event label: {{name
of the selected item}}
Then I could easily answer my question through the Analytics interface on the events section. Filter by event action == 'filter' and as the event label as a dimension. The metrics TotalEvents and UniqueEvents will give you the insights you require.
For the search terms that users type on your page you can use the build in search term report that requires some small configuration. See more here
If cannot implement that, I would advise you use another custom event with the structure ase below
event category: {{title of the list}}
event action: 'search'
event label: {{search tem}}
This way you would see the search terms as event labels in your event report after you apply the correct filters.
Related
I ran into this inconsistent behavior on my Gatsby site I have GTM set up to track events for GA4.
Here's my code
<button onClick={(e) => {
e.preventDefault();
window.dataLayer.push({
event: 'get_case_info'
});
}}>
See Info
</button>
And my tag and trigger settings:
It will get triggered a total of 11 times each time I click. What's more odd is that if I change the event name and set the trigger to occur on the changed name (see_case) then it only gets triggered once per click. It's odd because other events don't get triggered another 10 times on top of the initial event despite have the same setup of keeping a consistent name throughout the dataLayer event and Google Analytics event name.
I found the issue. According to the docs you do not need to create the Custom Event in GA4 as well. The Custom Events are designed to trigger when a condition is met a lot like GTM. Say you want to record a conversion based on Purchases made in the US. You would create a new custom event called "US Purchases" then add the conditions for event_name equals 'purchase' and currency equals 'USD'. I assume the 10x was an infinite loop that Google added a limit to. My set up is correct with the data layer push going to the trigger then finally sending the event name to GA4.
The only thing you would need to add in GA4 was if you added some custom parameters to the event like so:
window.dataLayer.push({
event: 'get_case_info',
caseNumber: 1234
})
You would set up the custom parameters to get tracked via the custom dimensions set up.
Im trying to setup ecommerce tracking and there is something i dont understand.
In Google Analytics site, in reports->Monetization->Overview, there is a widget called
"Item Views by Item promotion name" - I dont know why its empty.
At bottom there is a "view promotions list" in it, and there i can see the promotions sections from my homepage are listed there. Does it count item views from the "view_promotion" event items, or need some promotion property in a view_item event on detail page? In both cases i set items array, where i have both item_id and item_name set - should i set item_list_name in view_items as described here?
https://developers.google.com/analytics/devguides/collection/ga4/reference/events#view_item
Please provide short snippet for events needed to fill that widget with data, im lost.
Or any idea which events and how to use for this ?
(i use GA4 GTM)
I created trigger to fire when the view_item event occurs by using a custom event and setting the "Event" equals "view_item". in preview mode when I check the view_item event, the built-in dataLayer.push is showing the item name. I created a variable that will pull the dataLayer information from the "name" key. When I inspect the "view_item" event, the variable I created shows up with the correct value of the item name. However, in my tag, the {{Item Name}} variable is showing up as undefined. I've tried to look for Google documentation on the hierarchy of the "view_item" event and the firing of the tags, but I couldn't find anything explicit.
Why is my "Custom HTML" tag that uses my {{Item Name}} variable showing as "undefined" when the "Variables" section for this partcular event shows the proper value?
Here is my custom html tag:
<script type="text/javascript">
voyage.event(6157, { productName: '{{Item Name}}', productViewed: '{{Page URL}}' })
</script>
The {{Page URL}} built in variable is showing properly. I know it's loaded when the container loads. But the {{Item Name}} variable is not showing. It (the data.push()) is pushing the correct data on the view_item event, but why is my variable not displaying the data correctly.
If this is a hierarchy issue, how do I make sure that I fire this tag after the view_item event happens.
Also, what puzzles me is that I also have a GA4 tag that is triggered by the same "view_item" event and the parameters I set for this event also use the {{Item Name}} variable and the value is showing up correctly in this tag.
Furthermore, subsequent events such as DOM Ready or Window Loaded do not show that my user defined "Item Name" variable contains a value. I was under the impressions that data.push() on the view_item event was adding to the data layer, but it would appear not. It seems that my user defined variable is only good on the view_item event.
And finally, although the Google Tag Manager preview window shows that my data layer on the final Window Loaded event only contains the below data, when I use javascript to access window.dataLayer my data is all there.
{
event: "gtm.load",
gtm: {uniqueEventId: 10, start: 1644552712402},
developer_id: {dOGY3NW: true}
}
I'm extremely confused, as I thought the data layer was reset on each page load, but it would seem that the data layer object (according to the preview mode) is being reset on each event, or the data.push() items are not persistent till the final Window Loaded event. BUT, the actual javascript object IS being added to.
I'm using an Element Visibility trigger to track a value that appears on a page. However, I want to track this value even when the user doesn't scroll to the area of the page where the element is (i.e. when the page is loaded, and the value is displayed below the fold, but the user doesn't scroll down there). Is there a way of doing this?
Suppose that you want to track a value when a certain element is present on the DOM but not depending on the visibility, then there is a 4-steps-way to do it as follows:
Assumption: you know the class or id of the element you are looking for. In the
following example, I will use a class because it allows me to report not just one but a collection of elements being part of the DOM.
We can create a trigger to detect every page visited, without any limitations due to the element we want to track could be everywhere.
Then, we can create a TAGS (called "SCRIPT detect element" on the example) of the type "Custom HTML".
Triggering will be the trigger created in step 1.
Knowing the class of the element we want to track, the script to write will be:
<script>
window.dataLayer = window.dataLayer || [];
// get all elements with a given class name
var els = document.getElementsByClassName("classname-to-look-for");
Array.prototype.forEach.call(els, function(el) {
var evtElementPresent = {
'event': 'wantedElementRendered'
}
// push event per each element.
window.dataLayer.push(evtElementPresent);
});
</script>
At this point, we will be reporting events (with event name = "wantedElementRendered") from the website to the TAG MANAGER every time an element with the classname equals to classname-to-look-for is part of the DOM, despite if it is in the viewport or not.
Now, with that in mind, we need to create a new trigger on TAG MANAGER. This time the type of the trigger will be "Custom Event" and we will make this trigger happen only if the event name is wantedElementRendered.
Final step: Let's create a tag that will create a GA4 event reporting it to google analytics.
Tag name: "Report X Element is present"
Type: "Google Analytics: GA4 Event"
Event Name: the name we want to declare on analitycs, eg: "X-Element-Present".
Triggering: will be the trigger created on step 3 -> "X Element Rendered".
Now, let's take a look how it works:
Final notes:
What if we want to track the presence of a lot of elements on the page without taking into account the visibility of each one, but also taking care of each element representing different things, like products?
Then, we can send to Google Analytics not just an event name each time an element is part of the DOM, but an event parameter as well, with the product ID. This will allow us to create reports in analytics, asking not only how many times a product appears as part of pages, but to refine the question: "How many times X product appears across pages?".
Altering steps 1-4 to contemplate events attributes, that can be done in a beautiful way. If anyone is interested, I am open to sharing this alternative as well.
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.