Patrik
Patrik

Reputation: 2247

Knowing when Google Analytics has loaded when loaded via Google Tag Manager

We're using GTM to load Universal Analytics and I want to send some custom events from js to GA. So I need to do something like this:

ga('send', {
    hitType: 'event',
    eventCategory: 'Legitimation',
    eventAction: 'Is returning customer',
    nonInteraction: true
});

But I don't know when GA has loaded since GTM makes everything async. How can I know when ga() is ready?

Upvotes: 3

Views: 2332

Answers (1)

DanielS
DanielS

Reputation: 856

Sending GA Events not through the Tag Manager if you load GA through the GTM is a little bit tricky. You can´t use the normal events you use if you have GA hardcoded on the Page.

Here is a good thread about this - also answering your question: https://productforums.google.com/forum/#!topic/tag-manager/C2j4nt8dBxw

I would suggest to send Datalayers instead of Events, catch this Datalayers with the GTM and send the Events through the GTM. This makes it a lot easier.

Upvotes: 4

Related Questions