Reputation: 6962
I am attempting to log an event via Google Analytics when a user clicks certain links on our site's home page. I want to log when the user clicks the link for our telephone number, and also when they click the link for our email address.
I can get the first event to be logged, but any subsequent events are not being logged. I do not see any JavaScript errors, however in the Network tab of Chrome's Dev Tools window, I see that the Status of these network events is "(canceled)"
Can anyone point me to a working example of multiple events working on a single page? Does Google Analytics support multiple events on a single page?
Per request, I have added an example of the code I am using:
The links with events attached (again, the first click/event is working, any subsequent clicks/events are not)
<p class="lead">Call Now: <a href="tel:5555555555" onclick="ga('send', 'event', 'Default', 'Click', 'PhoneTop');" style="color: #ddd;" >555-555-5555</a></p>
<p class="lead">Email: <a href="mailto:[email protected]" onclick="ga('send', 'event', 'Default', 'Click', 'EmailTop');" style="color: #ddd;">[email protected]</a></p>
And the Google Analytics code:
<script>
(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', '//www.google-analytics.com/analytics.js', 'ga');
ga('create', 'UA-55555555-1', 'example.com');
ga('send', 'pageview');
</script>
Upvotes: 1
Views: 2593
Reputation: 6962
This was an issue with Chrome and tracking mailto and tel links (more here: New Google Analytics event tracking wont work on mailto)
I resolved this issue by adding a setTimeout() to the onclick()
<p class="lead">Call Now: <a href="tel:5555555555" onclick="setTimeout(function () { ga('send', 'event', 'Default', 'Click', 'PhoneTop'); }, 500);" style="color: #ddd;" >555-555-5555</a></p>
<p class="lead">Email: <a href="mailto:[email protected]" onclick="setTimeout(function () { ga('send', 'event', 'Default', 'Click', 'EmailTop'); }, 500);" style="color: #ddd;">[email protected]</a></p>
Upvotes: 1