forked from snowplow/snowplow-javascript-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
44 lines (40 loc) · 1.36 KB
/
Copy pathindex.ts
File metadata and controls
44 lines (40 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { CorePluginConfiguration, SelfDescribingJson } from '@snowplow/tracker-core';
import { AppLifecycleConfiguration } from '../../types';
import { APPLICATION_CONTEXT_SCHEMA, MOBILE_APPLICATION_CONTEXT_SCHEMA } from '../../constants';
/**
* Tracks the application context entity with information about the app version.
* If appBuild is provided, a mobile application context is tracked, otherwise the Web equivalent is tracked.
*
* Entity schema if `appBuild` property is set: `iglu:com.snowplowanalytics.mobile/application/jsonschema/1-0-0`
* Entity schema if `appBuild` property is not set: `iglu:com.snowplowanalytics.snowplow/application/jsonschema/1-0-0`
*/
export function newAppContextPlugin({ appVersion, appBuild }: AppLifecycleConfiguration): CorePluginConfiguration {
const contexts = () => {
let entities: SelfDescribingJson[] = [];
if (appVersion) {
// Add application context to all events
if (appBuild) {
entities.push({
schema: MOBILE_APPLICATION_CONTEXT_SCHEMA,
data: {
version: appVersion,
build: appBuild,
},
});
} else {
entities.push({
schema: APPLICATION_CONTEXT_SCHEMA,
data: {
version: appVersion,
},
});
}
}
return entities;
};
return {
plugin: {
contexts,
},
};
}