Angular gtag.js
A simple Google Analytics gtag.js package for Angular.
Install
npm install angular-gtag --save
Add the the tracking code from GA admin dashboard to index.html
and set send_page_view to false.
Add the package to to your app.module.ts
.
;
Pageviews
The package will listen to route changes by default, you just need to instantiate service in the root of the project.
Gtag is a serivce that also allows you to track pageviews manually.
gtag.pageview; // or with custom params gtag.pageview;
Events
Events expect an action.
gtag.event'view_promotion'
You can optionally pass in addtional params.
gtag.event'login', ;
Event Directive
Many analytics events are tracked based on user interaction, such as button clicks. Just tell it which DOM event to track.
Track Me
This will register a general event in GA based on the event name.
You can pass optional params to the directive like so:
Some Product...
The directive will produce the following event on dragstart.