Pass dynamic event label in Google AMP analytics event tracking - google-analytics

I want to track an event with google analytics when a link is clicked on my AMP html page. Also I want to pass the link(href) as eventLabel while tracking this event. Is there a way to set the link URL as data-* attribute which then can be passed to google analytics event tracking script. Or is there any other way to do this.
This is pretty standard thing but Google Analytics for AMP page doesn't cover it.

I think what you are asking for was recently made available here.
basically, you can use code like
<span id="test1" class="box" data-vars-event-label="22"> Click here </span>
and then use the value in the configuration as ${eventLabel}

It seems this is possible. AMP is now supported by Google Analytics as an extended component.
Events are user interactions with content that can be tracked independently from a web page or a screen load. Event tracking with clicked links can now be monitored like:
..,
"trackAnchorClicks": {
"on": "click",
"selector": "a",
"request": "event",
"vars": {
"eventId": "42",
"eventLabel": "clicked on a link"
}

Related

Zoho: Forms: Google Tag Manager events not firing

I have a form hosted by Zoho Forms that is embedded onto my website using an iframe.
The zoho form has a custom domain, setup as follows:
My website: example.com
Zoho Form: forms.example.com
Using Google Tag Manager (GTM) I'm trying to fire a Google Analytics 4 (GA4) event when someone submits the Zoho Form.
Zoho allows me to add the GTM container ID to my form. They also push data layer variables such as zf_submitform, zf_formview, etc.
So I have added my GTM container ID to my form, configured the events, and setup a trigger on GTM. But the tags are never triggered.
For example, I create a Tag that should fire a GA4 Event when the zf_submitform event is triggered. But it doesn't fire.
Even when I view the form directly in it's native URL (not embedded into my website) the event will not fire.
Also, when debugging it using GTM Preview, it has a green "tick" symbol next to the firing trigger. But the Firing Status is "Not Fired". So even their own debugger thinks that the tag should have fired, but it does not.
Here are some screenshots of that setup to show you what I have tried:
What am I doing wrong?
The Tag:
The Custom Event (zf_submitform)
The GTM Preview Debugger
I have just discovered that Zoho Forms includes an allowList in their dataLayer variable.
This means only tag containers matching the allowlist will be fired.
Here is an example of the datalayer showing the allowlist:
{
gtm: {
allowlist: ["gas", "ua", "v", "c", "e"],
uniqueEventId: 9,
start: 1630545428319
},
event: "zf_onclickfield",
zf_category: "Zoho Forms",
zf_field: "Name",
zf_page: "",
zf_action: "Onclick Field",
zf_formname: "Contact Us Form"
}
It is understandable that they have an allowlist on their container, to avoid people running custom code on their forms.
But it needs to have the new GA4 Config and GA4 Event tags added to the list for them to work.
I have sent them a support request asking them to add gaawc (Google Analytics 4 Configuration) and gaawe (Google Analytics 4 Event) to the allowedlist but they are dragging their feet.
If you are using Zoho Forms and having problems with your own Google Tag Manager setup: Check the datalayer and it's allowlist. If it does not have gaawc and gaawe then it means Zoho has not yet updated their GTM integration. In that case can you please also message Zoho support with a link to this answer, asking them to update the allowlist ASAP. The more people who request this change the faster they will act.

Need Help Measuring Users Clicking PLay on Video That's Sitting in iFrame (Tealium/GA)

I am trying to use Tealium to send the amount of times users have clicked play on the video and sending the data to Google Analytics. There is an iframe on the home page and the secondary page has the content for the iframe. I am having trouble sending the data to GA. If I go directly to the secondary page it does send the info, but if I go through the home page and click play on the video it doesn't send data to GA. Can someone give me a solution for this? I would really appreciate it. Thanks.
Below is the iframe code that's on the home page;
Secondary Page
function myVideo(){
window.$DataTracking.SendForData({ "event_category" : "Video", "event_action" : "Played Video", "event_label" : "Home Page Video" });
}
You cannot track clicks inside iframe from the host page. But as soon as you can out tracking code on the secondary page you may use some trick to make the thing work.
When the secondary page is loaded in an iframe on some host page its referrer points to host page URL on which an iframe was loaded. You may use this value to override dl parameter of your event hit so Analytics would track this event as happened on the host page. I can't point you to the Tealium code for that but in plain analytics that would look like:
ga("set", "location", document.referrer);
ga("send", {
"hitType" : "event",
"event_category" : "Video",
"event_action" : "Played Video",
"event_label" : "Home Page Video"
});

onclick events with Google Tag Manager and Universal Analytics

My client is using Google Tag Manager and Universal Analytics, and would like to be able to track the views for the videos on their website. Their videos are YouTube videos that are displayed in a shadowbox/lightbox via an onclick event.
I added a second onclick event to the same div that opens the shadlowbox, but the datalayer.push events are not appearing in the Analytics reports. I've included my onclick script below:
<div onclick="OpenVideo( 'S6cPlRkiKTw', 'youtube' );dataLayer.push({'eventCategory' : 'videos', 'eventAction' : 'click', 'eventLabel' : ’The Title of the Video', 'event' : 'shadowboxVideo'});”>
The "OpenVideo" function opens the video in the shadowbox and this is working fine, but the clicks are not being tracked in the Analytics reports.
Does anyone see anything wrong with my script or have any other suggestions? Because the client wants to see the title of the video in the reports, I can't think of any other way to do this other than using onclick events, but maybe I'm missing something.
Pushing variables to the datalayer does not by itself send any data to Google Analytics. You need a Google Analytics tag with the type of "Event Tracking" in the tag manager and "event equals shadowboxVideo" as firing rule.
Are there a lot of videos? You could potentially just listen for the element url and then create a rule in UA which replaces a Youtube URL with the title. I have it set up for a client where they just want to know the URL.
Also why not use autoevents in GTM instead of hardcoding?

Hashsignaling and Google Analytics

I am currently working on a site that uses hashsignaling for page loads. This means there are very few page "loads", but rather lots of ajax content changes and template manipulation.
My question is: how do I track this using Google Analytics? Is there a way I can trigger a GA call in my code that captures the entire url including the hash and any other parameters?
It depends how you want to represent your site activity in GA, but you could decide what you want to qualify as a "pageview" and call the _trackPageview() method with URL included as a parameter any time that activity happens:
_gaq.push(['_trackPageview', 'YOUR URL HERE']);
Hashsignaling fire a hashsignal.hashchange event on window object when a page is updated :
$(window).trigger('hashsignal.hashchange', [subhash]);
So you can bind a Google Analytics tracking call to this event with something like :
$(window).on('hashsignal.hashchange', function(event, subhash){
_gaq.push(['_trackPageview', subhash]);
});

how to use google analytics to count clicks on a button

I have google analytics on my site.
One page has a button which when pressed executes some javascript.
It would be nice to monitor the number of hits the button receives when people come to this page.
Can anybody suggest the easiest way to achieve this with google analytics ?
Are there any best practices to do this ?
thanks
You can trackPageview in the link's onclick handler:
http://www.google.com/support/googleanalytics/bin/answer.py?answer=55521
<a href="javascript:void(0);"onClick="javascript:pageTracker._trackPageview('/folder/file');" >
This inflates your pageviews though, so it may be better to so use GA event tracking:
http://code.google.com/apis/analytics/docs/tracking/eventTrackerOverview.html
Play
Updated Answer
Here is the new method for Google Analytics event tracking:
<button onClick="ga('send', 'event', 'Category', 'Action', 'Label');" >Button text</button>
Category: Typically the object that was interacted with (e.g.
'Video')
Action: The type of interaction (e.g. 'play')
Label (optional param): Useful for categorizing events (e.g. 'Fall Campaign')
More info here: https://developers.google.com/analytics/devguides/collection/analyticsjs/events
The google analytics snippet sends google the page URL (among other things, probably) every time it's executed. I don't think you will be able to use it to count button clicks. If you execute the same snippet, it will keep sending the page's URL which is hardly valuable. If you manage to change the URL it sends, you might be able to get something...
Update:
You were right and I was wrong: google analytics does in fact support tracking events other than page loads.

Resources