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

Release/4.0.2 #1379

Merged
merged 3 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@snowplow/browser-plugin-media-tracking",
"comment": "Fix ignored label property in the startHtml5MediaTracking call",
"type": "none"
}
],
"packageName": "@snowplow/browser-plugin-media-tracking"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@snowplow/javascript-tracker",
"comment": "Add `performanceNavigationTiming` option to JS contexts config",
"type": "none"
}
],
"packageName": "@snowplow/javascript-tracker"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@snowplow/tracker-core",
"comment": "Fix customPostPath configuration being ignored (close #1376)",
"type": "none"
}
],
"packageName": "@snowplow/tracker-core"
}
2 changes: 2 additions & 0 deletions libraries/tracker-core/src/emitter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ interface RequestResult {
export function newEmitter({
endpoint,
eventMethod = 'post',
postPath,
protocol,
port,
maxPostBytes = 40000,
Expand Down Expand Up @@ -320,6 +321,7 @@ export function newEmitter({
maxPostBytes,
useStm,
credentials,
postPath,
});
}

Expand Down
18 changes: 18 additions & 0 deletions libraries/tracker-core/test/emitter/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,3 +333,21 @@ test('adds a timeout to the request', async (t) => {
t.is(requests.length, 1);
t.is(await eventStore.count(), 1);
});

test('uses custom POST path configured in the emitter', async (t) => {
const requests: Request[] = [];
const mockFetch = createMockFetch(200, requests);
const eventStore = newInMemoryEventStore({});
const emitter: Emitter = newEmitter({
endpoint: 'https://example.com',
customFetch: mockFetch,
postPath: '/custom',
eventStore,
});

await emitter.input({ e: 'pv' });
await emitter.flush();

t.is(requests.length, 1);
t.is(requests[0].url, 'https://example.com/custom');
});
7 changes: 5 additions & 2 deletions plugins/browser-plugin-media-tracking/src/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,15 @@ function htmlContext(el: HTMLMediaElement): (() => SelfDescribingJson)[] {
}

export function setUpListeners(config: ElementConfig) {
const { id, video } = config;
const { id, video, label } = config;

startMediaTracking({
...config,
id,
player: updatePlayer(video),
player: {
label,
...updatePlayer(video)
},
context: (config.context ?? []).concat(htmlContext(video)),
});

Expand Down
16 changes: 16 additions & 0 deletions plugins/browser-plugin-media-tracking/tests/test.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,4 +312,20 @@ describe('MediaTrackingPlugin', () => {

expect(eventQueue.length).toBe(0);
});

it("adds label to tracked event", async () => {
const video = document.createElement('video');
video.id = id;
document.body.appendChild(video);

startHtml5MediaTracking({ id: 'id', label: 'foo', video, captureEvents: [MediaEventType.Play] });

video.play();

let playerContext = eventQueue[0].context.find(
(c) => c.schema === 'iglu:com.snowplowanalytics.snowplow/media_player/jsonschema/2-0-0'
)?.data;

expect(playerContext?.label).toEqual('foo');
});
});
1 change: 1 addition & 0 deletions trackers/javascript-tracker/src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ export interface JavaScriptTrackerConfiguration extends TrackerConfiguration {
geolocation: boolean;
clientHints: boolean | { includeHighEntropy: boolean };
webVitals: boolean | { loadWebVitalsScript?: boolean; webVitalsSource?: string };
performanceNavigationTiming: boolean;
};
}
11 changes: 3 additions & 8 deletions trackers/javascript-tracker/src/features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,8 @@ import * as WebVitals from '@snowplow/browser-plugin-web-vitals';
* @param configuration - The tracker configuration object
*/
export function Plugins(configuration: JavaScriptTrackerConfiguration) {
const {
performanceTiming,
gaCookies,
geolocation,
clientHints,
webVitals
} = configuration?.contexts ?? {};
const { performanceTiming, gaCookies, geolocation, clientHints, webVitals, performanceNavigationTiming } =
configuration?.contexts ?? {};
const activatedPlugins: Array<[BrowserPlugin, {} | Record<string, Function>]> = [];

if (plugins.performanceTiming && performanceTiming) {
Expand Down Expand Up @@ -148,7 +143,7 @@ export function Plugins(configuration: JavaScriptTrackerConfiguration) {
activatedPlugins.push([EventSpecificationsPlugin(), apiMethods]);
}

if (plugins.performanceNavigationTiming) {
if (plugins.performanceNavigationTiming && performanceNavigationTiming) {
const { PerformanceNavigationTimingPlugin, ...apiMethods } = PerformanceNavigationTiming;
activatedPlugins.push([PerformanceNavigationTimingPlugin(), apiMethods]);
}
Expand Down
61 changes: 61 additions & 0 deletions trackers/javascript-tracker/test/unit/plugin_features.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { SelfDescribingJson } from '@snowplow/tracker-core';
import { Plugins } from '../../src/features';

describe('Performance Navigation Timing', () => {
let windowSpy: any;

const otherContexts = {
webPage: false,
session: false,
performanceTiming: false,
gaCookies: false,
geolocation: false,
clientHints: false,
webVitals: false,
};

const hasPerformanceNavigationTimingContext = (plugins: ReturnType<typeof Plugins>): boolean => {
const pluginContexts = plugins.map((plugin) => plugin[0]?.contexts?.());
const hasPerformanceContext = pluginContexts.some((contexts?: SelfDescribingJson[]) =>
contexts?.some(
(context: { schema?: string }) => context.schema === 'iglu:org.w3/PerformanceNavigationTiming/jsonschema/1-0-0'
)
);
return hasPerformanceContext;
};

beforeEach(() => {
windowSpy = jest.spyOn(global, 'window', 'get');

// The PerformanceNavigationTiming context will only be added if the plugin can:
// - Access the `performance` object on the window
// - See that a value is returned from `getEntriesByType`
windowSpy.mockImplementation(() => ({
performance: {
getEntriesByType: () => [{}],
},
}));
});

it('Is enabled if contexts.performanceNavigationTiming is true', () => {
const plugins = Plugins({
contexts: {
performanceNavigationTiming: true,
...otherContexts,
},
});

expect(hasPerformanceNavigationTimingContext(plugins)).toBe(true);
});

it('Is disabled if contexts.performanceNavigationTiming is false', () => {
const plugins = Plugins({
contexts: {
performanceNavigationTiming: false,
...otherContexts,
},
});

expect(hasPerformanceNavigationTimingContext(plugins)).toBe(false);
});
});
Loading