From ea0a687584da1e777bcd5760f0e0ddd8e40821ae Mon Sep 17 00:00:00 2001 From: Paul Boocock Date: Tue, 21 Dec 2021 19:46:30 +0000 Subject: [PATCH 001/475] Add support for custom headers (#1019) --- ...-1010_custom_headers_2021-11-26-16-12.json | 10 ++++++++++ ...-1010_custom_headers_2021-11-26-16-12.json | 10 ++++++++++ ...-1010_custom_headers_2021-11-26-16-12.json | 10 ++++++++++ .../browser-tracker-core/src/tracker/index.ts | 3 ++- .../src/tracker/out_queue.ts | 19 ++++++++++++++----- .../browser-tracker-core/src/tracker/types.ts | 6 ++++++ .../test/out_queue.test.ts | 3 ++- .../docs/browser-tracker.api.md | 1 + .../test/integration/integration.test.ts | 14 ++++++++++++++ .../test/pages/integration.html | 3 +++ trackers/javascript-tracker/tsconfig.json | 2 +- 11 files changed, 73 insertions(+), 8 deletions(-) create mode 100644 common/changes/@snowplow/browser-tracker-core/issue-1010_custom_headers_2021-11-26-16-12.json create mode 100644 common/changes/@snowplow/browser-tracker/issue-1010_custom_headers_2021-11-26-16-12.json create mode 100644 common/changes/@snowplow/javascript-tracker/issue-1010_custom_headers_2021-11-26-16-12.json diff --git a/common/changes/@snowplow/browser-tracker-core/issue-1010_custom_headers_2021-11-26-16-12.json b/common/changes/@snowplow/browser-tracker-core/issue-1010_custom_headers_2021-11-26-16-12.json new file mode 100644 index 000000000..a5eae6bbc --- /dev/null +++ b/common/changes/@snowplow/browser-tracker-core/issue-1010_custom_headers_2021-11-26-16-12.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@snowplow/browser-tracker-core", + "comment": "Add support for custom headers (#1010)", + "type": "none" + } + ], + "packageName": "@snowplow/browser-tracker-core" +} \ No newline at end of file diff --git a/common/changes/@snowplow/browser-tracker/issue-1010_custom_headers_2021-11-26-16-12.json b/common/changes/@snowplow/browser-tracker/issue-1010_custom_headers_2021-11-26-16-12.json new file mode 100644 index 000000000..d6185279a --- /dev/null +++ b/common/changes/@snowplow/browser-tracker/issue-1010_custom_headers_2021-11-26-16-12.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@snowplow/browser-tracker", + "comment": "Add support for custom headers (#1010)", + "type": "none" + } + ], + "packageName": "@snowplow/browser-tracker" +} \ No newline at end of file diff --git a/common/changes/@snowplow/javascript-tracker/issue-1010_custom_headers_2021-11-26-16-12.json b/common/changes/@snowplow/javascript-tracker/issue-1010_custom_headers_2021-11-26-16-12.json new file mode 100644 index 000000000..5a8c8441c --- /dev/null +++ b/common/changes/@snowplow/javascript-tracker/issue-1010_custom_headers_2021-11-26-16-12.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@snowplow/javascript-tracker", + "comment": "Add support for custom headers (#1010)", + "type": "none" + } + ], + "packageName": "@snowplow/javascript-tracker" +} \ No newline at end of file diff --git a/libraries/browser-tracker-core/src/tracker/index.ts b/libraries/browser-tracker-core/src/tracker/index.ts index 2b691a1ef..7f95c4fd0 100755 --- a/libraries/browser-tracker-core/src/tracker/index.ts +++ b/libraries/browser-tracker-core/src/tracker/index.ts @@ -261,7 +261,8 @@ export function Tracker( trackerConfiguration.useStm ?? true, trackerConfiguration.maxLocalStorageQueueSize ?? 1000, trackerConfiguration.connectionTimeout ?? 5000, - configAnonymousServerTracking + configAnonymousServerTracking, + trackerConfiguration.customHeaders ?? {} ), // Whether pageViewId should be regenerated after each trackPageView. Affect web_page context preservePageViewId = false, diff --git a/libraries/browser-tracker-core/src/tracker/out_queue.ts b/libraries/browser-tracker-core/src/tracker/out_queue.ts index 788a8db11..8fe4dacae 100644 --- a/libraries/browser-tracker-core/src/tracker/out_queue.ts +++ b/libraries/browser-tracker-core/src/tracker/out_queue.ts @@ -63,14 +63,15 @@ export function OutQueueManager( id: string, sharedSate: SharedState, useLocalStorage: boolean, - eventMethod: string | boolean | null, + eventMethod: string | boolean, postPath: string, bufferSize: number, maxPostBytes: number, useStm: boolean, maxLocalStorageQueueSize: number, connectionTimeout: number, - anonymousTracking: boolean + anonymousTracking: boolean, + customHeaders: Record ): OutQueue { type PostEvent = { evt: Record; @@ -84,9 +85,8 @@ export function OutQueueManager( //Force to lower case if its a string eventMethod = typeof eventMethod === 'string' ? eventMethod.toLowerCase() : eventMethod; - // Use the Beacon API if eventMethod is set null, true, or 'beacon'. - const isBeaconRequested = - eventMethod === null || eventMethod === true || eventMethod === 'beacon' || eventMethod === 'true', + // Use the Beacon API if eventMethod is set true, 'true', or 'beacon'. + const isBeaconRequested = eventMethod === true || eventMethod === 'beacon' || eventMethod === 'true', // Fall back to POST or GET for browsers which don't support Beacon API isBeaconAvailable = Boolean( isBeaconRequested && @@ -106,6 +106,10 @@ export function OutQueueManager( // Different queue names for GET and POST since they are stored differently queueName = `snowplowOutQueue_${id}_${usePost ? 'post2' : 'get'}`; + // Ensure we don't set headers when beacon is the requested eventMethod as we might fallback to POST + // and end up sending them in older browsers which don't support beacon leading to inconsistencies + if (isBeaconRequested) customHeaders = {}; + // Get buffer size or set 1 if unable to buffer bufferSize = (useLocalStorage && localStorageAccessible() && usePost && bufferSize) || 1; @@ -405,6 +409,11 @@ export function OutQueueManager( if (anonymousTracking) { xhr.setRequestHeader('SP-Anonymous', '*'); } + for (const header in customHeaders) { + if (Object.prototype.hasOwnProperty.call(customHeaders, header)) { + xhr.setRequestHeader(header, customHeaders[header]); + } + } return xhr; } diff --git a/libraries/browser-tracker-core/src/tracker/types.ts b/libraries/browser-tracker-core/src/tracker/types.ts index e29d834a3..f793f9656 100755 --- a/libraries/browser-tracker-core/src/tracker/types.ts +++ b/libraries/browser-tracker-core/src/tracker/types.ts @@ -192,6 +192,12 @@ export type TrackerConfiguration = { * @defaultValue [] */ plugins?: Array; + /** + * An object of key value pairs which represent headers to + * attach when sending a POST request, only works for POST + * @defaultValue `{}` + */ + customHeaders?: Record; }; /** diff --git a/libraries/browser-tracker-core/test/out_queue.test.ts b/libraries/browser-tracker-core/test/out_queue.test.ts index 7fb9c0c0a..3a2510385 100644 --- a/libraries/browser-tracker-core/test/out_queue.test.ts +++ b/libraries/browser-tracker-core/test/out_queue.test.ts @@ -50,7 +50,8 @@ describe('OutQueueManager', () => { false, maxQueueSize, 5000, - false + false, + {} ); }); diff --git a/trackers/browser-tracker/docs/browser-tracker.api.md b/trackers/browser-tracker/docs/browser-tracker.api.md index 6f6c7bd0d..7e60ab398 100644 --- a/trackers/browser-tracker/docs/browser-tracker.api.md +++ b/trackers/browser-tracker/docs/browser-tracker.api.md @@ -331,6 +331,7 @@ export type TrackerConfiguration = { webPage: boolean; }; plugins?: Array; + customHeaders?: Record; }; // @public diff --git a/trackers/javascript-tracker/test/integration/integration.test.ts b/trackers/javascript-tracker/test/integration/integration.test.ts index 5520703d6..26abea064 100755 --- a/trackers/javascript-tracker/test/integration/integration.test.ts +++ b/trackers/javascript-tracker/test/integration/integration.test.ts @@ -802,5 +802,19 @@ describe('Snowplow Micro integration', () => { }) ).toBe(false); }); + + it(`${method}: has custom headers attached if possible (not with Beacon or IE9)`, () => { + const results = log.filter( + (event: any) => + event.rawEvent.context.headers.includes('Content-Language: de-DE, en-CA') && + event.event.app_id === `sp-${method}` + ) as Array; + + if (method === 'beacon' || F.isMatch({ browserName: 'internet explorer', version: '9' }, browser.capabilities)) { + expect(results.length).toBe(0); + } else { + expect(results.length).toBeGreaterThanOrEqual(1); + } + }); }); }); diff --git a/trackers/javascript-tracker/test/pages/integration.html b/trackers/javascript-tracker/test/pages/integration.html index ff359e4d4..7365ae63c 100644 --- a/trackers/javascript-tracker/test/pages/integration.html +++ b/trackers/javascript-tracker/test/pages/integration.html @@ -72,6 +72,9 @@ contexts: { webPage: true, }, + customHeaders: { + 'Content-Language': 'de-DE, en-CA', + }, }); window.secondSnowplow('newTracker', 'b64off', collector_endpoint, { diff --git a/trackers/javascript-tracker/tsconfig.json b/trackers/javascript-tracker/tsconfig.json index 52f2c486d..235ff9915 100644 --- a/trackers/javascript-tracker/tsconfig.json +++ b/trackers/javascript-tracker/tsconfig.json @@ -1,7 +1,7 @@ { "extends": "./tsconfig.prod.json", "compilerOptions": { - "types": ["jest", "node", "@wdio/sync", "@wdio/jasmine-framework"] + "types": ["node", "@wdio/sync", "@wdio/jasmine-framework", "jest"] }, "include": ["./test/**/*.test.ts"] } From 3b6bdf7cbce91de3e3854fdb498216566533f71c Mon Sep 17 00:00:00 2001 From: Paul Boocock Date: Wed, 22 Dec 2021 16:21:53 +0000 Subject: [PATCH 002/475] Allow alternative Access-Control-Allow-Credentials values (close #808) Co-authored-by: Mitch Pierias --- .../issue-808_2021-12-21-20-04.json | 10 ++++++++++ .../browser-tracker/issue-808_2021-12-21-20-04.json | 10 ++++++++++ .../javascript-tracker/issue-808_2021-12-21-20-04.json | 10 ++++++++++ libraries/browser-tracker-core/src/tracker/index.ts | 3 ++- .../browser-tracker-core/src/tracker/out_queue.ts | 7 +++++-- libraries/browser-tracker-core/src/tracker/types.ts | 6 ++++++ libraries/browser-tracker-core/test/out_queue.test.ts | 3 ++- trackers/browser-tracker/docs/browser-tracker.api.md | 1 + 8 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 common/changes/@snowplow/browser-tracker-core/issue-808_2021-12-21-20-04.json create mode 100644 common/changes/@snowplow/browser-tracker/issue-808_2021-12-21-20-04.json create mode 100644 common/changes/@snowplow/javascript-tracker/issue-808_2021-12-21-20-04.json diff --git a/common/changes/@snowplow/browser-tracker-core/issue-808_2021-12-21-20-04.json b/common/changes/@snowplow/browser-tracker-core/issue-808_2021-12-21-20-04.json new file mode 100644 index 000000000..89b4636c0 --- /dev/null +++ b/common/changes/@snowplow/browser-tracker-core/issue-808_2021-12-21-20-04.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@snowplow/browser-tracker-core", + "comment": "Allow alternative Access-Control-Allow-Credentials values (#808)", + "type": "none" + } + ], + "packageName": "@snowplow/browser-tracker-core" +} \ No newline at end of file diff --git a/common/changes/@snowplow/browser-tracker/issue-808_2021-12-21-20-04.json b/common/changes/@snowplow/browser-tracker/issue-808_2021-12-21-20-04.json new file mode 100644 index 000000000..4bf9e6e48 --- /dev/null +++ b/common/changes/@snowplow/browser-tracker/issue-808_2021-12-21-20-04.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@snowplow/browser-tracker", + "comment": "Allow alternative Access-Control-Allow-Credentials values (#808)", + "type": "none" + } + ], + "packageName": "@snowplow/browser-tracker" +} \ No newline at end of file diff --git a/common/changes/@snowplow/javascript-tracker/issue-808_2021-12-21-20-04.json b/common/changes/@snowplow/javascript-tracker/issue-808_2021-12-21-20-04.json new file mode 100644 index 000000000..f71b35a22 --- /dev/null +++ b/common/changes/@snowplow/javascript-tracker/issue-808_2021-12-21-20-04.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@snowplow/javascript-tracker", + "comment": "Allow alternative Access-Control-Allow-Credentials values (#808)", + "type": "none" + } + ], + "packageName": "@snowplow/javascript-tracker" +} \ No newline at end of file diff --git a/libraries/browser-tracker-core/src/tracker/index.ts b/libraries/browser-tracker-core/src/tracker/index.ts index 7f95c4fd0..0426ba39d 100755 --- a/libraries/browser-tracker-core/src/tracker/index.ts +++ b/libraries/browser-tracker-core/src/tracker/index.ts @@ -262,7 +262,8 @@ export function Tracker( trackerConfiguration.maxLocalStorageQueueSize ?? 1000, trackerConfiguration.connectionTimeout ?? 5000, configAnonymousServerTracking, - trackerConfiguration.customHeaders ?? {} + trackerConfiguration.customHeaders ?? {}, + trackerConfiguration.withCredentials ?? true ), // Whether pageViewId should be regenerated after each trackPageView. Affect web_page context preservePageViewId = false, diff --git a/libraries/browser-tracker-core/src/tracker/out_queue.ts b/libraries/browser-tracker-core/src/tracker/out_queue.ts index 8fe4dacae..9faab75ea 100644 --- a/libraries/browser-tracker-core/src/tracker/out_queue.ts +++ b/libraries/browser-tracker-core/src/tracker/out_queue.ts @@ -57,6 +57,8 @@ export interface OutQueue { * @param maxLocalStorageQueueSize - Maximum number of queued events we will attempt to store in local storage * @param connectionTimeout - Defines how long to wait before aborting the request * @param anonymousTracking - Defines whether to set the SP-Anonymous header for anonymous tracking on GET and POST + * @param customHeaders - Allows custom headers to be defined and passed on XMLHttpRequest requests + * @param withCredentials - Sets the value of the withCredentials flag on XMLHttpRequest (GET and POST) requests * @returns object OutQueueManager instance */ export function OutQueueManager( @@ -71,7 +73,8 @@ export function OutQueueManager( maxLocalStorageQueueSize: number, connectionTimeout: number, anonymousTracking: boolean, - customHeaders: Record + customHeaders: Record, + withCredentials: boolean ): OutQueue { type PostEvent = { evt: Record; @@ -405,7 +408,7 @@ export function OutQueueManager( } else { xhr.open('GET', url, !sync); } - xhr.withCredentials = true; + xhr.withCredentials = withCredentials; if (anonymousTracking) { xhr.setRequestHeader('SP-Anonymous', '*'); } diff --git a/libraries/browser-tracker-core/src/tracker/types.ts b/libraries/browser-tracker-core/src/tracker/types.ts index f793f9656..0fff70f9b 100755 --- a/libraries/browser-tracker-core/src/tracker/types.ts +++ b/libraries/browser-tracker-core/src/tracker/types.ts @@ -92,6 +92,12 @@ export type TrackerConfiguration = { * @defaultValue 63072000 (2 years) */ cookieLifetime?: number; + /** + * Sets the value of the withCredentials flag + * on XMLHttpRequest (GET and POST) requests + * @defaultValue true + */ + withCredentials?: boolean; /** * How long until a session expires * @defaultValue 1800 (30 minutes) diff --git a/libraries/browser-tracker-core/test/out_queue.test.ts b/libraries/browser-tracker-core/test/out_queue.test.ts index 3a2510385..5b38787db 100644 --- a/libraries/browser-tracker-core/test/out_queue.test.ts +++ b/libraries/browser-tracker-core/test/out_queue.test.ts @@ -51,7 +51,8 @@ describe('OutQueueManager', () => { maxQueueSize, 5000, false, - {} + {}, + true ); }); diff --git a/trackers/browser-tracker/docs/browser-tracker.api.md b/trackers/browser-tracker/docs/browser-tracker.api.md index 7e60ab398..eff6366d0 100644 --- a/trackers/browser-tracker/docs/browser-tracker.api.md +++ b/trackers/browser-tracker/docs/browser-tracker.api.md @@ -311,6 +311,7 @@ export type TrackerConfiguration = { cookieSameSite?: CookieSameSite; cookieSecure?: boolean; cookieLifetime?: number; + withCredentials?: boolean; sessionCookieTimeout?: number; appId?: string; platform?: Platform; From 67e3277066a133ae692f5465777695240c467126 Mon Sep 17 00:00:00 2001 From: Greg Leonard <45019882+greg-el@users.noreply.github.com> Date: Wed, 22 Dec 2021 16:42:52 +0000 Subject: [PATCH 003/475] JavaScript Tracker HTML5 Media Tracking (close #805) Enables Snowplow tracking for HTML5 Video and Audio elements. Co-authored-by: Greg Leonard --- .../media-tracking_2021-11-15-17-12.json | 10 + .../media-tracking_2021-11-15-17-12.json | 10 + .../rush/browser-approved-packages.json | 4 + common/config/rush/pnpm-lock.yaml | 71 ++- common/config/rush/repo-state.json | 2 +- .../browser-plugin-media-tracking/.gitignore | 2 + .../.prettierignore | 84 +++ .../browser-plugin-media-tracking/.prettierrc | 7 + plugins/browser-plugin-media-tracking/LICENSE | 29 + .../browser-plugin-media-tracking/README.md | 88 +++ .../browser-plugin-media-tracking/banner.js | 44 ++ .../jest.config.js | 5 + .../package.json | 49 ++ .../rollup.config.js | 64 +++ .../src/buildMediaEvent.ts | 85 +++ .../src/constants.ts | 33 ++ .../src/contexts.ts | 238 ++++++++ .../src/eventGroups.ts | 28 + .../src/findMediaElement.ts | 41 ++ .../src/helperFunctions.ts | 100 ++++ .../src/index.ts | 244 +++++++++ .../src/mediaEvents.ts | 47 ++ .../src/types.ts | 72 +++ .../test/media.test.ts | 187 +++++++ .../tsconfig.json | 21 + rush.json | 6 + trackers/javascript-tracker/package.json | 3 +- .../javascript-tracker/rollup.config.test.js | 8 +- trackers/javascript-tracker/src/features.ts | 6 + .../test/integration/media.test.ts | 507 ++++++++++++++++++ trackers/javascript-tracker/test/micro.ts | 3 + .../test/pages/media/test-track.vtt | 4 + .../test/pages/media/test-video.mp4 | Bin 0 -> 7144 bytes .../test/pages/media/tracking-2-players.html | 59 ++ .../test/pages/media/tracking-2-trackers.html | 52 ++ .../test/pages/media/tracking-all-events.html | 51 ++ .../test/pages/media/tracking.html | 51 ++ trackers/javascript-tracker/tracker.config.ts | 1 + .../javascript-tracker/tracker.lite.config.ts | 1 + .../javascript-tracker/tracker.test.config.ts | 49 ++ 40 files changed, 2350 insertions(+), 16 deletions(-) create mode 100644 common/changes/@snowplow/browser-plugin-media-tracking/media-tracking_2021-11-15-17-12.json create mode 100644 common/changes/@snowplow/javascript-tracker/media-tracking_2021-11-15-17-12.json create mode 100644 plugins/browser-plugin-media-tracking/.gitignore create mode 100644 plugins/browser-plugin-media-tracking/.prettierignore create mode 100644 plugins/browser-plugin-media-tracking/.prettierrc create mode 100644 plugins/browser-plugin-media-tracking/LICENSE create mode 100644 plugins/browser-plugin-media-tracking/README.md create mode 100644 plugins/browser-plugin-media-tracking/banner.js create mode 100644 plugins/browser-plugin-media-tracking/jest.config.js create mode 100644 plugins/browser-plugin-media-tracking/package.json create mode 100644 plugins/browser-plugin-media-tracking/rollup.config.js create mode 100644 plugins/browser-plugin-media-tracking/src/buildMediaEvent.ts create mode 100644 plugins/browser-plugin-media-tracking/src/constants.ts create mode 100644 plugins/browser-plugin-media-tracking/src/contexts.ts create mode 100644 plugins/browser-plugin-media-tracking/src/eventGroups.ts create mode 100644 plugins/browser-plugin-media-tracking/src/findMediaElement.ts create mode 100644 plugins/browser-plugin-media-tracking/src/helperFunctions.ts create mode 100644 plugins/browser-plugin-media-tracking/src/index.ts create mode 100644 plugins/browser-plugin-media-tracking/src/mediaEvents.ts create mode 100644 plugins/browser-plugin-media-tracking/src/types.ts create mode 100644 plugins/browser-plugin-media-tracking/test/media.test.ts create mode 100644 plugins/browser-plugin-media-tracking/tsconfig.json create mode 100644 trackers/javascript-tracker/test/integration/media.test.ts create mode 100644 trackers/javascript-tracker/test/pages/media/test-track.vtt create mode 100644 trackers/javascript-tracker/test/pages/media/test-video.mp4 create mode 100644 trackers/javascript-tracker/test/pages/media/tracking-2-players.html create mode 100644 trackers/javascript-tracker/test/pages/media/tracking-2-trackers.html create mode 100644 trackers/javascript-tracker/test/pages/media/tracking-all-events.html create mode 100644 trackers/javascript-tracker/test/pages/media/tracking.html create mode 100644 trackers/javascript-tracker/tracker.test.config.ts diff --git a/common/changes/@snowplow/browser-plugin-media-tracking/media-tracking_2021-11-15-17-12.json b/common/changes/@snowplow/browser-plugin-media-tracking/media-tracking_2021-11-15-17-12.json new file mode 100644 index 000000000..38cd19aee --- /dev/null +++ b/common/changes/@snowplow/browser-plugin-media-tracking/media-tracking_2021-11-15-17-12.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@snowplow/browser-plugin-media-tracking", + "comment": "Add HTML5 Media Tracking plugin (#805)", + "type": "none" + } + ], + "packageName": "@snowplow/browser-plugin-media-tracking" +} \ No newline at end of file diff --git a/common/changes/@snowplow/javascript-tracker/media-tracking_2021-11-15-17-12.json b/common/changes/@snowplow/javascript-tracker/media-tracking_2021-11-15-17-12.json new file mode 100644 index 000000000..357ea248e --- /dev/null +++ b/common/changes/@snowplow/javascript-tracker/media-tracking_2021-11-15-17-12.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@snowplow/javascript-tracker", + "comment": "Add HTML5 Media Tracking plugin (#805)", + "type": "none" + } + ], + "packageName": "@snowplow/javascript-tracker" +} \ No newline at end of file diff --git a/common/config/rush/browser-approved-packages.json b/common/config/rush/browser-approved-packages.json index 90f9f87c8..b69b6daf0 100644 --- a/common/config/rush/browser-approved-packages.json +++ b/common/config/rush/browser-approved-packages.json @@ -90,6 +90,10 @@ "name": "@snowplow/browser-plugin-link-click-tracking", "allowedCategories": [ "trackers" ] }, + { + "name": "@snowplow/browser-plugin-media-tracking", + "allowedCategories": [ "trackers" ] + }, { "name": "@snowplow/browser-plugin-optimizely", "allowedCategories": [ "trackers" ] diff --git a/common/config/rush/pnpm-lock.yaml b/common/config/rush/pnpm-lock.yaml index 631ad51dd..48d3462a2 100644 --- a/common/config/rush/pnpm-lock.yaml +++ b/common/config/rush/pnpm-lock.yaml @@ -653,6 +653,49 @@ importers: ts-jest: 26.5.0_jest@26.6.3+typescript@4.3.5 typescript: 4.3.5 + ../../plugins/browser-plugin-media-tracking: + specifiers: + '@ampproject/rollup-plugin-closure-compiler': ^0.27.0 + '@rollup/plugin-commonjs': ^17.1.0 + '@rollup/plugin-node-resolve': ^11.2.0 + '@snowplow/browser-tracker-core': workspace:* + '@snowplow/tracker-core': workspace:* + '@types/jest': ^26.0.20 + '@typescript-eslint/eslint-plugin': ^4.9.0 + '@typescript-eslint/parser': ^4.9.0 + eslint: ^7.7.0 + jest: ^26.6.3 + jest-standard-reporter: ^2.0.0 + rollup: ^2.41.1 + rollup-plugin-cleanup: ^3.2.1 + rollup-plugin-license: ^2.2.0 + rollup-plugin-terser: ^7.0.2 + rollup-plugin-ts: ^1.4.0 + ts-jest: ^26.5.0 + tslib: ^2.3.0 + typescript: ^4.3.5 + dependencies: + '@snowplow/browser-tracker-core': link:../../libraries/browser-tracker-core + '@snowplow/tracker-core': link:../../libraries/tracker-core + tslib: 2.3.0 + devDependencies: + '@ampproject/rollup-plugin-closure-compiler': 0.27.0_rollup@2.41.1 + '@rollup/plugin-commonjs': 17.1.0_rollup@2.41.1 + '@rollup/plugin-node-resolve': 11.2.0_rollup@2.41.1 + '@types/jest': 26.0.20 + '@typescript-eslint/eslint-plugin': 4.11.0_03dc75c18e96dfbc156c58d5a8cd7146 + '@typescript-eslint/parser': 4.11.0_eslint@7.16.0+typescript@4.3.5 + eslint: 7.16.0 + jest: 26.6.3 + jest-standard-reporter: 2.0.0 + rollup: 2.41.1 + rollup-plugin-cleanup: 3.2.1_rollup@2.41.1 + rollup-plugin-license: 2.2.0_rollup@2.41.1 + rollup-plugin-terser: 7.0.2_rollup@2.41.1 + rollup-plugin-ts: 1.4.0_rollup@2.41.1+typescript@4.3.5 + ts-jest: 26.5.0_jest@26.6.3+typescript@4.3.5 + typescript: 4.3.5 + ../../plugins/browser-plugin-optimizely: specifiers: '@ampproject/rollup-plugin-closure-compiler': ^0.27.0 @@ -957,6 +1000,7 @@ importers: '@snowplow/browser-plugin-ga-cookies': workspace:* '@snowplow/browser-plugin-geolocation': workspace:* '@snowplow/browser-plugin-link-click-tracking': workspace:* + '@snowplow/browser-plugin-media-tracking': workspace:* '@snowplow/browser-plugin-optimizely': workspace:* '@snowplow/browser-plugin-optimizely-x': workspace:* '@snowplow/browser-plugin-performance-timing': workspace:* @@ -976,7 +1020,7 @@ importers: '@wdio/spec-reporter': ^6.11.0 '@wdio/static-server-service': ^6.10.10 '@wdio/sync': ^6.11.0 - chromedriver: ^92.0.1 + chromedriver: ^94.0.0 dockerode: ^3.2.1 jest: ^26.6.3 jest-standard-reporter: ^2.0.0 @@ -1007,6 +1051,7 @@ importers: '@snowplow/browser-plugin-ga-cookies': link:../../plugins/browser-plugin-ga-cookies '@snowplow/browser-plugin-geolocation': link:../../plugins/browser-plugin-geolocation '@snowplow/browser-plugin-link-click-tracking': link:../../plugins/browser-plugin-link-click-tracking + '@snowplow/browser-plugin-media-tracking': link:../../plugins/browser-plugin-media-tracking '@snowplow/browser-plugin-optimizely': link:../../plugins/browser-plugin-optimizely '@snowplow/browser-plugin-optimizely-x': link:../../plugins/browser-plugin-optimizely-x '@snowplow/browser-plugin-performance-timing': link:../../plugins/browser-plugin-performance-timing @@ -1033,7 +1078,7 @@ importers: '@wdio/spec-reporter': 6.11.0_@wdio+cli@6.12.1 '@wdio/static-server-service': 6.10.10 '@wdio/sync': 6.11.0 - chromedriver: 92.0.1 + chromedriver: 94.0.0 dockerode: 3.2.1 jest: 26.6.3_ts-node@9.1.1 jest-standard-reporter: 2.0.0 @@ -1050,7 +1095,7 @@ importers: ts-jest: 26.5.0_jest@26.6.3+typescript@4.3.5 ts-node: 9.1.1_typescript@4.3.5 typescript: 4.3.5 - wdio-chromedriver-service: 6.0.4_4a3e955417911ce9093a06b981efd7b7 + wdio-chromedriver-service: 6.0.4_25d7422259640475936d8a95dcd9427b ../../trackers/node-tracker: specifiers: @@ -4133,10 +4178,10 @@ packages: resolution: {integrity: sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA==} dev: true - /axios/0.21.1: - resolution: {integrity: sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==} + /axios/0.21.4: + resolution: {integrity: sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==} dependencies: - follow-redirects: 1.13.1 + follow-redirects: 1.14.5 transitivePeerDependencies: - debug dev: true @@ -4795,14 +4840,14 @@ packages: rimraf: 3.0.2 dev: true - /chromedriver/92.0.1: - resolution: {integrity: sha512-LptlDVCs1GgyFNVbRoHzzy948JDVzTgGiVPXjNj385qXKQP3hjAVBIgyvb/Hco0xSEW8fjwJfsm1eQRmu6t4pQ==} + /chromedriver/94.0.0: + resolution: {integrity: sha512-x4hK7R7iOyAhdLHJEcOyGBW/oa2kno6AqpHVLd+n3G7c2Vk9XcAXMz84XhNItqykJvTc6E3z/JRIT1eHYH//Eg==} engines: {node: '>=10'} hasBin: true requiresBuild: true dependencies: '@testim/chrome-version': 1.0.7 - axios: 0.21.1 + axios: 0.21.4 del: 6.0.0 extract-zip: 2.0.1 https-proxy-agent: 5.0.0 @@ -6342,8 +6387,8 @@ packages: resolution: {integrity: sha512-tW+UkmtNg/jv9CSofAKvgVcO7c2URjhTdW1ZTkcAritblu8tajiYy7YisnIflEwtKssCtOxpnBRoCB7iap0/TA==} dev: true - /follow-redirects/1.13.1: - resolution: {integrity: sha512-SSG5xmZh1mkPGyKzjZP8zLjltIfpW32Y5QpdNJyjcfGxK3qo3NDDkZOZSFiGn1A6SclQxY9GzEwAHQ3dmYRWpg==} + /follow-redirects/1.14.5: + resolution: {integrity: sha512-wtphSXy7d4/OR+MvIFbCVBDzZ5520qV8XfPklSN5QtxuMUJZ+b0Wnst1e1lCDocfzuCkHqj8k0FpZqO+UIaKNA==} engines: {node: '>=4.0'} peerDependencies: debug: '*' @@ -11726,7 +11771,7 @@ packages: defaults: 1.0.3 dev: true - /wdio-chromedriver-service/6.0.4_4a3e955417911ce9093a06b981efd7b7: + /wdio-chromedriver-service/6.0.4_25d7422259640475936d8a95dcd9427b: resolution: {integrity: sha512-ed0ctxRJ4KbhAX/BkGUFS/sy6zDrZ3oB1Tqvokrs3r7GPX115w/AcOySofXdAk7Pdjm2JLDW/marHG/LmVoBuw==} engines: {node: '>=10.0.0'} peerDependencies: @@ -11734,7 +11779,7 @@ packages: chromedriver: '*' dependencies: '@wdio/cli': 6.12.1 - chromedriver: 92.0.1 + chromedriver: 94.0.0 fs-extra: 9.0.1 dev: true diff --git a/common/config/rush/repo-state.json b/common/config/rush/repo-state.json index f192b6671..828050afb 100644 --- a/common/config/rush/repo-state.json +++ b/common/config/rush/repo-state.json @@ -1,5 +1,5 @@ // DO NOT MODIFY THIS FILE MANUALLY BUT DO COMMIT IT. It is generated and used by Rush. { - "pnpmShrinkwrapHash": "42a8258d87b6908622c307febeb387666d00a459", + "pnpmShrinkwrapHash": "8864df375b241f29eb4e7c4da2577817cfaefe69", "preferredVersionsHash": "bf21a9e8fbc5a3846fb05b4fa0859e0917b2202f" } diff --git a/plugins/browser-plugin-media-tracking/.gitignore b/plugins/browser-plugin-media-tracking/.gitignore new file mode 100644 index 000000000..f06235c46 --- /dev/null +++ b/plugins/browser-plugin-media-tracking/.gitignore @@ -0,0 +1,2 @@ +node_modules +dist diff --git a/plugins/browser-plugin-media-tracking/.prettierignore b/plugins/browser-plugin-media-tracking/.prettierignore new file mode 100644 index 000000000..9bf4fb248 --- /dev/null +++ b/plugins/browser-plugin-media-tracking/.prettierignore @@ -0,0 +1,84 @@ +#------------------------------------------------------------------------------------------------------------------- +# Keep this section in sync with .gitignore +#------------------------------------------------------------------------------------------------------------------- + +# Logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# Runtime data +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env + +# next.js build output +.next + +# OS X temporary files +.DS_Store + +# IDE files +.idea/ +.DS_Store + +#------------------------------------------------------------------------------------------------------------------- +# Prettier-specific overrides +#------------------------------------------------------------------------------------------------------------------- + +# Package manager files +pnpm-lock.yaml +yarn.lock +package-lock.json +shrinkwrap.json + +# Build outputs +dist +lib + +# Prettier reformats code blocks inside Markdown, which affects rendered output +*.md \ No newline at end of file diff --git a/plugins/browser-plugin-media-tracking/.prettierrc b/plugins/browser-plugin-media-tracking/.prettierrc new file mode 100644 index 000000000..3bb548593 --- /dev/null +++ b/plugins/browser-plugin-media-tracking/.prettierrc @@ -0,0 +1,7 @@ +{ + "trailingComma": "es5", + "tabWidth": 2, + "singleQuote": true, + "printWidth": 120, + "endOfLine": "auto" +} diff --git a/plugins/browser-plugin-media-tracking/LICENSE b/plugins/browser-plugin-media-tracking/LICENSE new file mode 100644 index 000000000..265053606 --- /dev/null +++ b/plugins/browser-plugin-media-tracking/LICENSE @@ -0,0 +1,29 @@ +BSD 3-Clause License + +Copyright (c) 2021 Snowplow Analytics Ltd +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/plugins/browser-plugin-media-tracking/README.md b/plugins/browser-plugin-media-tracking/README.md new file mode 100644 index 000000000..730f717fd --- /dev/null +++ b/plugins/browser-plugin-media-tracking/README.md @@ -0,0 +1,88 @@ +# Snowplow Media Tracking + +[![License][license-image]](LICENSE) + +Browser Plugin to be used with `@snowplow/browser-tracker`. + +Adds HTML5 Video and Audio tracking events to your Snowplow tracking. + +## Maintainer quick start + +Part of the Snowplow JavaScript Tracker monorepo. +Build with [Node.js](https://nodejs.org/en/) (12 LTS or 14 LTS) and [Rush](https://rushjs.io/). + +### Setup repository + +```bash +npm install -g @microsoft/rush +git clone https://github.com/snowplow/snowplow-javascript-tracker.git +rush update +``` + +### Package Installation + +With npm: + +```bash +npm install @snowplow/browser-plugin-media-tracking +``` + +## Usage + +Initialize your tracker with the MediaTrackingPlugin: + +```js +import { newTracker } from '@snowplow/browser-tracker'; +import { MediaTrackingPlugin } from 'snowplow-browser-media-tracker'; + +newTracker('sp2', '{{collector}}', { plugins: [ MediaTrackingPlugin() ] }); // Also stores reference at module level +``` + +Then, use the `enableMediaTracking` function described below to produce events from your HTML5 Video/Audio element(s). + +```js +enableMediaTracking({ id, options?: { label?, captureEvents?, boundaries?, volumeChangeTrackingInterval? } }) +``` + +| Parameter | Type | Default | Description | Required | +| -------------------------------------- | ---------- | ------------------- | --------------------------------------------------------- | -------- | +| `id` | `string` | - | The HTML id attribute of the media element | Yes | +| `options.label` | `string` | - | An identifiable custom label sent with the event | No | +| `options.captureEvents` | `string[]` | `['DefaultEvents']` | The name(s) of the events to capture | No | +| `options.boundaries` | `number[]` | `[10, 25, 50, 75]` | The progress percentages to fire an event at (if enabled) | No | +| `options.volumeChangeTrackingInterval` | `number` | `250` | The rate at which volume events can be sent | No | + +## Example Usage + +```html + ... +