Jeffrey Simon
Jeffrey Simon

Reputation: 1034

Google Analytics event tracking not reported

Quite a ways back we switched from ga() to gtag() and the Global Site Tag. Ever since, we have not been able to get event tracking to report. I added an alert to the Global Site Tag and it shows that the gtag() function is being called. That alert is not shown in the code below, having been removed.

The following code is from the top of the web page I am testing:

<!DOCTYPE html>
<html class="no-js" lang="en">
<head>
    <!-- Google Tag Manager -->
<script>
    window.dataLayer = window.dataLayer || [];
    function gtag(){dataLayer.push(arguments);}
    gtag('js', new Date());
    
    gtag('config', '***********');
    gtag('config', '*************');
</script>
<script>
    (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=
    'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
    })(window,document,'script','dataLayer','***********');
</script>
<!-- End Google Tag Manager -->

The account numbers are obfuscated. However, normal Google Analytics reporting is occurring. So the account is set up properly for that.

As a test I have added the following code to a link on the page:

<a onclick="gtag('event', 'screen_view', {'app_name': 'myAppName', 'screen_name': 'Home'});" href="https://www.rephunter.net/blog">The RepHunter Blog - Discussion and Tips For Independent Sales Reps or Those Looking For Them</a>

According to the Google documentation, the above should be all that is needed, yet there is no reporting in either the Behavior section or the realtime section.

Originally I had my own names for the parameters in the gtag(), but when they did not work, I fell back to an example taken directly from https://developers.google.com/gtagjs/reference/api.

What else is needed to perform event tracking?

Upvotes: 1

Views: 2286

Answers (1)

ThilankaD
ThilankaD

Reputation: 1099

As per the documentation in here it has advised placing the global snippet above the gtag event commands, otherwise, it will be not sent to analytics.

enter image description here So you might need to add the Google Analytics specific snippet in the beginning of the <head> tag on the same page.

From gtag doc

The global snippet must appear at the top of every page on your site. gtag() commands cannot send data unless a global snippet appears on the page, and that snippet appears above where any gtag() commands are called.

Other Google Analytics related reportings might be working assuming that you have configured Google Analytics through Google Tag Manager through a tag with the type of Universal Analytics (or your approach might be different)

Upvotes: 1

Related Questions