Skip to content

Commit 785c929

Browse files
committed
Add sessionContext and devicePlatform options to React Native tracker configuration (#1401)
1 parent 81be079 commit 785c929

File tree

8 files changed

+52
-8
lines changed

8 files changed

+52
-8
lines changed

api-docs/docs/react-native-tracker/markdown/react-native-tracker.sessionconfiguration.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ export interface SessionConfiguration
1818
| --- | --- | --- |
1919
| [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 |
2020
| [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 |
21+
| [sessionContext?](./react-native-tracker.sessionconfiguration.sessioncontext.md) | boolean | <i>(Optional)</i> Whether session context is attached to tracked events. |
2122

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[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)
4+
5+
## SessionConfiguration.sessionContext property
6+
7+
Whether session context is attached to tracked events.
8+
9+
<b>Signature:</b>
10+
11+
```typescript
12+
sessionContext?: boolean;
13+
```
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[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)
4+
5+
## TrackerConfiguration.devicePlatform property
6+
7+
The device platform the tracker runs on.
8+
9+
<b>Signature:</b>
10+
11+
```typescript
12+
devicePlatform?: Platform;
13+
```

api-docs/docs/react-native-tracker/markdown/react-native-tracker.trackerconfiguration.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export interface TrackerConfiguration
1717
| Property | Type | Description |
1818
| --- | --- | --- |
1919
| [appId?](./react-native-tracker.trackerconfiguration.appid.md) | string | <i>(Optional)</i> The application ID |
20+
| [devicePlatform?](./react-native-tracker.trackerconfiguration.deviceplatform.md) | Platform | <i>(Optional)</i> The device platform the tracker runs on. |
2021
| [encodeBase64?](./react-native-tracker.trackerconfiguration.encodebase64.md) | boolean | <i>(Optional)</i> Whether unstructured events and custom contexts should be base64 encoded. |
2122
| [namespace](./react-native-tracker.trackerconfiguration.namespace.md) | string | The namespace of the tracker |
2223
| [plugins?](./react-native-tracker.trackerconfiguration.plugins.md) | BrowserPlugin\[\] | <i>(Optional)</i> Inject plugins which will be evaluated for each event |

api-docs/docs/react-native-tracker/react-native-tracker.api.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import { BrowserPlugin } from '@snowplow/browser-tracker-core';
88
import { BrowserPluginConfiguration } from '@snowplow/browser-tracker-core';
9+
import { Platform } from '@snowplow/browser-tracker-core';
910
import { ScreenTrackingConfiguration } from '@snowplow/browser-plugin-screen-tracking';
1011

1112
// @public
@@ -464,6 +465,7 @@ export type SelfDescribing<T = Record<string, unknown>> = SelfDescribingJson<T>;
464465
export interface SessionConfiguration {
465466
backgroundSessionTimeout?: number;
466467
foregroundSessionTimeout?: number;
468+
sessionContext?: boolean;
467469
}
468470

469471
// @public
@@ -511,6 +513,7 @@ export type TimingProps = {
511513
// @public
512514
export interface TrackerConfiguration {
513515
appId?: string;
516+
devicePlatform?: Platform;
514517
encodeBase64?: boolean;
515518
namespace: string;
516519
plugins?: BrowserPlugin[];

trackers/react-native-tracker/src/plugins/session/index.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ async function resumeStoredSession(namespace: string): Promise<SessionState> {
5454
*/
5555
export async function newSessionPlugin({
5656
namespace,
57+
sessionContext = true,
5758
foregroundSessionTimeout,
5859
backgroundSessionTimeout,
5960
}: TrackerConfiguration & SessionConfiguration): Promise<SessionPlugin> {
@@ -105,10 +106,12 @@ export async function newSessionPlugin({
105106
}
106107

107108
// add session context to the payload
108-
payloadBuilder.addContextEntity({
109-
schema: CLIENT_SESSION_ENTITY_SCHEMA,
110-
data: { ...sessionState },
111-
});
109+
if (sessionContext) {
110+
payloadBuilder.addContextEntity({
111+
schema: CLIENT_SESSION_ENTITY_SCHEMA,
112+
data: { ...sessionState },
113+
});
114+
}
112115
};
113116

114117
return {

trackers/react-native-tracker/src/tracker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export async function newTracker(
6464

6565
const core = trackerCore({ base64: encodeBase64, callback });
6666

67-
core.setPlatform('mob'); // default platform
67+
core.setPlatform(configuration.devicePlatform ?? 'mob');
6868
core.setTrackerVersion('rn-' + version);
6969
core.setTrackerNamespace(namespace);
7070
if (appId) {

trackers/react-native-tracker/src/types.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BrowserPlugin, BrowserPluginConfiguration } from '@snowplow/browser-tracker-core';
1+
import { BrowserPlugin, BrowserPluginConfiguration, Platform } from '@snowplow/browser-tracker-core';
22
import {
33
ConditionalContextProvider,
44
ContextPrimitive,
@@ -40,6 +40,11 @@ export interface SessionConfiguration {
4040
* @defaultValue 1800
4141
*/
4242
backgroundSessionTimeout?: number;
43+
/**
44+
* Whether session context is attached to tracked events.
45+
* @defaultValue true
46+
*/
47+
sessionContext?: boolean;
4348
}
4449

4550
/**
@@ -53,15 +58,15 @@ export interface AppLifecycleConfiguration {
5358
* Foreground event schema: `iglu:com.snowplowanalytics.snowplow/application_foreground/jsonschema/1-0-0`
5459
* Background event schema: `iglu:com.snowplowanalytics.snowplow/application_background/jsonschema/1-0-0`
5560
* Context entity schema: `iglu:com.snowplowanalytics.mobile/application_lifecycle/jsonschema/1-0-0`
56-
*
61+
*
5762
* @defaultValue true
5863
*/
5964
lifecycleAutotracking?: boolean;
6065
/**
6166
* Whether to automatically track app install event on first run.
6267
*
6368
* Schema: `iglu:com.snowplowanalytics.mobile/application_install/jsonschema/1-0-0`
64-
*
69+
*
6570
* @defaultValue false
6671
*/
6772
installAutotracking?: boolean;
@@ -98,6 +103,11 @@ export interface TrackerConfiguration {
98103
* @defaultValue []
99104
*/
100105
plugins?: BrowserPlugin[];
106+
/**
107+
* The device platform the tracker runs on.
108+
* @defaultValue 'mob'
109+
*/
110+
devicePlatform?: Platform;
101111
}
102112

103113
export enum PlatformContextProperty {

0 commit comments

Comments
 (0)