Search code examples
angulargoogle-analyticsgoogle-tag-managerangularticsangulartics2

How to change default `Page View` name


Is it possible to change default name of page view event tracked after importing Angulartics2GoogleTagManager in app.component? Rigth now its Page View and I need to change the name.


Solution

  • If you want to change the name of the event, you would need to modify the angulartic2 GTM package itself. Specifically this file: https://github.com/angulartics/angulartics2/blob/master/src/lib/providers/gtm/gtm.ts

    The datalayer.push for angulartics2.pageTrack looks like this:

    dataLayer.push({
            'event': 'Page View',
            'content-name': path,
            'userId': this.angulartics2.settings.gtm.userId
          });
    

    If you want to change it, just change the 'event' key value.

    To track pageviews however:

    You need to:

    1. create a GTM custom event trigger for the "Page View" event
    2. create a GTM datalayer variable to capture the "content-name" value
    3. create a GTM tag for Google Analytics with the custom fields "page" set to the datalayer variable created in step 2 and trigger on the trigger created on step 1