import { Component , OnInit } from '@angular/core' ; import { MatomoTracker } from 'ngx-matomo' ; import { FormBuilder , Validators } from '@angular/forms' ; @ Component ( { selector : 'app-user' , templateUrl : './user.component.html' , styleUrls : [ ] , } ) export class UserComponent implements OnInit { public userId = '' ; public visitorId = '' ; public visitorInfo : Array < string > = [ ] ; public userIdForm = this . formBuilder . group ( { userId : [ '' , Validators . required ] , } ) ; param matomoTracker param formBuilder constructor ( private readonly matomoTracker , private readonly formBuilder ) { } /**
     * Angular OnInit lifecycle hook.
     */ ngOnInit ( ) { this . matomoTracker . getUserId ( ) . then ( ( uid ) => { this . userId = uid ; } ) ; this . matomoTracker . getVisitorId ( ) . then ( ( vid ) => { this . visitorId = vid ; } ) ; this . matomoTracker . getVisitorInfo ( ) . then ( ( vinf ) => { this . visitorInfo = vinf ; } ) ; } onUserIdSubmit ( ) { this . matomoTracker . setUserId ( this . userIdForm . value . userId ) ; this . userIdForm . reset ( ) ; this . matomoTracker . getUserId ( ) . then ( ( uid ) => { this . userId = uid ; } ) ; } onUserIdReset ( ) { this . matomoTracker . resetUserId ( ) ; this . matomoTracker . getUserId ( ) . then ( ( uid ) => { this . userId = uid ; } ) ; } }