I am going to use Google tag manager for the first time and I have very basic question that I am struggling with. I have my code to insert to data layer. But the problem I do not see any place to insert my code. Sorry if the question is too stupid but this is what I see
Where can I put this code?
// The GTM code.
dataLayer.push({
"event": "addToCart",
"ecommerce": {
"currencyCode": "USD",
"add": {
"products": [{
"id": "57b9d",
"name": "Kiosk T-Shirt",
"price": "55.00",
"brand": "Kiosk",
"category": "T-Shirts",
"variant": "red",
"dimension1": "M",
"quantity": 1
}]
}
}
});
Usually the datalayer is not inserted via GTM, but is created within the page code. If you create it according to the specifications then the GTM tag will read it automatically without an special configuration, you'll have to make sure that "use datalayer" is enabled.
(In theory it is also possible to create a custom HTML tag and push the info to the datalayer via some custom javascript, or create a GTM variable of the type "Custom Javascript" and create a datalayer there. But there are few scenarios where this makes sense. The point of the datalayer is to get data from a backend system into your tags, and GTM does not know about your backend.)
Related
GA4 currently provides two methods for tracking. They are gtag and GTM (dataLayer).
The gtag method does NOT require the ecommerce property but the dataLayer method does.
Example:
gtag("event", "add_payment_info", {
items: [
{
// item's properties
}
]
});
dataLayer.push({
event: "add_payment_info",
ecommerce: {
items: [
{
// item's properties
}
]
}
});
Is there any difference between the two methods?
I understand that gtag will call dataLayer.push under the hood. But is there any technical reason that the ecommerce property is required for GTM methods or is it just by design?
Use DataLayer as much as you can. Because it can be highly re-use in the Google Tag Mangaer.
The common marketing technology now is not only GA to implement. There are also like Facebook pixel and a lot of pixels that need to be installed.
Most of them has similar Ecommerce feature like view_item add_to_cart purchase.
If you use DataLayer. You can just use the items in it and re-assemble to another pixel need.
If you use gtag. This function will only apply on GA and Google Ads. In the future you still need to implement facebook pixel again from begining.
So the point here is once there is a accurate DataLayer on the website. It will save times in the future.
I am trying to send events from a Telegram bot (Java backend) to Google Analytics using Measurement Protocol V4. The event currently looks like this:
{
"client_id": "<telegram_chat_id>",
"events": [
{
"name": "tg_bot_command",
"params": {
"command_type": "HELP"
}
}
]
}
After the event is sent, I see the event and its property on the real-time overview page in the "Event count by Event name" card, but the client_id property is nowhere to be seen. And the "Users in last 30 minutes" card remains empty.
I also tried adding the user_id parameter to the events, but it also had no effect.
How do I send those events so that they show that users are active?
G-Analytics page showing logged events, but no users
Solution: add engagement_time_msec to event properties
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.
I am doing some work on a site. A message is passed to the dataLayer updating the variable "u1".
I have searched the container tag and am still unsure of how this is working,
this happens when a user hits the homepage, no push elements on the site.
URL: "premierline.co.uk"
Another example of this is the "u3" variable
URL: https://www.quote.premierline.co.uk/AWE/Container.aspx?CurrentStep=NewClient&CurrentWorkflow=CommercialB2C&ProductTarget=CompleteRetailerUnderwriting
Please help.
Thanks
The "u1" and "u3" parameters are being populated via onpage scripting. When you look at the source code on those pages and search for "dataLayer", you'll see this:
<script>
dataLayer = [{
'u1': 'QWEB MISC'
}];
</script>
and on the other link you'll see this:
<script type="application/x-javascript">
dataLayer = [{
'u3': 'XXRX'
}];
</script>
I'm trying to display multiple Google calendars with Full Calendar, like so:
eventSources: [
{
googleCalendarId: 'a.calendar.google.com'
},
{
googleCalendarId: 'b#group.calendar.google.com'
},
{
googleCalendarId: 'c#group.calendar.google.com'
}
]
All three calendars have the same settings and when I view the calendar at https://www.google.com/calendar/embed… I can see events from the different calendars displayed, but when I view my Full Calendar implementation, I can only see events from one of the calendars.
If I comment out the source of the calendar with events, my calendar shows no events.
Do I need to set up different API keys for each calendar? I haven't done anything that specifically ties the calendar that is working to the API key I've set up so far.