import { AfterContentInit , Directive , ElementRef , Input , NgModule , Renderer2 } from '@angular/core' ; import { Angulartics2 } from './angulartics2-core' ; @ Directive ( { selector : '[angulartics2On]' } ) export class Angulartics2On implements AfterContentInit { @ Input ( 'angulartics2On' ) angulartics2On : string ; @ Input ( ) angularticsAction : string ; @ Input ( ) angularticsCategory : string ; @ Input ( ) angularticsLabel : string ; @ Input ( ) angularticsValue : string ; @ Input ( ) angularticsProperties : any = { } ; constructor ( private elRef , private angulartics2 , private renderer ) { } ngAfterContentInit ( ) { this . renderer . listen ( this . elRef . nativeElement , this . angulartics2On || 'click' , ( event ) => this . eventTrack ( event ) ) ; } eventTrack ( event ) { const action = this . angularticsAction ; const properties = { ... this . angularticsProperties , eventType : event . type , } ; if ( this . angularticsCategory ) { properties . category = this . angularticsCategory ; } if ( this . angularticsLabel ) { properties . label = this . angularticsLabel ; } if ( this . angularticsValue ) { properties . value = this . angularticsValue ; } this . angulartics2 . eventTrack . next ( { action , properties , } ) ; } } @ NgModule ( { declarations : [ Angulartics2On ] , exports : [ Angulartics2On ] , } ) export class Angulartics2OnModule { }