Can fbevents.js override Google Analytics event tracking? - javascript

I'm responsible for a department website for a university (https://www.unomaha.edu/college-of-business-administration/economics/). Because this is driven by a CMS, I can control a portion of the body section. However, the sausage code in the header or in the bottom portion of the body, I have no way to remove.
In the header of the page, the university has loaded Google Tag Manager. What I'd like to is record some in-page events using the standard Google Analytics approach. However, when these events are fired, (a) the event isn't recorded in Google Analytics and (b) if you have the Google Developer Console open there is a call to https://www.facebook.com/tr/.
I've tried this using both the dataLayer push method and a direct call to the "ga" function. Both result in no event recorded and a call to facebook. Directly looking at the dataLayer array in the console does show the event was pushed to the array.
gtag method (gtag defined earlier in the code):
gtag('event', 'econ_passion', {
'event_category': 'econ_passion',
'event_label': passion,
'event_action': 'open_passion'
});
ga method:
ga('send', {
hitType: 'event',
eventCategory: 'econ_passion',
eventAction: 'open_passion',
eventLabel: passion
});
What seems to be happening is that fbevents is dynamically loaded into the bottom portion of the body tag.
Has someone experienced this? Understanding that I can't actually remove the facebook code, is there a way you've found around this problem such that I can record G. analytics events?

You're using the wrong methods to push the event to GTM then GA. To track an event through GA implemented through GTM, you need to have access to the GTM container as well.

Related

Google Tag Manager Events showing up on Google Analytics inconsistently

In this project I'm in, they have configured GTM and GA to work together to track particular events. I was asked to find the root cause of some kind of a leak that's happening.
Currently, the events are being tracked with the eventLayer.push strategy. Those events are handled by the Event Tag in GTM, which sends them to GA.
When testing them, it's happening that the events aren't reaching GA 100% of the time. Even the same event, doesn't hit GA every single time it's being triggered. I'm looking into
This is leading to issues when analyzing the results GA gives.
To test this, I've been trying the Preview Mode on GTM. When doing so, I can see that every event that is triggered appears there. However, not all of them appear in the real-time view of GA. Here's an example of this:
https://b.imge.to/2019/07/16/LVqot.png
Then, I started using the Tag Assistant Chrome's extension to find out if it was helpful, and I got to see some errors there. This is an example:
https://b.imge.to/2019/07/16/LV18x.png
To make this, the events are being pushed like this:
dataLayer.push({'eventCategory': 'sign in', 'eventAction': 'click', 'eventLabel': 'sign-in-popup', 'event': 'click-sign-in-popup'});
and GTM is being embedded like this:
:javascript
dataLayer = []
/ Google Tag Manager
:javascript
(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=
'//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','#{ENV['GTM_CONTAINER_ID']}');
/ End Google Tag Manager
To clarify, the GTM container is already published. I can't find the reason of why sometimes events reach GA

How to get Google Tag Manager Event Tracking to send to Google Analytics?

My website has a tel: link in the header, and I want to see in Google Analytics when this link is clicked, and on what page. I've decided to do this using Event Tracking in Google Tag Manager. So I made a tag, with the following configuration.
And this is my Trigger configuration.
This is the HTML that this is referencing, (note that I also tried to add an onclick attribute, which was meant to push Event data directly to analytics. This didn't work.)
This is the variable configuration used in this tag.
This is proof it fires in the GTM debug pane.
And this is the summary coming in when you click on the item withing the pane.
In Analytics, this is what I see in the Real-time events tracking.
And this is what I see under the events overview.
So the tag is firing correctly, but the information is not going over to Analytics. I can find no resource on the internet that addresses this issue. Has anyone successfully pushed Google Tag Manager event tracking into Google Analytics? If so, what did you do to make it work, and what am I not doing/doing wrong that is preventing me from the result?
The end goal is I want to track the page where the click happened in Google Analytics' Events Overview, and also in the Goals section.
Thanks for that link, Uda! What was going wrong was my Google Optimize Tag. I paused all tags except my click-tracking and my Universal Analytics

Adding an Analytics Event to the Google Classroom Share button

I recently added the Google Classroom share button to my website. I'm looking to fire off a Google Analytics event every time this share button is clicked. I've tried using a javascript onClick to do it, but that didn't work. I think it might be because this creates an iframe when rendered by the browser.
$('#___sharetoclassroom_0').on('click', function(e) {
ga('send', 'event', 'gClassroom', 'gClassroom Click', 'Google Classroom Clicked');
}
I then saw the "data-onsharestart" attribute I can add to the Google Classroom tag and tried using that. That didn't work either...
<g:sharetoclassroom url="URL" data-onsharestart="gClassroomCount" size="20"></g:sharetoclassroom>
function gClassroomCount() {
ga('send', 'event', 'gClassroom', 'gClassroom Click', 'Google Classroom Clicked');
}
Any ideas on how I could add this event to the Google Classroom Share button?
You should try to use the debug version of the analytics.js library, that logs detailed messages to the Javascript console as it's running. These messages include successfully executed commands as well as warnings and error messages that can tell you when your tracking code is set up incorrectly. It also provides a breakdown of each hit sent to Google Analytics, so you can see exactly what data is being tracked.
Based from the blog, if you want a full control of the appearance and behavior of the share button (and don't need the callbacks), you can customize the Classroom icon as long as it still meets our branding guidelines and initiate the share via a URL of the form: https://classroom.google.com/share?url=https://foo.com/
You can also check this related SO question, hope it helps!

Google analytics event goal not creating conversion

I am using GA to analyze button click but it doesnt show them in the goal section. It just get displayed in the real time section.
My configuration:
Google Analytics configuration
Event sent via my onclick
ga('send', 'event', 'Buttonclick', 'Moveto', 'Register')
Everything looks good to me, too. You can confirm the event is actually firing with the "Google Analytics Debugger" Chrome extension. As long as that works properly, then you're golden.

Tracking Google Analytics events with Angulartics

I am using Angulartics to do the tracking on my website. https://github.com/luisfarzati/angulartics
Events are tracked on mixpanel as well as google analytics. Mixpanel events are tracked as desired. However, Google analytics does receive the page views but does not track any events at all. I know that GA requires a "category" as well as a "action" to be set for each event.
So my event tracking basically looks like this,
<a ng-click="bookingModal($parent.$index)" href="{{trip.bookings[0].providers[0].url}}" target="_blank">Test </a>
Basically, I have a simple ng-click on my event (some events can be fired without clicking).
in my controller I have the following:
$scope.bookingModal=function (trip){
var clickedIndex=trip;
var detailTracker={
eventCategory: 'bookingModalClicked',
eventAction: 'bookingModalClicked Action',
userMail:Auth.user().email,
userName:Auth.user().user,
clickedIndex: clickedIndex
};
$analytics.eventTrack('clickBooking',detailTracker);
This tracking works perfectly fine with mixpanel, but events are not tracked with GA. What am I doing wrong? I dont seem to find my mistake.

Categories