Commit 67db7b30 authored by Rajkumar-D's avatar Rajkumar-D
Browse files

Adding user-Id for google analytics

parent 183337fb
Pipeline #278449 passed with stages
in 5 minutes and 7 seconds
......@@ -12,6 +12,7 @@
import { Component } from '@angular/core';
import { Router, NavigationEnd } from '@angular/router';
import { environment } from '../environments/environment';
import { WebinAuthenticationService } from './webin-authentication.service';
declare let gtag: Function;
@Component({
......@@ -22,7 +23,8 @@ declare let gtag: Function;
export class AppComponent {
title = 'Webin';
constructor(public router: Router) {
constructor(public router: Router,
private _webinAuthService: WebinAuthenticationService) {
// Adding code for Google Analytics
if (environment.googleAnalyticsTrackingId) {
// register google tag manager
......@@ -41,20 +43,28 @@ export class AppComponent {
document.head.appendChild(gaScript);
}
// Triggering route event.
// Triggering route event for Google Analytics.
this.router.events.subscribe(event => {
var submissionAccount = JSON.parse(
this._webinAuthService.getSubmissionAccount());
if (event instanceof NavigationEnd) {
gtag('config', environment.googleAnalyticsTrackingId,
{
'page_path': event.urlAfterRedirects,
'page_location': event.url
'page_location': event.url,
'user_id': submissionAccount ? submissionAccount.id : ""
}
);
if (submissionAccount) {
gtag('set', 'user_properties', {
'submission_account_id': submissionAccount.id
});
}
}
}
)
})
}
}
......@@ -77,6 +77,8 @@ export class LoginComponent implements OnInit {
this._router.navigateByUrl('');
if (!this._webinAuthenticationService.ega) {
this._webinAuthenticationService.setSubmissionAccount();
} else {
this._webinAuthenticationService.setEgaSubmissionAccount();
}
}
},
......
......@@ -162,6 +162,11 @@ export class WebinAuthenticationService implements WebinAuthenticationServiceInt
});
}
setEgaSubmissionAccount() {
// For Google analytics
sessionStorage.setItem('submissionAccount', '{"id":"' + this.username + '"}');
}
isBroker(): boolean {
var submissionAccount = JSON.parse(
sessionStorage.getItem('submissionAccount')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment