Skip to content

Commit

Permalink
Add sessionContext and devicePlatform options to React Native tracker…
Browse files Browse the repository at this point in the history
… configuration (#1401)
  • Loading branch information
matus-tomlein authored Jan 6, 2025
1 parent cd7267f commit cba41e8
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ export interface SessionConfiguration
| --- | --- | --- |
| [backgroundSessionTimeout?](./react-native-tracker.sessionconfiguration.backgroundsessiontimeout.md) | number | <i>(Optional)</i> 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 | <i>(Optional)</i> 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 | <i>(Optional)</i> Whether session context is attached to tracked events. |

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@snowplow/react-native-tracker](./react-native-tracker.md) &gt; [SessionConfiguration](./react-native-tracker.sessionconfiguration.md) &gt; [sessionContext](./react-native-tracker.sessionconfiguration.sessioncontext.md)

## SessionConfiguration.sessionContext property

Whether session context is attached to tracked events.

<b>Signature:</b>

```typescript
sessionContext?: boolean;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@snowplow/react-native-tracker](./react-native-tracker.md) &gt; [TrackerConfiguration](./react-native-tracker.trackerconfiguration.md) &gt; [devicePlatform](./react-native-tracker.trackerconfiguration.deviceplatform.md)

## TrackerConfiguration.devicePlatform property

The device platform the tracker runs on.

<b>Signature:</b>

```typescript
devicePlatform?: Platform;
```
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export interface TrackerConfiguration
| Property | Type | Description |
| --- | --- | --- |
| [appId?](./react-native-tracker.trackerconfiguration.appid.md) | string | <i>(Optional)</i> The application ID |
| [devicePlatform?](./react-native-tracker.trackerconfiguration.deviceplatform.md) | Platform | <i>(Optional)</i> The device platform the tracker runs on. |
| [encodeBase64?](./react-native-tracker.trackerconfiguration.encodebase64.md) | boolean | <i>(Optional)</i> 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\[\] | <i>(Optional)</i> Inject plugins which will be evaluated for each event |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -464,6 +465,7 @@ export type SelfDescribing<T = Record<string, unknown>> = SelfDescribingJson<T>;
export interface SessionConfiguration {
backgroundSessionTimeout?: number;
foregroundSessionTimeout?: number;
sessionContext?: boolean;
}

// @public
Expand Down Expand Up @@ -511,6 +513,7 @@ export type TimingProps = {
// @public
export interface TrackerConfiguration {
appId?: string;
devicePlatform?: Platform;
encodeBase64?: boolean;
namespace: string;
plugins?: BrowserPlugin[];
Expand Down
11 changes: 7 additions & 4 deletions trackers/react-native-tracker/src/plugins/session/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ async function resumeStoredSession(namespace: string): Promise<SessionState> {
*/
export async function newSessionPlugin({
namespace,
sessionContext = true,
foregroundSessionTimeout,
backgroundSessionTimeout,
}: TrackerConfiguration & SessionConfiguration): Promise<SessionPlugin> {
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion trackers/react-native-tracker/src/tracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
16 changes: 13 additions & 3 deletions trackers/react-native-tracker/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BrowserPlugin, BrowserPluginConfiguration } from '@snowplow/browser-tracker-core';
import { BrowserPlugin, BrowserPluginConfiguration, Platform } from '@snowplow/browser-tracker-core';
import {
ConditionalContextProvider,
ContextPrimitive,
Expand Down Expand Up @@ -40,6 +40,11 @@ export interface SessionConfiguration {
* @defaultValue 1800
*/
backgroundSessionTimeout?: number;
/**
* Whether session context is attached to tracked events.
* @defaultValue true
*/
sessionContext?: boolean;
}

/**
Expand All @@ -53,15 +58,15 @@ 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;
/**
* 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;
Expand Down Expand Up @@ -98,6 +103,11 @@ export interface TrackerConfiguration {
* @defaultValue []
*/
plugins?: BrowserPlugin[];
/**
* The device platform the tracker runs on.
* @defaultValue 'mob'
*/
devicePlatform?: Platform;
}

export enum PlatformContextProperty {
Expand Down

0 comments on commit cba41e8

Please sign in to comment.