Reputation: 263
I have set up event tracking on a phone number link using the following code,
<a onclick="ga('send', 'event', 'Phone Call', 'click', 'Header phone link', { nonInteraction: true });" href="tel:+123456789">+123456789</a>
Its been over 24 hours and I did not see any events being tracked so I added the Google Analytics Debugger on Chrome and on inspection I found the following error,
Running command: ga("send", "event", "Phone Call", "click", "Header phone link", {nonInteraction: true})
Command ignored. Unknown target: undefined
I've tried moving the analytics code to the header from the footer on a suggestion I found somewhere but it hasn't helped.
What else can I do?
EDIT: I'm using gtag.js
Upvotes: 1
Views: 1924
Reputation: 15913
You must have ga('create', 'UA-XXXX-Y');
command on your head section before you can send any event.
For this, it is beneficial to include create just after you have included Google analytics code on your site. It must look something like this
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXX-Y');
On a side note,
I would recommend you to use Google tag manager, as then it will be very easy for you to manage tags.
Right now gtag
object is used in GA. I would recommend you to go tou your property and have a look into tracking info.
Since you edited that you are using GTAG, then assuming you have implemented the main tracking code correctly, use this to send an event
gtag('event', <action>, {
'event_category': <category>,
'event_label': <label>,
'non_interaction': true
});
Upvotes: 4