@amplitude/analytics-react-native 0.0.1-dev.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -0
- package/amplitude-react-native.podspec +21 -0
- package/android/build.gradle +61 -0
- package/android/gradle.properties +3 -0
- package/android/src/main/AndroidManifest.xml +4 -0
- package/android/src/main/java/com/amplitude/reactnative/AmplitudeReactNativeModule.kt +36 -0
- package/android/src/main/java/com/amplitude/reactnative/AmplitudeReactNativePackage.java +28 -0
- package/android/src/main/java/com/amplitude/reactnative/AndroidContextProvider.kt +415 -0
- package/android/src/main/java/com/amplitude/reactnative/AndroidLogger.kt +56 -0
- package/android/src/main/java/com/amplitude/reactnative/Utils.kt +34 -0
- package/ios/AmplitudeReactNative-Bridging-Header.h +5 -0
- package/ios/AmplitudeReactNative.m +7 -0
- package/ios/AmplitudeReactNative.swift +29 -0
- package/ios/AmplitudeReactNative.xcodeproj/project.pbxproj +293 -0
- package/ios/AppleContextProvider.swift +219 -0
- package/lib/commonjs/attribution/campaign-parser.js +74 -0
- package/lib/commonjs/attribution/campaign-parser.js.map +1 -0
- package/lib/commonjs/attribution/campaign-tracker.js +133 -0
- package/lib/commonjs/attribution/campaign-tracker.js.map +1 -0
- package/lib/commonjs/attribution/constants.js +47 -0
- package/lib/commonjs/attribution/constants.js.map +1 -0
- package/lib/commonjs/config.js +257 -0
- package/lib/commonjs/config.js.map +1 -0
- package/lib/commonjs/constants.js +31 -0
- package/lib/commonjs/constants.js.map +1 -0
- package/lib/commonjs/cookie-migration/index.js +74 -0
- package/lib/commonjs/cookie-migration/index.js.map +1 -0
- package/lib/commonjs/index.js +141 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/plugins/context.js +136 -0
- package/lib/commonjs/plugins/context.js.map +1 -0
- package/lib/commonjs/react-native-client.js +362 -0
- package/lib/commonjs/react-native-client.js.map +1 -0
- package/lib/commonjs/session-manager.js +114 -0
- package/lib/commonjs/session-manager.js.map +1 -0
- package/lib/commonjs/storage/cookie.js +124 -0
- package/lib/commonjs/storage/cookie.js.map +1 -0
- package/lib/commonjs/storage/local-storage.js +79 -0
- package/lib/commonjs/storage/local-storage.js.map +1 -0
- package/lib/commonjs/storage/utm-cookie.js +42 -0
- package/lib/commonjs/storage/utm-cookie.js.map +1 -0
- package/lib/commonjs/transports/fetch.js +34 -0
- package/lib/commonjs/transports/fetch.js.map +1 -0
- package/lib/commonjs/transports/send-beacon.js +43 -0
- package/lib/commonjs/transports/send-beacon.js.map +1 -0
- package/lib/commonjs/transports/xhr.js +54 -0
- package/lib/commonjs/transports/xhr.js.map +1 -0
- package/lib/commonjs/typings/browser-snippet.d.js +6 -0
- package/lib/commonjs/typings/browser-snippet.d.js.map +1 -0
- package/lib/commonjs/typings/ua-parser.d.js +2 -0
- package/lib/commonjs/typings/ua-parser.d.js.map +1 -0
- package/lib/commonjs/utils/cookie-name.js +23 -0
- package/lib/commonjs/utils/cookie-name.js.map +1 -0
- package/lib/commonjs/utils/language.js +18 -0
- package/lib/commonjs/utils/language.js.map +1 -0
- package/lib/commonjs/utils/platform.js +21 -0
- package/lib/commonjs/utils/platform.js.map +1 -0
- package/lib/commonjs/utils/query-params.js +36 -0
- package/lib/commonjs/utils/query-params.js.map +1 -0
- package/lib/commonjs/utils/snippet-helper.js +56 -0
- package/lib/commonjs/utils/snippet-helper.js.map +1 -0
- package/lib/commonjs/version.js +9 -0
- package/lib/commonjs/version.js.map +1 -0
- package/lib/module/attribution/campaign-parser.js +62 -0
- package/lib/module/attribution/campaign-parser.js.map +1 -0
- package/lib/module/attribution/campaign-tracker.js +120 -0
- package/lib/module/attribution/campaign-tracker.js.map +1 -0
- package/lib/module/attribution/constants.js +26 -0
- package/lib/module/attribution/constants.js.map +1 -0
- package/lib/module/config.js +217 -0
- package/lib/module/config.js.map +1 -0
- package/lib/module/constants.js +13 -0
- package/lib/module/constants.js.map +1 -0
- package/lib/module/cookie-migration/index.js +56 -0
- package/lib/module/cookie-migration/index.js.map +1 -0
- package/lib/module/index.js +6 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/plugins/context.js +118 -0
- package/lib/module/plugins/context.js.map +1 -0
- package/lib/module/react-native-client.js +329 -0
- package/lib/module/react-native-client.js.map +1 -0
- package/lib/module/session-manager.js +104 -0
- package/lib/module/session-manager.js.map +1 -0
- package/lib/module/storage/cookie.js +114 -0
- package/lib/module/storage/cookie.js.map +1 -0
- package/lib/module/storage/local-storage.js +67 -0
- package/lib/module/storage/local-storage.js.map +1 -0
- package/lib/module/storage/utm-cookie.js +32 -0
- package/lib/module/storage/utm-cookie.js.map +1 -0
- package/lib/module/transports/fetch.js +24 -0
- package/lib/module/transports/fetch.js.map +1 -0
- package/lib/module/transports/send-beacon.js +33 -0
- package/lib/module/transports/send-beacon.js.map +1 -0
- package/lib/module/transports/xhr.js +44 -0
- package/lib/module/transports/xhr.js.map +1 -0
- package/lib/module/typings/browser-snippet.d.js +2 -0
- package/lib/module/typings/browser-snippet.d.js.map +1 -0
- package/lib/module/typings/ua-parser.d.js +2 -0
- package/lib/module/typings/ua-parser.d.js.map +1 -0
- package/lib/module/utils/cookie-name.js +10 -0
- package/lib/module/utils/cookie-name.js.map +1 -0
- package/lib/module/utils/language.js +9 -0
- package/lib/module/utils/language.js.map +1 -0
- package/lib/module/utils/platform.js +8 -0
- package/lib/module/utils/platform.js.map +1 -0
- package/lib/module/utils/query-params.js +26 -0
- package/lib/module/utils/query-params.js.map +1 -0
- package/lib/module/utils/snippet-helper.js +41 -0
- package/lib/module/utils/snippet-helper.js.map +1 -0
- package/lib/module/version.js +2 -0
- package/lib/module/version.js.map +1 -0
- package/lib/typescript/attribution/campaign-parser.d.ts +10 -0
- package/lib/typescript/attribution/campaign-parser.d.ts.map +1 -0
- package/lib/typescript/attribution/campaign-tracker.d.ts +72 -0
- package/lib/typescript/attribution/campaign-tracker.d.ts.map +1 -0
- package/lib/typescript/attribution/constants.d.ts +17 -0
- package/lib/typescript/attribution/constants.d.ts.map +1 -0
- package/lib/typescript/config.d.ts +90 -0
- package/lib/typescript/config.d.ts.map +1 -0
- package/lib/typescript/constants.d.ts +13 -0
- package/lib/typescript/constants.d.ts.map +1 -0
- package/lib/typescript/cookie-migration/index.d.ts +5 -0
- package/lib/typescript/cookie-migration/index.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +6 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/plugins/context.d.ts +31 -0
- package/lib/typescript/plugins/context.d.ts.map +1 -0
- package/lib/typescript/react-native-client.d.ts +209 -0
- package/lib/typescript/react-native-client.d.ts.map +1 -0
- package/lib/typescript/session-manager.d.ts +28 -0
- package/lib/typescript/session-manager.d.ts.map +1 -0
- package/lib/typescript/storage/cookie.d.ts +12 -0
- package/lib/typescript/storage/cookie.d.ts.map +1 -0
- package/lib/typescript/storage/local-storage.d.ts +10 -0
- package/lib/typescript/storage/local-storage.d.ts.map +1 -0
- package/lib/typescript/storage/utm-cookie.d.ts +6 -0
- package/lib/typescript/storage/utm-cookie.d.ts.map +1 -0
- package/lib/typescript/transports/fetch.d.ts +6 -0
- package/lib/typescript/transports/fetch.d.ts.map +1 -0
- package/lib/typescript/transports/send-beacon.d.ts +6 -0
- package/lib/typescript/transports/send-beacon.d.ts.map +1 -0
- package/lib/typescript/transports/xhr.d.ts +7 -0
- package/lib/typescript/transports/xhr.d.ts.map +1 -0
- package/lib/typescript/utils/cookie-name.d.ts +3 -0
- package/lib/typescript/utils/cookie-name.d.ts.map +1 -0
- package/lib/typescript/utils/language.d.ts +2 -0
- package/lib/typescript/utils/language.d.ts.map +1 -0
- package/lib/typescript/utils/platform.d.ts +3 -0
- package/lib/typescript/utils/platform.d.ts.map +1 -0
- package/lib/typescript/utils/query-params.d.ts +2 -0
- package/lib/typescript/utils/query-params.d.ts.map +1 -0
- package/lib/typescript/utils/snippet-helper.d.ts +16 -0
- package/lib/typescript/utils/snippet-helper.d.ts.map +1 -0
- package/lib/typescript/version.d.ts +2 -0
- package/lib/typescript/version.d.ts.map +1 -0
- package/package.json +93 -0
- package/src/attribution/campaign-parser.ts +78 -0
- package/src/attribution/campaign-tracker.ts +112 -0
- package/src/attribution/constants.ts +32 -0
- package/src/config.ts +210 -0
- package/src/constants.ts +14 -0
- package/src/cookie-migration/index.ts +54 -0
- package/src/index.ts +23 -0
- package/src/plugins/context.ts +106 -0
- package/src/react-native-client.ts +349 -0
- package/src/session-manager.ts +81 -0
- package/src/storage/cookie.ts +95 -0
- package/src/storage/local-storage.ts +67 -0
- package/src/storage/utm-cookie.ts +27 -0
- package/src/transports/fetch.ts +23 -0
- package/src/transports/send-beacon.ts +34 -0
- package/src/transports/xhr.ts +36 -0
- package/src/typings/browser-snippet.d.ts +7 -0
- package/src/typings/ua-parser.d.ts +4 -0
- package/src/utils/cookie-name.ts +9 -0
- package/src/utils/language.ts +7 -0
- package/src/utils/platform.ts +9 -0
- package/src/utils/query-params.ts +21 -0
- package/src/utils/snippet-helper.ts +35 -0
- package/src/version.ts +1 -0
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "Identify", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _analyticsCore.Identify;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "Revenue", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _analyticsCore.Revenue;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
exports.Types = void 0;
|
|
19
|
+
Object.defineProperty(exports, "add", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function () {
|
|
22
|
+
return _reactNativeClient.add;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
Object.defineProperty(exports, "getDeviceId", {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
get: function () {
|
|
28
|
+
return _reactNativeClient.getDeviceId;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
Object.defineProperty(exports, "getSessionId", {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
get: function () {
|
|
34
|
+
return _reactNativeClient.getSessionId;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
Object.defineProperty(exports, "getUserId", {
|
|
38
|
+
enumerable: true,
|
|
39
|
+
get: function () {
|
|
40
|
+
return _reactNativeClient.getUserId;
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
Object.defineProperty(exports, "groupIdentify", {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
get: function () {
|
|
46
|
+
return _reactNativeClient.groupIdentify;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
Object.defineProperty(exports, "identify", {
|
|
50
|
+
enumerable: true,
|
|
51
|
+
get: function () {
|
|
52
|
+
return _reactNativeClient.identify;
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
Object.defineProperty(exports, "init", {
|
|
56
|
+
enumerable: true,
|
|
57
|
+
get: function () {
|
|
58
|
+
return _reactNativeClient.init;
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
Object.defineProperty(exports, "logEvent", {
|
|
62
|
+
enumerable: true,
|
|
63
|
+
get: function () {
|
|
64
|
+
return _reactNativeClient.logEvent;
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
Object.defineProperty(exports, "remove", {
|
|
68
|
+
enumerable: true,
|
|
69
|
+
get: function () {
|
|
70
|
+
return _reactNativeClient.remove;
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
Object.defineProperty(exports, "revenue", {
|
|
74
|
+
enumerable: true,
|
|
75
|
+
get: function () {
|
|
76
|
+
return _reactNativeClient.revenue;
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
Object.defineProperty(exports, "runQueuedFunctions", {
|
|
80
|
+
enumerable: true,
|
|
81
|
+
get: function () {
|
|
82
|
+
return _snippetHelper.runQueuedFunctions;
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
Object.defineProperty(exports, "setDeviceId", {
|
|
86
|
+
enumerable: true,
|
|
87
|
+
get: function () {
|
|
88
|
+
return _reactNativeClient.setDeviceId;
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
Object.defineProperty(exports, "setGroup", {
|
|
92
|
+
enumerable: true,
|
|
93
|
+
get: function () {
|
|
94
|
+
return _reactNativeClient.setGroup;
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
Object.defineProperty(exports, "setOptOut", {
|
|
98
|
+
enumerable: true,
|
|
99
|
+
get: function () {
|
|
100
|
+
return _reactNativeClient.setOptOut;
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
Object.defineProperty(exports, "setSessionId", {
|
|
104
|
+
enumerable: true,
|
|
105
|
+
get: function () {
|
|
106
|
+
return _reactNativeClient.setSessionId;
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
Object.defineProperty(exports, "setTransport", {
|
|
110
|
+
enumerable: true,
|
|
111
|
+
get: function () {
|
|
112
|
+
return _reactNativeClient.setTransport;
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
Object.defineProperty(exports, "setUserId", {
|
|
116
|
+
enumerable: true,
|
|
117
|
+
get: function () {
|
|
118
|
+
return _reactNativeClient.setUserId;
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
Object.defineProperty(exports, "track", {
|
|
122
|
+
enumerable: true,
|
|
123
|
+
get: function () {
|
|
124
|
+
return _reactNativeClient.track;
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
var _reactNativeClient = require("./react-native-client");
|
|
129
|
+
|
|
130
|
+
var _snippetHelper = require("./utils/snippet-helper");
|
|
131
|
+
|
|
132
|
+
var _analyticsCore = require("@amplitude/analytics-core");
|
|
133
|
+
|
|
134
|
+
var Types = _interopRequireWildcard(require("@amplitude/analytics-types"));
|
|
135
|
+
|
|
136
|
+
exports.Types = Types;
|
|
137
|
+
|
|
138
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
139
|
+
|
|
140
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
141
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export {\n add,\n getDeviceId,\n getSessionId,\n getUserId,\n groupIdentify,\n identify,\n init,\n logEvent,\n remove,\n revenue,\n setDeviceId,\n setGroup,\n setOptOut,\n setSessionId,\n setTransport,\n setUserId,\n track,\n} from './react-native-client';\nexport { runQueuedFunctions } from './utils/snippet-helper';\nexport { Revenue, Identify } from '@amplitude/analytics-core';\nimport * as Types from '@amplitude/analytics-types';\nexport { Types };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AAmBA;;AACA;;AACA"}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Context = void 0;
|
|
7
|
+
|
|
8
|
+
var _analyticsTypes = require("@amplitude/analytics-types");
|
|
9
|
+
|
|
10
|
+
var _uaParserJs = _interopRequireDefault(require("@amplitude/ua-parser-js"));
|
|
11
|
+
|
|
12
|
+
var _analyticsCore = require("@amplitude/analytics-core");
|
|
13
|
+
|
|
14
|
+
var _language = require("../utils/language");
|
|
15
|
+
|
|
16
|
+
var _version = require("../version");
|
|
17
|
+
|
|
18
|
+
var _reactNative = require("react-native");
|
|
19
|
+
|
|
20
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
|
+
|
|
22
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
23
|
+
|
|
24
|
+
const BROWSER_PLATFORM = 'Web';
|
|
25
|
+
const IP_ADDRESS = '$remote';
|
|
26
|
+
|
|
27
|
+
class Context {
|
|
28
|
+
// this.config is defined in setup() which will always be called first
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
30
|
+
// @ts-ignore
|
|
31
|
+
constructor() {
|
|
32
|
+
_defineProperty(this, "name", 'context');
|
|
33
|
+
|
|
34
|
+
_defineProperty(this, "type", _analyticsTypes.PluginType.BEFORE);
|
|
35
|
+
|
|
36
|
+
_defineProperty(this, "config", void 0);
|
|
37
|
+
|
|
38
|
+
_defineProperty(this, "eventId", 0);
|
|
39
|
+
|
|
40
|
+
_defineProperty(this, "uaResult", void 0);
|
|
41
|
+
|
|
42
|
+
_defineProperty(this, "nativeModule", _reactNative.NativeModules.AmplitudeReactNative);
|
|
43
|
+
|
|
44
|
+
_defineProperty(this, "library", `amplitude-ts/${_version.VERSION}`);
|
|
45
|
+
|
|
46
|
+
let agent;
|
|
47
|
+
/* istanbul ignore else */
|
|
48
|
+
|
|
49
|
+
if (typeof navigator !== 'undefined') {
|
|
50
|
+
agent = navigator.userAgent;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
this.uaResult = new _uaParserJs.default(agent).getResult();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
setup(config) {
|
|
57
|
+
this.config = config;
|
|
58
|
+
return Promise.resolve(undefined);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async execute(context) {
|
|
62
|
+
var _this$nativeModule;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Manages user session triggered by new events
|
|
66
|
+
*/
|
|
67
|
+
if (!this.isSessionValid()) {
|
|
68
|
+
// Creates new session
|
|
69
|
+
this.config.sessionId = Date.now();
|
|
70
|
+
} // else use previously creates session
|
|
71
|
+
// Updates last event time to extend time-based session
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
this.config.lastEventTime = Date.now();
|
|
75
|
+
const time = new Date().getTime();
|
|
76
|
+
const nativeContext = await ((_this$nativeModule = this.nativeModule) === null || _this$nativeModule === void 0 ? void 0 : _this$nativeModule.getApplicationContext());
|
|
77
|
+
const appVersion = (nativeContext === null || nativeContext === void 0 ? void 0 : nativeContext.version) || this.config.appVersion;
|
|
78
|
+
const platform = (nativeContext === null || nativeContext === void 0 ? void 0 : nativeContext.platform) || BROWSER_PLATFORM;
|
|
79
|
+
const osName = (nativeContext === null || nativeContext === void 0 ? void 0 : nativeContext.os_name) || this.uaResult.browser.name;
|
|
80
|
+
const osVersion = (nativeContext === null || nativeContext === void 0 ? void 0 : nativeContext.os_version) || this.uaResult.browser.version;
|
|
81
|
+
const deviceVendor = (nativeContext === null || nativeContext === void 0 ? void 0 : nativeContext.device_manufacturer) || this.uaResult.device.vendor;
|
|
82
|
+
const deviceModel = (nativeContext === null || nativeContext === void 0 ? void 0 : nativeContext.device_model) || this.uaResult.device.model || this.uaResult.os.name;
|
|
83
|
+
const language = (nativeContext === null || nativeContext === void 0 ? void 0 : nativeContext.language) || (0, _language.getLanguage)();
|
|
84
|
+
const carrier = nativeContext === null || nativeContext === void 0 ? void 0 : nativeContext.carrier;
|
|
85
|
+
const event = {
|
|
86
|
+
user_id: this.config.userId,
|
|
87
|
+
device_id: this.config.deviceId,
|
|
88
|
+
session_id: this.config.sessionId,
|
|
89
|
+
time,
|
|
90
|
+
...(this.config.appVersion && {
|
|
91
|
+
app_version: appVersion
|
|
92
|
+
}),
|
|
93
|
+
...(this.config.trackingOptions.platform && {
|
|
94
|
+
platform: platform
|
|
95
|
+
}),
|
|
96
|
+
...(this.config.trackingOptions.osName && {
|
|
97
|
+
os_name: osName
|
|
98
|
+
}),
|
|
99
|
+
...(this.config.trackingOptions.osVersion && {
|
|
100
|
+
os_version: osVersion
|
|
101
|
+
}),
|
|
102
|
+
...(this.config.trackingOptions.deviceManufacturer && {
|
|
103
|
+
device_manufacturer: deviceVendor
|
|
104
|
+
}),
|
|
105
|
+
...(this.config.trackingOptions.deviceModel && {
|
|
106
|
+
device_model: deviceModel
|
|
107
|
+
}),
|
|
108
|
+
...(this.config.trackingOptions.language && {
|
|
109
|
+
language: language
|
|
110
|
+
}),
|
|
111
|
+
...(this.config.trackingOptions.carrier && {
|
|
112
|
+
carrier: carrier
|
|
113
|
+
}),
|
|
114
|
+
...(this.config.trackingOptions.ipAddress && {
|
|
115
|
+
ip: IP_ADDRESS
|
|
116
|
+
}),
|
|
117
|
+
insert_id: (0, _analyticsCore.UUID)(),
|
|
118
|
+
partner_id: this.config.partnerId,
|
|
119
|
+
plan: this.config.plan,
|
|
120
|
+
...context,
|
|
121
|
+
event_id: this.eventId++,
|
|
122
|
+
library: this.library
|
|
123
|
+
};
|
|
124
|
+
return event;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
isSessionValid() {
|
|
128
|
+
const lastEventTime = this.config.lastEventTime || Date.now();
|
|
129
|
+
const timeSinceLastEvent = Date.now() - lastEventTime;
|
|
130
|
+
return timeSinceLastEvent < this.config.sessionTimeout;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
exports.Context = Context;
|
|
136
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["BROWSER_PLATFORM","IP_ADDRESS","Context","constructor","PluginType","BEFORE","NativeModules","AmplitudeReactNative","VERSION","agent","navigator","userAgent","uaResult","UAParser","getResult","setup","config","Promise","resolve","undefined","execute","context","isSessionValid","sessionId","Date","now","lastEventTime","time","getTime","nativeContext","nativeModule","getApplicationContext","appVersion","version","platform","osName","os_name","browser","name","osVersion","os_version","deviceVendor","device_manufacturer","device","vendor","deviceModel","device_model","model","os","language","getLanguage","carrier","event","user_id","userId","device_id","deviceId","session_id","app_version","trackingOptions","deviceManufacturer","ipAddress","ip","insert_id","UUID","partner_id","partnerId","plan","event_id","eventId","library","timeSinceLastEvent","sessionTimeout"],"sources":["context.ts"],"sourcesContent":["import { BeforePlugin, ReactNativeConfig, Event, PluginType } from '@amplitude/analytics-types';\nimport UAParser from '@amplitude/ua-parser-js';\nimport { UUID } from '@amplitude/analytics-core';\nimport { getLanguage } from '../utils/language';\nimport { VERSION } from '../version';\nimport { NativeModules } from 'react-native';\n\nconst BROWSER_PLATFORM = 'Web';\nconst IP_ADDRESS = '$remote';\n\ntype NativeContext = {\n version: string;\n platform: string;\n language: string;\n os_name: string;\n os_version: string;\n device_brand: string;\n device_manufacturer: string;\n device_model: string;\n carrier: string;\n};\n\nexport interface AmplitudeReactNative {\n getApplicationContext(): Promise<NativeContext>;\n}\n\nexport class Context implements BeforePlugin {\n name = 'context';\n type = PluginType.BEFORE as const;\n\n // this.config is defined in setup() which will always be called first\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n config: ReactNativeConfig;\n eventId = 0;\n uaResult: UAParser.IResult;\n nativeModule: AmplitudeReactNative | undefined = NativeModules.AmplitudeReactNative as\n | AmplitudeReactNative\n | undefined;\n library = `amplitude-ts/${VERSION}`;\n\n constructor() {\n let agent: string | undefined;\n /* istanbul ignore else */\n if (typeof navigator !== 'undefined') {\n agent = navigator.userAgent;\n }\n this.uaResult = new UAParser(agent).getResult();\n }\n\n setup(config: ReactNativeConfig): Promise<undefined> {\n this.config = config;\n return Promise.resolve(undefined);\n }\n\n async execute(context: Event): Promise<Event> {\n /**\n * Manages user session triggered by new events\n */\n if (!this.isSessionValid()) {\n // Creates new session\n this.config.sessionId = Date.now();\n } // else use previously creates session\n // Updates last event time to extend time-based session\n this.config.lastEventTime = Date.now();\n const time = new Date().getTime();\n const nativeContext = await this.nativeModule?.getApplicationContext();\n const appVersion = nativeContext?.version || this.config.appVersion;\n const platform = nativeContext?.platform || BROWSER_PLATFORM;\n const osName = nativeContext?.os_name || this.uaResult.browser.name;\n const osVersion = nativeContext?.os_version || this.uaResult.browser.version;\n const deviceVendor = nativeContext?.device_manufacturer || this.uaResult.device.vendor;\n const deviceModel = nativeContext?.device_model || this.uaResult.device.model || this.uaResult.os.name;\n const language = nativeContext?.language || getLanguage();\n const carrier = nativeContext?.carrier;\n\n const event: Event = {\n user_id: this.config.userId,\n device_id: this.config.deviceId,\n session_id: this.config.sessionId,\n time,\n ...(this.config.appVersion && { app_version: appVersion }),\n ...(this.config.trackingOptions.platform && { platform: platform }),\n ...(this.config.trackingOptions.osName && { os_name: osName }),\n ...(this.config.trackingOptions.osVersion && { os_version: osVersion }),\n ...(this.config.trackingOptions.deviceManufacturer && { device_manufacturer: deviceVendor }),\n ...(this.config.trackingOptions.deviceModel && { device_model: deviceModel }),\n ...(this.config.trackingOptions.language && { language: language }),\n ...(this.config.trackingOptions.carrier && { carrier: carrier }),\n ...(this.config.trackingOptions.ipAddress && { ip: IP_ADDRESS }),\n insert_id: UUID(),\n partner_id: this.config.partnerId,\n plan: this.config.plan,\n ...context,\n event_id: this.eventId++,\n library: this.library,\n };\n return event;\n }\n\n isSessionValid() {\n const lastEventTime = this.config.lastEventTime || Date.now();\n const timeSinceLastEvent = Date.now() - lastEventTime;\n return timeSinceLastEvent < this.config.sessionTimeout;\n }\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.track = exports.setUserId = exports.setTransport = exports.setSessionId = exports.setOptOut = exports.setGroup = exports.setDeviceId = exports.revenue = exports.remove = exports.regenerateDeviceId = exports.logEvent = exports.init = exports.identify = exports.groupIdentify = exports.getUserId = exports.getSessionId = exports.getDeviceId = exports.add = exports.AmplitudeReactNative = void 0;
|
|
7
|
+
|
|
8
|
+
var _analyticsCore = require("@amplitude/analytics-core");
|
|
9
|
+
|
|
10
|
+
var _snippetHelper = require("./utils/snippet-helper");
|
|
11
|
+
|
|
12
|
+
var _context = require("./plugins/context");
|
|
13
|
+
|
|
14
|
+
var _config = require("./config");
|
|
15
|
+
|
|
16
|
+
var _cookieMigration = require("./cookie-migration");
|
|
17
|
+
|
|
18
|
+
var _campaignTracker = require("./attribution/campaign-tracker");
|
|
19
|
+
|
|
20
|
+
class AmplitudeReactNative extends _analyticsCore.AmplitudeCore {
|
|
21
|
+
async init(apiKey, userId, options) {
|
|
22
|
+
var _oldCookies$deviceId, _oldCookies$sessionId, _options$optOut;
|
|
23
|
+
|
|
24
|
+
// Step 1: Read cookies stored by old SDK
|
|
25
|
+
const oldCookies = await (0, _cookieMigration.parseOldCookies)(apiKey, options); // Step 2: Create react native config
|
|
26
|
+
|
|
27
|
+
const reactNativeOptions = await (0, _config.useReactNativeConfig)(apiKey, userId || oldCookies.userId, { ...options,
|
|
28
|
+
deviceId: (_oldCookies$deviceId = oldCookies.deviceId) !== null && _oldCookies$deviceId !== void 0 ? _oldCookies$deviceId : options === null || options === void 0 ? void 0 : options.deviceId,
|
|
29
|
+
sessionId: (_oldCookies$sessionId = oldCookies.sessionId) !== null && _oldCookies$sessionId !== void 0 ? _oldCookies$sessionId : options === null || options === void 0 ? void 0 : options.sessionId,
|
|
30
|
+
optOut: (_options$optOut = options === null || options === void 0 ? void 0 : options.optOut) !== null && _options$optOut !== void 0 ? _options$optOut : oldCookies.optOut,
|
|
31
|
+
lastEventTime: oldCookies.lastEventTime
|
|
32
|
+
});
|
|
33
|
+
await super.init(undefined, undefined, reactNativeOptions); // Step 3: Manage session
|
|
34
|
+
|
|
35
|
+
let isNewSession = false;
|
|
36
|
+
|
|
37
|
+
if (!this.config.sessionId || this.config.lastEventTime && Date.now() - this.config.lastEventTime > this.config.sessionTimeout) {
|
|
38
|
+
// Either
|
|
39
|
+
// 1) No previous session; or
|
|
40
|
+
// 2) Previous session expired
|
|
41
|
+
this.config.sessionId = Date.now();
|
|
42
|
+
isNewSession = true;
|
|
43
|
+
} // Step 4: Install plugins
|
|
44
|
+
// Do not track any events before this
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
await this.add(new _context.Context());
|
|
48
|
+
await this.add(new _analyticsCore.Destination()); // Step 5: Track attributions
|
|
49
|
+
|
|
50
|
+
await this.runAttributionStrategy(options === null || options === void 0 ? void 0 : options.attribution, isNewSession);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async runAttributionStrategy(attributionConfig) {
|
|
54
|
+
let isNewSession = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
55
|
+
const track = this.track.bind(this);
|
|
56
|
+
const onNewCampaign = this.setSessionId.bind(this, Date.now());
|
|
57
|
+
const storage = await (0, _config.createFlexibleStorage)(this.config);
|
|
58
|
+
const campaignTracker = new _campaignTracker.CampaignTracker(this.config.apiKey, { ...attributionConfig,
|
|
59
|
+
storage,
|
|
60
|
+
track,
|
|
61
|
+
onNewCampaign
|
|
62
|
+
});
|
|
63
|
+
await campaignTracker.send(isNewSession);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
getUserId() {
|
|
67
|
+
return this.config.userId;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
setUserId(userId) {
|
|
71
|
+
this.config.userId = userId;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
getDeviceId() {
|
|
75
|
+
return this.config.deviceId;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
setDeviceId(deviceId) {
|
|
79
|
+
this.config.deviceId = deviceId;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
regenerateDeviceId() {
|
|
83
|
+
const deviceId = (0, _config.createDeviceId)();
|
|
84
|
+
this.setDeviceId(deviceId);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
getSessionId() {
|
|
88
|
+
return this.config.sessionId;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
setSessionId(sessionId) {
|
|
92
|
+
this.config.sessionId = sessionId;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
setOptOut(optOut) {
|
|
96
|
+
this.config.optOut = optOut;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
setTransport(transport) {
|
|
100
|
+
this.config.transportProvider = (0, _config.createTransport)(transport);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
identify(identify, eventOptions) {
|
|
104
|
+
if ((0, _snippetHelper.isInstanceProxy)(identify)) {
|
|
105
|
+
const queue = identify._q;
|
|
106
|
+
identify._q = [];
|
|
107
|
+
identify = (0, _snippetHelper.convertProxyObjectToRealObject)(new _analyticsCore.Identify(), queue);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return super.identify(identify, eventOptions);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
groupIdentify(groupType, groupName, identify, eventOptions) {
|
|
114
|
+
if ((0, _snippetHelper.isInstanceProxy)(identify)) {
|
|
115
|
+
const queue = identify._q;
|
|
116
|
+
identify._q = [];
|
|
117
|
+
identify = (0, _snippetHelper.convertProxyObjectToRealObject)(new _analyticsCore.Identify(), queue);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return super.groupIdentify(groupType, groupName, identify, eventOptions);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
revenue(revenue, eventOptions) {
|
|
124
|
+
if ((0, _snippetHelper.isInstanceProxy)(revenue)) {
|
|
125
|
+
const queue = revenue._q;
|
|
126
|
+
revenue._q = [];
|
|
127
|
+
revenue = (0, _snippetHelper.convertProxyObjectToRealObject)(new _analyticsCore.Revenue(), queue);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return super.revenue(revenue, eventOptions);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
exports.AmplitudeReactNative = AmplitudeReactNative;
|
|
136
|
+
const client = new AmplitudeReactNative();
|
|
137
|
+
/**
|
|
138
|
+
* Initializes the Amplitude SDK with your apiKey, userId and optional configurations.
|
|
139
|
+
* This method must be called before any other operations.
|
|
140
|
+
*
|
|
141
|
+
* ```typescript
|
|
142
|
+
* await init(API_KEY, USER_ID, options).promise;
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
|
|
146
|
+
const init = (0, _analyticsCore.returnWrapper)(client.init.bind(client));
|
|
147
|
+
/**
|
|
148
|
+
* Adds a new plugin.
|
|
149
|
+
*
|
|
150
|
+
* ```typescript
|
|
151
|
+
* const plugin = {...};
|
|
152
|
+
* amplitude.add(plugin);
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
|
|
156
|
+
exports.init = init;
|
|
157
|
+
const add = (0, _analyticsCore.returnWrapper)(client.add.bind(client));
|
|
158
|
+
/**
|
|
159
|
+
* Removes a plugin.
|
|
160
|
+
*
|
|
161
|
+
* ```typescript
|
|
162
|
+
* amplitude.remove('myPlugin');
|
|
163
|
+
* ```
|
|
164
|
+
*/
|
|
165
|
+
|
|
166
|
+
exports.add = add;
|
|
167
|
+
const remove = (0, _analyticsCore.returnWrapper)(client.remove.bind(client));
|
|
168
|
+
/**
|
|
169
|
+
* Tracks user-defined event, with specified type, optional event properties and optional overwrites.
|
|
170
|
+
*
|
|
171
|
+
* ```typescript
|
|
172
|
+
* // event tracking with event type only
|
|
173
|
+
* track('Page Load');
|
|
174
|
+
*
|
|
175
|
+
* // event tracking with event type and additional event properties
|
|
176
|
+
* track('Page Load', { loadTime: 1000 });
|
|
177
|
+
*
|
|
178
|
+
* // event tracking with event type, additional event properties, and overwritten event options
|
|
179
|
+
* track('Page Load', { loadTime: 1000 }, { sessionId: -1 });
|
|
180
|
+
*
|
|
181
|
+
* // alternatively, this tracking method is awaitable
|
|
182
|
+
* const result = await track('Page Load').promise;
|
|
183
|
+
* console.log(result.event); // {...}
|
|
184
|
+
* console.log(result.code); // 200
|
|
185
|
+
* console.log(result.message); // "Event tracked successfully"
|
|
186
|
+
* ```
|
|
187
|
+
*/
|
|
188
|
+
|
|
189
|
+
exports.remove = remove;
|
|
190
|
+
const track = (0, _analyticsCore.returnWrapper)(client.track.bind(client));
|
|
191
|
+
/**
|
|
192
|
+
* Alias for track()
|
|
193
|
+
*/
|
|
194
|
+
|
|
195
|
+
exports.track = track;
|
|
196
|
+
const logEvent = (0, _analyticsCore.returnWrapper)(client.logEvent.bind(client));
|
|
197
|
+
/**
|
|
198
|
+
* Sends an identify event containing user property operations
|
|
199
|
+
*
|
|
200
|
+
* ```typescript
|
|
201
|
+
* const id = new Identify();
|
|
202
|
+
* id.set('colors', ['rose', 'gold']);
|
|
203
|
+
* identify(id);
|
|
204
|
+
*
|
|
205
|
+
* // alternatively, this tracking method is awaitable
|
|
206
|
+
* const result = await identify(id).promise;
|
|
207
|
+
* console.log(result.event); // {...}
|
|
208
|
+
* console.log(result.code); // 200
|
|
209
|
+
* console.log(result.message); // "Event tracked successfully"
|
|
210
|
+
* ```
|
|
211
|
+
*/
|
|
212
|
+
|
|
213
|
+
exports.logEvent = logEvent;
|
|
214
|
+
const identify = (0, _analyticsCore.returnWrapper)(client.identify.bind(client));
|
|
215
|
+
/**
|
|
216
|
+
* Sends a group identify event containing group property operations.
|
|
217
|
+
*
|
|
218
|
+
* ```typescript
|
|
219
|
+
* const id = new Identify();
|
|
220
|
+
* id.set('skills', ['js', 'ts']);
|
|
221
|
+
* const groupType = 'org';
|
|
222
|
+
* const groupName = 'engineering';
|
|
223
|
+
* groupIdentify(groupType, groupName, id);
|
|
224
|
+
*
|
|
225
|
+
* // alternatively, this tracking method is awaitable
|
|
226
|
+
* const result = await groupIdentify(groupType, groupName, id).promise;
|
|
227
|
+
* console.log(result.event); // {...}
|
|
228
|
+
* console.log(result.code); // 200
|
|
229
|
+
* console.log(result.message); // "Event tracked successfully"
|
|
230
|
+
* ```
|
|
231
|
+
*/
|
|
232
|
+
|
|
233
|
+
exports.identify = identify;
|
|
234
|
+
const groupIdentify = (0, _analyticsCore.returnWrapper)(client.groupIdentify.bind(client));
|
|
235
|
+
exports.groupIdentify = groupIdentify;
|
|
236
|
+
const setGroup = (0, _analyticsCore.returnWrapper)(client.setGroup.bind(client));
|
|
237
|
+
/**
|
|
238
|
+
* Sends a revenue event containing revenue property operations.
|
|
239
|
+
*
|
|
240
|
+
* ```typescript
|
|
241
|
+
* const rev = new Revenue();
|
|
242
|
+
* rev.setRevenue(100);
|
|
243
|
+
* revenue(rev);
|
|
244
|
+
*
|
|
245
|
+
* // alternatively, this tracking method is awaitable
|
|
246
|
+
* const result = await revenue(rev).promise;
|
|
247
|
+
* console.log(result.event); // {...}
|
|
248
|
+
* console.log(result.code); // 200
|
|
249
|
+
* console.log(result.message); // "Event tracked successfully"
|
|
250
|
+
* ```
|
|
251
|
+
*/
|
|
252
|
+
|
|
253
|
+
exports.setGroup = setGroup;
|
|
254
|
+
const revenue = (0, _analyticsCore.returnWrapper)(client.revenue.bind(client));
|
|
255
|
+
/**
|
|
256
|
+
* Returns current user ID.
|
|
257
|
+
*
|
|
258
|
+
* ```typescript
|
|
259
|
+
* const userId = getUserId();
|
|
260
|
+
* ```
|
|
261
|
+
*/
|
|
262
|
+
|
|
263
|
+
exports.revenue = revenue;
|
|
264
|
+
const getUserId = client.getUserId.bind(client);
|
|
265
|
+
/**
|
|
266
|
+
* Sets a new user ID.
|
|
267
|
+
*
|
|
268
|
+
* ```typescript
|
|
269
|
+
* setUserId('userId');
|
|
270
|
+
* ```
|
|
271
|
+
*/
|
|
272
|
+
|
|
273
|
+
exports.getUserId = getUserId;
|
|
274
|
+
const setUserId = client.setUserId.bind(client);
|
|
275
|
+
/**
|
|
276
|
+
* Returns current device ID.
|
|
277
|
+
*
|
|
278
|
+
* ```typescript
|
|
279
|
+
* const deviceId = getDeviceId();
|
|
280
|
+
* ```
|
|
281
|
+
*/
|
|
282
|
+
|
|
283
|
+
exports.setUserId = setUserId;
|
|
284
|
+
const getDeviceId = client.getDeviceId.bind(client);
|
|
285
|
+
/**
|
|
286
|
+
* Sets a new device ID.
|
|
287
|
+
* When setting a custom device ID, make sure the value is sufficiently unique.
|
|
288
|
+
* A uuid is recommended.
|
|
289
|
+
*
|
|
290
|
+
* ```typescript
|
|
291
|
+
* setDeviceId('deviceId');
|
|
292
|
+
* ```
|
|
293
|
+
*/
|
|
294
|
+
|
|
295
|
+
exports.getDeviceId = getDeviceId;
|
|
296
|
+
const setDeviceId = client.setDeviceId.bind(client);
|
|
297
|
+
/**
|
|
298
|
+
* Regenerates a new random deviceId for current user. Note: this is not recommended unless you know what you
|
|
299
|
+
* are doing. This can be used in conjunction with `setUserId(undefined)` to anonymize users after they log out.
|
|
300
|
+
* With an `unefined` userId and a completely new deviceId, the current user would appear as a brand new user in dashboard.
|
|
301
|
+
*
|
|
302
|
+
* ```typescript
|
|
303
|
+
* regenerateDeviceId();
|
|
304
|
+
* ```
|
|
305
|
+
*/
|
|
306
|
+
|
|
307
|
+
exports.setDeviceId = setDeviceId;
|
|
308
|
+
const regenerateDeviceId = client.regenerateDeviceId.bind(client);
|
|
309
|
+
/**
|
|
310
|
+
* Returns current session ID.
|
|
311
|
+
*
|
|
312
|
+
* ```typescript
|
|
313
|
+
* const sessionId = getSessionId();
|
|
314
|
+
* ```
|
|
315
|
+
*/
|
|
316
|
+
|
|
317
|
+
exports.regenerateDeviceId = regenerateDeviceId;
|
|
318
|
+
const getSessionId = client.getSessionId.bind(client);
|
|
319
|
+
/**
|
|
320
|
+
* Sets a new session ID.
|
|
321
|
+
* When settign a custom session ID, make sure the value is in milliseconds since epoch (Unix Timestamp).
|
|
322
|
+
*
|
|
323
|
+
* ```typescript
|
|
324
|
+
* setSessionId(Date.now());
|
|
325
|
+
* ```
|
|
326
|
+
*/
|
|
327
|
+
|
|
328
|
+
exports.getSessionId = getSessionId;
|
|
329
|
+
const setSessionId = client.setSessionId.bind(client);
|
|
330
|
+
/**
|
|
331
|
+
* Sets a new optOut config value. This toggles event tracking on/off.
|
|
332
|
+
*
|
|
333
|
+
*```typescript
|
|
334
|
+
* // Stops tracking
|
|
335
|
+
* setOptOut(true);
|
|
336
|
+
*
|
|
337
|
+
* // Starts/resumes tracking
|
|
338
|
+
* setOptOut(false);
|
|
339
|
+
* ```
|
|
340
|
+
*/
|
|
341
|
+
|
|
342
|
+
exports.setSessionId = setSessionId;
|
|
343
|
+
const setOptOut = client.setOptOut.bind(client);
|
|
344
|
+
/**
|
|
345
|
+
* Sets the network transport type for events.
|
|
346
|
+
*
|
|
347
|
+
* ```typescript
|
|
348
|
+
* // Use Fetch API
|
|
349
|
+
* setTransport('fetch');
|
|
350
|
+
*
|
|
351
|
+
* // Use XMLHttpRequest API
|
|
352
|
+
* setTransport('xhr');
|
|
353
|
+
*
|
|
354
|
+
* // Use navigator.sendBeacon API
|
|
355
|
+
* setTransport('beacon');
|
|
356
|
+
* ```
|
|
357
|
+
*/
|
|
358
|
+
|
|
359
|
+
exports.setOptOut = setOptOut;
|
|
360
|
+
const setTransport = client.setTransport.bind(client);
|
|
361
|
+
exports.setTransport = setTransport;
|
|
362
|
+
//# sourceMappingURL=react-native-client.js.map
|