Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1926 #1928

Merged
merged 2 commits into from
Apr 8, 2023
Merged

1926 #1928

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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