I am trying to trigger event when user clicks on the link. The code I am using is this
<a href="https://www.businessxb.com/"
gtag('event',
'tosubscribe',
{'event_category':'subscribe', 'event_label':'subscribe for notifications'});="">
Business opportunities in Dubai
</a>
But I am not getting any event recorded in Google Analytics
Due to processing latency it can take between 24 - 48 hours for data to appear in the standard reports.
Check the real-time reports if you are seeing hits there your code is probably working. Just wait the data should appear in a few days.
As DalmTo pointed out, you code is indeed seems to be incorrect. It's not specified, when gtag command should be fired. More precisely, it is not bound to onClick event. You should use something like this. (I've not tested the gtag part, just added the onClick syntax.)
<a href="https://www.businessxb.com/"
onclick="gtag('event',
'tosubscribe',
{'event_category':'subscribe', 'event_label':'subscribe for notifications'});">
Business opportunities in Dubai
</a>
Related
Completely new to GTM and having trouble getting ecommerce conversion tracking to work on GA4. This is what debug mode looks like in GTM the tag doesn't fire. Does anyone know what could be causing the issue?
Have research all the possible reasons, checked the source code, spoken with the developer who added the GTM container to the site, reviewed the tag itself but still none the wiser.
Look at the trigger is waiting for a datalayer event : add_to_cart.
So you need to ask the developer to push a datalayer event with ecommerce item when user successfully perform an add_to_cart event.
Here is the detail about all ecommerce event and its datalayer.
https://developers.google.com/analytics/devguides/collection/ga4/ecommerce?client_type=gtm
You have done half of the job. The there is still another part need to be done.
We have noticed purchase events in our Google Analytics 4 report coming through in Realtime as 'ecommerce_purchase', rather than 'purchase', as it has always been:
We have not updated anything within the GTM container or the GA4 report. The GTM Purchase tag continues to reference 'purchase' as the event, and is untouched:
Up until last Friday (16/01/21) our report was only ever receiving a 'purchase' event until this weekend where this new 'ecommerce_purchase' is now being tracked. It seems intermittent, where we can see 'ecommerce_purchase' in the GA4 Debugview, then run the same test a minute later where we then see 'purchase' as the event tracked in Debugview.
The dataLayer and code have remained untouched. When testing ourselves and viewing the tags fired in the GTM Preview, the 'purchase' event triggers our GTM tag, and the dataLayer displays all information from this event with no mention of 'ecommmerce_purchase'.
Would anyone have any idea as to what is causing this? Or, is anyone experiencing this as well?
Any help is much appreciated.
Thanks!
You might want to check in your Create Events/Modify Events to see if someone created a new event based on the purchase event or modified the purchase event coming in and renamed it to ecommerce_purchase.
Go to All Events > Create Events or Modify Events to see if any have been created.
So, I have an event firing when a mailto link is clicked, which is working fine:
Then I added a goal, with the properties of the event. (I should probably mention this was already in place, I didn't just add it after firing the event). I successfully verify it should work:
...But the conversion goal just isn't getting hit:
Screencast here: https://youtu.be/VClrTtVeizw
Am I doing something wrong? The fact it verifies makes me think not but I'm not a seasoned Analytics user so any advice would be great.
I have a page setup with the following GA JavaScript on the page to track pageviews
ga('create', 'UA-xxxx-xxx', 'auto');
ga('send', 'pageview', location.pathname);
I also have the following JavaScript within document.ready to track an Event
$(document).on('click', 'button[type="submit"]', function () {
if (typeof (ga) !== 'undefined') {
ga('send', 'event', 'Your Details', 'Save Address Change');
}
});
Within all development and test environments, the code fires only when it should (the form contains only ONE button) but in LIVE, the Event is almost in line with the pageview number (and the backend data confirms that the button has not been pressed as it is logged in the SQL database as it fires an INSERT statement). When I attempt to debug the JS, the event does NOT fire
Is there any way the pageview event on my form could then be triggering the event? Caching?
Using the secondary dimensions, I cannot find any data that tells me what or who is triggering this event on almost every pageview. All it confirms is that this is not isolated to one browser
The code looks like it would operate the way you would hope, so there must be something else going on... This isn't particularly an answer as much as it is other things to check that may lead to an answer:
How many Unique Events vs. Total Events are occurring for "Your Details"?
Are there any other submit buttons elsewhere on the page (search, subscribe, etc)?
Any chance you're loading your tracking script (where the event listener is) more than once?
How about spam bots? Have you noticed many server-side crawlers? This wouldn't be caused by "ghost" spambots, so check for Full Referrer as a secondary dimension.
Does this appear on both your unfiltered and filtered views?
Are any other core metrics (users, sessions, pageviews, bounce rate) in your reports odd?
Create a segment for just users who have triggered this event and look through all of your other reports. Are they following a typical funnel/path that you would expect?
Check the User Explorer to see if you can find a specific user who triggered the event. What else did they do? Does it look like a normal users?
You could add a custom dimension of Client ID and parse the GA cookie to track which CIDs are triggering the event (it would help you find them in the User Explorer).
Other custom dimensions that could help you get more context clues: Timestamp, Hit ID (random ID assigned to every individual hit), PHP Referrer.
The long shot: any chance some other script is triggering a click on that button?
I hope something here helps you.
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.