Using Gtag In Angular

Google Analytics with gtag.js

Lucio Francisco
Wizdm Genesys

--

Photo by Webaroo.com.au on Unsplash

I recently wanted to include Google site tagging capabilities to a simple single-page application of mine and that’s what I came up with:

In the example above we see the GtagDirective at work (look closely in the .html).

The gtag="home" statement in the .html sends a page-view event to the Google Analytics, Google Ads or Google Marketing Platform account you configured during the initialization (more next).

The “home” text will appear in the report to be the page title while the page location is automatically detected by the directive provided the application makes use of a Router.

By simply adding this directive to every page of your app you’ll be tracking page views.

The same can be applied to part of your views when displayed conditionally:

--

--

Wizdm Genesys
Wizdm Genesys

Published in Wizdm Genesys

An attempt in combining modern software development with ancient wisdom

Lucio Francisco
Lucio Francisco

Written by Lucio Francisco

I believe that whatever problem we’re puzzling ourselves with, once we really get to the bottom of it the solution has to be simple