Adam McGurk
Adam McGurk

Reputation: 476

Google Analytics Event not firing containing hit type

I've got a small little internal app that counts code, and I'm trying to set it up so that Google Analytics logs an event everytime somebody uses it, but the problem is, the event isn't logging. I've got my google analytics tag in my head, but when I call the following function:

ga("send", "event", "code", "counted", "Counted Code", jsonReturn.data.raw_total);

Once my ajax call to actually count the code has completed, nothing happens. There is no event logged in Google Analytics.

What am I doing wrong?

--------------------- EDIT ---------------------

Here is the surrounding code where it is called:

window.addEventListener("repofound", (ev:CustomEvent) => {

    const repoUrl:string = ev.detail;
    const ajax:XMLHttpRequest = new XMLHttpRequest();
    ajax.open("GET", "https://URLtoServer" + repoUrl);
    ajax.send();
    ajax.onload = () => {

        countButton.removeAttribute("aria-busy");

        const jsonReturn = JSON.parse(ajax.response);

        if (jsonReturn.success) {

            ga("send", "event", "code", "counted", "Counted Code", jsonReturn.data.raw_total);

            // specific client side UI code that is most definitely firing

        }

    };


}, false);

Upvotes: 0

Views: 176

Answers (1)

Michele Pisani
Michele Pisani

Reputation: 14179

From your comment it is clear that you are using the gtag library while the event is sending it with ga (Analytics Universal).

So you need to edit your event from this:

ga("send", "event", "code", "counted", "Counted Code", jsonReturn.data.raw_total);

To this:

gtag('event', 'counted', {
  'event_category': 'code',
  'event_label': 'Counted Code',
  'value': jsonReturn.data.raw_total
});

Upvotes: 3

Related Questions