-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PIDP-898 Add Snowplow web tracker (#519)
* add snowplow script * add snowplow to allowed CSP scripts * move to scripts * mv * add script * Revert "add script" This reverts commit 0b9c3e3. * move to script src * set CSP_connect * add script-src-elem directive for the other script * maybe now * mv * fix * try again * s * fix2 * hope it works * add window ref service * snowplow collector as a service * run snowplow * track link clicking on login page * track link clicking on help page * rearrange lifecycle methods to have ngOninit last * dmft * hcim * imms * prescription * add custom event tracking method * track PAS link clicks * saeforms * unused
- Loading branch information
Showing
17 changed files
with
236 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -108,9 +108,8 @@ nginx: | |
set $CSP_style "style-src 'self' 'unsafe-inline' *.googleapis.com *.gstatic.com https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"; | ||
set $CSP_font "font-src 'self' data: *.googleapis.com *.gstatic.com"; | ||
set $CSP_frame "frame-ancestors 'self' *.oidc.gov.bc.ca oidc.gov.bc.ca"; | ||
set $CSP_SCRIPT "script-src 'self' 'unsafe-inline' https://code.jquery.com/jquery-3.6.0.min.js"; | ||
set $CSP "default-src 'self' 'unsafe-inline' *.hlth.gov.bc.ca ; ${CSP_style} ; ${CSP_font} ; ${CSP_SCRIPT} ; ${CSP_frame}"; | ||
set $CSP_SCRIPT "script-src 'self' 'unsafe-inline' https://code.jquery.com/jquery-3.6.0.min.js https://www2.gov.bc.ca/StaticWebResources/static/sp/sp-2-14-0.js"; | ||
set $CSP "default-src 'self' 'unsafe-inline' *.hlth.gov.bc.ca https://spm.apps.gov.bc.ca ; ${CSP_style} ; ${CSP_font} ; ${CSP_SCRIPT} ; ${CSP_frame}"; | ||
add_header Content-Security-Policy $CSP; | ||
add_header X-Frame-Options "ALLOW-FROM dev.oidc.gov.bc.ca oidc.gov.bc.ca" always; | ||
add_header X-XSS-Protection "1; mode=block" always; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
workspace/apps/pidp/src/app/core/services/snowplow.service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { SnowplowService } from './snowplow.service'; | ||
|
||
describe('SnowplowService', () => { | ||
let service: SnowplowService; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({}); | ||
service = TestBed.inject(SnowplowService); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
}); |
53 changes: 53 additions & 0 deletions
53
workspace/apps/pidp/src/app/core/services/snowplow.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { Injectable } from '@angular/core'; | ||
|
||
import { | ||
ISnowplowWindow, | ||
WindowRefService, | ||
} from '@core/services/window-ref.service'; | ||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class SnowplowService { | ||
private _window: ISnowplowWindow; | ||
|
||
public constructor(window: WindowRefService) { | ||
this._window = window.nativeWindow; | ||
if (this._window.snowplow) { | ||
const collector = 'spm.apps.gov.bc.ca'; | ||
this._window.snowplow('newTracker', 'rt', collector, { | ||
appId: 'Snowplow_standalone', | ||
cookieLifetime: 86400 * 548, | ||
platform: 'web', | ||
post: true, | ||
forceSecureTracker: true, | ||
contexts: { | ||
webPage: true, | ||
performanceTiming: true, | ||
}, | ||
}); | ||
this._window.snowplow('enableActivityTracking', 30, 30); // Ping every 30 seconds after 30 seconds | ||
this._window.snowplow('enableLinkClickTracking'); | ||
} | ||
} | ||
|
||
public trackPageView(): void { | ||
if (this._window.snowplow) { | ||
this._window.snowplow('trackPageView'); | ||
} | ||
} | ||
|
||
// Add Snowplow click listeners to all links which do not already have them | ||
public refreshLinkClickTracking(): void { | ||
if (this._window.snowplow) { | ||
this._window.snowplow('refreshLinkClickTracking'); | ||
} | ||
} | ||
|
||
// Add Snowplow click listeners to a custom click event | ||
public trackLinkClick(url: string): void { | ||
if (this._window.snowplow) { | ||
this._window.snowplow('trackLinkClick', url); | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
workspace/apps/pidp/src/app/core/services/window-ref.service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { WindowRefService } from './window-ref.service'; | ||
|
||
describe('WindowRefService', () => { | ||
let service: WindowRefService; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({}); | ||
service = TestBed.inject(WindowRefService); | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
}); |
23 changes: 23 additions & 0 deletions
23
workspace/apps/pidp/src/app/core/services/window-ref.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import { Injectable } from '@angular/core'; | ||
|
||
export interface ISnowplowWindow extends Window { | ||
snowplow: (...args: any) => void; | ||
} | ||
|
||
function getWindow(): any { | ||
return window; | ||
} | ||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class WindowRefService { | ||
/** | ||
* @description | ||
* Get a reference to the native window object. | ||
*/ | ||
public get nativeWindow(): ISnowplowWindow { | ||
return getWindow(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.