From 29895a93cda2a195d92603e06932462f50a4604c Mon Sep 17 00:00:00 2001 From: Leonardo Mendoza Fernadez Date: Fri, 7 Apr 2023 13:55:11 -0600 Subject: [PATCH 1/2] 1926 --- src/app/guards/authorize.guard.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/app/guards/authorize.guard.ts b/src/app/guards/authorize.guard.ts index 83feb793ba..b0fe72eafa 100644 --- a/src/app/guards/authorize.guard.ts +++ b/src/app/guards/authorize.guard.ts @@ -23,6 +23,7 @@ import { GoogleTagManagerService } from '../core/google-tag-manager/google-tag-m }) export class AuthorizeGuard implements CanActivateChild { lastRedirectUrl: string + redirectTroughGtmWasCalled: boolean constructor( private _user: UserService, private _router: Router, @@ -72,8 +73,6 @@ export class AuthorizeGuard implements CanActivateChild { } reportAlreadyAuthorize(request: RequestInfoForm) { - console.log('reportAlreadyAuthorize') - const analyticsReports: Observable[] = [] analyticsReports.push( this._gtag.reportEvent(`Reauthorize`, 'RegGrowth', request) @@ -81,6 +80,10 @@ export class AuthorizeGuard implements CanActivateChild { analyticsReports.push( this._googleTagManagerService.reportEvent(`Reauthorize`, request) ) + addEventListener('beforeunload', (event) => { + console.log('beforeunload', event) + this.redirectTroughGtmWasCalled = true + }) return forkJoin(analyticsReports).pipe( tap( @@ -102,7 +105,14 @@ export class AuthorizeGuard implements CanActivateChild { // This add blockers will also not trigger the `catchError` above, since GTM will not throw an error // So this timeout will redirect the user to the redirectURL after 4 seconds of waiting for the GTM redirect switchMap(() => timer(4000)), - switchMap(() => this.sendUserToRedirectURL(request)) + switchMap(() => { + // Checks that a redirect by GTM is not already in progress + // Stop a second redirect to happen if the a browser event `beforeunload` event was triggered + if (this.redirectTroughGtmWasCalled) { + return NEVER + } + return this.sendUserToRedirectURL(request) + }) ) } From e1befecaabb9c29abc54c9d690fee38a7551a626 Mon Sep 17 00:00:00 2001 From: Leonardo Mendoza Fernadez Date: Fri, 7 Apr 2023 13:57:40 -0600 Subject: [PATCH 2/2] add comments --- src/app/guards/authorize.guard.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/app/guards/authorize.guard.ts b/src/app/guards/authorize.guard.ts index b0fe72eafa..4bca7c0e7d 100644 --- a/src/app/guards/authorize.guard.ts +++ b/src/app/guards/authorize.guard.ts @@ -81,6 +81,7 @@ export class AuthorizeGuard implements CanActivateChild { this._googleTagManagerService.reportEvent(`Reauthorize`, request) ) addEventListener('beforeunload', (event) => { + // temporally keeping the console logs to debug the issue console.log('beforeunload', event) this.redirectTroughGtmWasCalled = true })