angulartics / angulartics-google-tag-manager

34 stars 35 forks source link

How can I add custom DataLayer Variables? #28

Open Gabrielr47 opened 5 years ago

Gabrielr47 commented 5 years ago

I'm trying to send:

        $analytics.eventTrack('play_game', {
            gameMode: '1',
            playForMoney: true,
        });

but the variables are not showing in the GTM console only the action, what should I do?

I read the code and I thing should have something like

      function eventTrack(action, properties) {
        var dataLayer = window.dataLayer = window.dataLayer || [];
        properties = properties || {};
        dataLayer.push({
          'event': properties.event || 'interaction',
          'target': properties.category,
          'action': action,
          'target-properties': properties.label,
          'value': properties.value,
          'interaction-type': properties.noninteraction,
          'userId': $analyticsProvider.settings.ga.userId,
          ...properties.gtmCustom // <-- the same way they are doing in https://github.com/angulartics/angulartics2/blob/5c478ca09c20ca8bb230f47a5669287fe8fd5f80/src/lib/providers/gtm/gtm.ts#L81
        });

      }