Joseph
Joseph

Reputation: 4695

Google Ads gtag tracking code not working, but analytics.js is working on same page

Please see this minimum example

I have a static HTML page that looks like this

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>New User</title>
  </head>

  <body>
    <!-- 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",
        "https://www.google-analytics.com/analytics.js",
        "ga"
      );
      ga("create", "MY_UA", "auto");
      ga("send", "pageview");
      ga("send", {
        hitType: "event",
        eventCategory: "livechatNewUser",
        eventAction: "redirect",
      });
    </script>

    <!-- Global site tag (gtag.js) -->
    <script src="https://www.googletagmanager.com/gtag/js?id=MY_AdWords"></script>
    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag() {
        dataLayer.push(arguments);
      }
      gtag("js", new Date());

      gtag("config", "MY_AdWords");

      gtag("event", "conversion", {
        send_to: "MY_AdWords/MY_Label",
      });
    </script>

    <script language="javascript">
      setTimeout(function () {
        document.location.href = "/dashboard";
      }, 1000);
    </script>
  </body>
</html>

After 3 days, my ga backend is receiving some data

enter image description here

However, my ad words backend is not receiving any data

enter image description here

The date range is the same, Why is this happening?

Upvotes: 0

Views: 805

Answers (1)

Dave Davis
Dave Davis

Reputation: 968

You're using the Google Analytics analytics.js implementation, not the gtag implementation. Which is fine, however, you're calling the AdWords conversion event using the gtag method. But there is no gtag.

See here: https://support.google.com/google-ads/answer/6331314?hl=en#zippy=%2Cset-up-conversion-tracking-using-javascript%2Cset-up-conversion-tracking-using-the-global-site-tag

I'd recommend switching out your analytics implementation for a gtag implementation of GA so you can use both.

Upvotes: 1

Related Questions