Skip to content

Commit

Permalink
1926 (#1928)
Browse files Browse the repository at this point in the history
* 1926

* add comments
  • Loading branch information
leomendoza123 authored Apr 8, 2023
1 parent b3920b8 commit ccedf02
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/app/guards/authorize.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -72,15 +73,18 @@ export class AuthorizeGuard implements CanActivateChild {
}

reportAlreadyAuthorize(request: RequestInfoForm) {
console.log('reportAlreadyAuthorize')

const analyticsReports: Observable<void>[] = []
analyticsReports.push(
this._gtag.reportEvent(`Reauthorize`, 'RegGrowth', request)
)
analyticsReports.push(
this._googleTagManagerService.reportEvent(`Reauthorize`, request)
)
addEventListener('beforeunload', (event) => {
// temporally keeping the console logs to debug the issue
console.log('beforeunload', event)
this.redirectTroughGtmWasCalled = true
})

return forkJoin(analyticsReports).pipe(
tap(
Expand All @@ -102,7 +106,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)
})
)
}

Expand Down

0 comments on commit ccedf02

Please sign in to comment.