From cba41e827665478b6b0603bced7120e7abf6d63b Mon Sep 17 00:00:00 2001 From: Matus Tomlein Date: Mon, 6 Jan 2025 12:43:28 +0100 Subject: [PATCH] Add sessionContext and devicePlatform options to React Native tracker configuration (#1401) --- .../react-native-tracker.sessionconfiguration.md | 1 + ...racker.sessionconfiguration.sessioncontext.md | 13 +++++++++++++ ...racker.trackerconfiguration.deviceplatform.md | 13 +++++++++++++ .../react-native-tracker.trackerconfiguration.md | 1 + .../react-native-tracker.api.md | 3 +++ .../src/plugins/session/index.ts | 11 +++++++---- trackers/react-native-tracker/src/tracker.ts | 2 +- trackers/react-native-tracker/src/types.ts | 16 +++++++++++++--- 8 files changed, 52 insertions(+), 8 deletions(-) create mode 100644 api-docs/docs/react-native-tracker/markdown/react-native-tracker.sessionconfiguration.sessioncontext.md create mode 100644 api-docs/docs/react-native-tracker/markdown/react-native-tracker.trackerconfiguration.deviceplatform.md diff --git a/api-docs/docs/react-native-tracker/markdown/react-native-tracker.sessionconfiguration.md b/api-docs/docs/react-native-tracker/markdown/react-native-tracker.sessionconfiguration.md index 3dc56ce35..6fa6b8a7d 100644 --- a/api-docs/docs/react-native-tracker/markdown/react-native-tracker.sessionconfiguration.md +++ b/api-docs/docs/react-native-tracker/markdown/react-native-tracker.sessionconfiguration.md @@ -18,4 +18,5 @@ export interface SessionConfiguration | --- | --- | --- | | [backgroundSessionTimeout?](./react-native-tracker.sessionconfiguration.backgroundsessiontimeout.md) | number | (Optional) The amount of time in seconds before the session id is updated while the app is in the background | | [foregroundSessionTimeout?](./react-native-tracker.sessionconfiguration.foregroundsessiontimeout.md) | number | (Optional) The amount of time in seconds before the session id is updated while the app is in the foreground | +| [sessionContext?](./react-native-tracker.sessionconfiguration.sessioncontext.md) | boolean | (Optional) Whether session context is attached to tracked events. | diff --git a/api-docs/docs/react-native-tracker/markdown/react-native-tracker.sessionconfiguration.sessioncontext.md b/api-docs/docs/react-native-tracker/markdown/react-native-tracker.sessionconfiguration.sessioncontext.md new file mode 100644 index 000000000..dc356ecdd --- /dev/null +++ b/api-docs/docs/react-native-tracker/markdown/react-native-tracker.sessionconfiguration.sessioncontext.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [@snowplow/react-native-tracker](./react-native-tracker.md) > [SessionConfiguration](./react-native-tracker.sessionconfiguration.md) > [sessionContext](./react-native-tracker.sessionconfiguration.sessioncontext.md) + +## SessionConfiguration.sessionContext property + +Whether session context is attached to tracked events. + +Signature: + +```typescript +sessionContext?: boolean; +``` diff --git a/api-docs/docs/react-native-tracker/markdown/react-native-tracker.trackerconfiguration.deviceplatform.md b/api-docs/docs/react-native-tracker/markdown/react-native-tracker.trackerconfiguration.deviceplatform.md new file mode 100644 index 000000000..3f09b591e --- /dev/null +++ b/api-docs/docs/react-native-tracker/markdown/react-native-tracker.trackerconfiguration.deviceplatform.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [@snowplow/react-native-tracker](./react-native-tracker.md) > [TrackerConfiguration](./react-native-tracker.trackerconfiguration.md) > [devicePlatform](./react-native-tracker.trackerconfiguration.deviceplatform.md) + +## TrackerConfiguration.devicePlatform property + +The device platform the tracker runs on. + +Signature: + +```typescript +devicePlatform?: Platform; +``` diff --git a/api-docs/docs/react-native-tracker/markdown/react-native-tracker.trackerconfiguration.md b/api-docs/docs/react-native-tracker/markdown/react-native-tracker.trackerconfiguration.md index 0815e0bb7..b07a8275f 100644 --- a/api-docs/docs/react-native-tracker/markdown/react-native-tracker.trackerconfiguration.md +++ b/api-docs/docs/react-native-tracker/markdown/react-native-tracker.trackerconfiguration.md @@ -17,6 +17,7 @@ export interface TrackerConfiguration | Property | Type | Description | | --- | --- | --- | | [appId?](./react-native-tracker.trackerconfiguration.appid.md) | string | (Optional) The application ID | +| [devicePlatform?](./react-native-tracker.trackerconfiguration.deviceplatform.md) | Platform | (Optional) The device platform the tracker runs on. | | [encodeBase64?](./react-native-tracker.trackerconfiguration.encodebase64.md) | boolean | (Optional) Whether unstructured events and custom contexts should be base64 encoded. | | [namespace](./react-native-tracker.trackerconfiguration.namespace.md) | string | The namespace of the tracker | | [plugins?](./react-native-tracker.trackerconfiguration.plugins.md) | BrowserPlugin\[\] | (Optional) Inject plugins which will be evaluated for each event | diff --git a/api-docs/docs/react-native-tracker/react-native-tracker.api.md b/api-docs/docs/react-native-tracker/react-native-tracker.api.md index 0914ed86a..e1928b9e6 100644 --- a/api-docs/docs/react-native-tracker/react-native-tracker.api.md +++ b/api-docs/docs/react-native-tracker/react-native-tracker.api.md @@ -6,6 +6,7 @@ import { BrowserPlugin } from '@snowplow/browser-tracker-core'; import { BrowserPluginConfiguration } from '@snowplow/browser-tracker-core'; +import { Platform } from '@snowplow/browser-tracker-core'; import { ScreenTrackingConfiguration } from '@snowplow/browser-plugin-screen-tracking'; // @public @@ -464,6 +465,7 @@ export type SelfDescribing> = SelfDescribingJson; export interface SessionConfiguration { backgroundSessionTimeout?: number; foregroundSessionTimeout?: number; + sessionContext?: boolean; } // @public @@ -511,6 +513,7 @@ export type TimingProps = { // @public export interface TrackerConfiguration { appId?: string; + devicePlatform?: Platform; encodeBase64?: boolean; namespace: string; plugins?: BrowserPlugin[]; diff --git a/trackers/react-native-tracker/src/plugins/session/index.ts b/trackers/react-native-tracker/src/plugins/session/index.ts index 70b32776a..c276cf8dd 100644 --- a/trackers/react-native-tracker/src/plugins/session/index.ts +++ b/trackers/react-native-tracker/src/plugins/session/index.ts @@ -54,6 +54,7 @@ async function resumeStoredSession(namespace: string): Promise { */ export async function newSessionPlugin({ namespace, + sessionContext = true, foregroundSessionTimeout, backgroundSessionTimeout, }: TrackerConfiguration & SessionConfiguration): Promise { @@ -105,10 +106,12 @@ export async function newSessionPlugin({ } // add session context to the payload - payloadBuilder.addContextEntity({ - schema: CLIENT_SESSION_ENTITY_SCHEMA, - data: { ...sessionState }, - }); + if (sessionContext) { + payloadBuilder.addContextEntity({ + schema: CLIENT_SESSION_ENTITY_SCHEMA, + data: { ...sessionState }, + }); + } }; return { diff --git a/trackers/react-native-tracker/src/tracker.ts b/trackers/react-native-tracker/src/tracker.ts index cc9d9e958..5abdbc501 100644 --- a/trackers/react-native-tracker/src/tracker.ts +++ b/trackers/react-native-tracker/src/tracker.ts @@ -64,7 +64,7 @@ export async function newTracker( const core = trackerCore({ base64: encodeBase64, callback }); - core.setPlatform('mob'); // default platform + core.setPlatform(configuration.devicePlatform ?? 'mob'); core.setTrackerVersion('rn-' + version); core.setTrackerNamespace(namespace); if (appId) { diff --git a/trackers/react-native-tracker/src/types.ts b/trackers/react-native-tracker/src/types.ts index e2d256bc8..6e2d8aaa2 100755 --- a/trackers/react-native-tracker/src/types.ts +++ b/trackers/react-native-tracker/src/types.ts @@ -1,4 +1,4 @@ -import { BrowserPlugin, BrowserPluginConfiguration } from '@snowplow/browser-tracker-core'; +import { BrowserPlugin, BrowserPluginConfiguration, Platform } from '@snowplow/browser-tracker-core'; import { ConditionalContextProvider, ContextPrimitive, @@ -40,6 +40,11 @@ export interface SessionConfiguration { * @defaultValue 1800 */ backgroundSessionTimeout?: number; + /** + * Whether session context is attached to tracked events. + * @defaultValue true + */ + sessionContext?: boolean; } /** @@ -53,7 +58,7 @@ export interface AppLifecycleConfiguration { * Foreground event schema: `iglu:com.snowplowanalytics.snowplow/application_foreground/jsonschema/1-0-0` * Background event schema: `iglu:com.snowplowanalytics.snowplow/application_background/jsonschema/1-0-0` * Context entity schema: `iglu:com.snowplowanalytics.mobile/application_lifecycle/jsonschema/1-0-0` - * + * * @defaultValue true */ lifecycleAutotracking?: boolean; @@ -61,7 +66,7 @@ export interface AppLifecycleConfiguration { * Whether to automatically track app install event on first run. * * Schema: `iglu:com.snowplowanalytics.mobile/application_install/jsonschema/1-0-0` - * + * * @defaultValue false */ installAutotracking?: boolean; @@ -98,6 +103,11 @@ export interface TrackerConfiguration { * @defaultValue [] */ plugins?: BrowserPlugin[]; + /** + * The device platform the tracker runs on. + * @defaultValue 'mob' + */ + devicePlatform?: Platform; } export enum PlatformContextProperty {