@capgo/capacitor-rudderstack 8.1.2
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/CapgoCapacitorRudderStack.podspec +19 -0
- package/LICENSE +373 -0
- package/Package.swift +30 -0
- package/README.md +390 -0
- package/android/build.gradle +182 -0
- package/android/src/main/AndroidManifest.xml +4 -0
- package/android/src/main/java/app/capgo/rudderstack/RudderStackBridge.java +256 -0
- package/android/src/main/java/app/capgo/rudderstack/RudderStackPlugin.java +205 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/dist/docs.json +525 -0
- package/dist/esm/definitions.d.ts +154 -0
- package/dist/esm/definitions.js +2 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +9 -0
- package/dist/esm/index.js +211 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/web.d.ts +63 -0
- package/dist/esm/web.js +69 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +283 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +286 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Sources/RudderStackPlugin/RudderStackBridge.swift +244 -0
- package/ios/Sources/RudderStackPlugin/RudderStackPlugin.swift +210 -0
- package/ios/Tests/RudderStackPluginTests/RudderStackPluginTests.swift +8 -0
- package/package.json +94 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { RudderLogLevelValue, RudderStackPlugin } from './definitions';
|
|
2
|
+
type RudderClientWithStatics = RudderStackPlugin & {
|
|
3
|
+
LogLevel: typeof RudderLogLevel;
|
|
4
|
+
};
|
|
5
|
+
export declare const RudderLogLevel: Record<string, RudderLogLevelValue>;
|
|
6
|
+
declare const RudderClient: RudderClientWithStatics;
|
|
7
|
+
declare const RudderStack: RudderClientWithStatics;
|
|
8
|
+
export * from './definitions';
|
|
9
|
+
export { RudderClient, RudderStack };
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { registerPlugin } from '@capacitor/core';
|
|
13
|
+
const nativePlugin = registerPlugin('RudderStack', {
|
|
14
|
+
web: () => import('./web').then((m) => new m.RudderStackWeb()),
|
|
15
|
+
});
|
|
16
|
+
export const RudderLogLevel = Object.freeze({
|
|
17
|
+
VERBOSE: 5,
|
|
18
|
+
DEBUG: 4,
|
|
19
|
+
INFO: 3,
|
|
20
|
+
WARN: 2,
|
|
21
|
+
ERROR: 1,
|
|
22
|
+
NONE: 0,
|
|
23
|
+
});
|
|
24
|
+
function isValidString(value) {
|
|
25
|
+
return typeof value === 'string' && value.trim().length > 0;
|
|
26
|
+
}
|
|
27
|
+
function isValidBoolean(value) {
|
|
28
|
+
return typeof value === 'boolean';
|
|
29
|
+
}
|
|
30
|
+
function isRecord(value) {
|
|
31
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
32
|
+
}
|
|
33
|
+
function isRudderOptions(value) {
|
|
34
|
+
return isRecord(value) && ('externalIds' in value || 'integrations' in value);
|
|
35
|
+
}
|
|
36
|
+
function sanitizeConfig(config) {
|
|
37
|
+
if (!config) {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
if (Array.isArray(config.factories) && config.factories.length > 0) {
|
|
41
|
+
console.warn('config.factories is ignored by @capgo/capacitor-rudderstack. Native Rudder destination factories are not implemented yet.');
|
|
42
|
+
}
|
|
43
|
+
const { factories } = config, safeConfig = __rest(config, ["factories"]);
|
|
44
|
+
void factories;
|
|
45
|
+
return safeConfig;
|
|
46
|
+
}
|
|
47
|
+
async function callIfValid(value, errorMessage, action) {
|
|
48
|
+
if (value === undefined) {
|
|
49
|
+
console.log(errorMessage);
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
await action();
|
|
53
|
+
}
|
|
54
|
+
const RudderClient = {
|
|
55
|
+
async initialize(writeKey, config, options) {
|
|
56
|
+
if (!isValidString(writeKey)) {
|
|
57
|
+
const message = 'WriteKey is Invalid, Aborting SDK Initialization';
|
|
58
|
+
console.log(message);
|
|
59
|
+
throw new Error(message);
|
|
60
|
+
}
|
|
61
|
+
let resolvedConfig = config;
|
|
62
|
+
let resolvedOptions = options;
|
|
63
|
+
if (isRudderOptions(config)) {
|
|
64
|
+
resolvedOptions = config;
|
|
65
|
+
resolvedConfig = undefined;
|
|
66
|
+
}
|
|
67
|
+
if (resolvedOptions !== undefined && !isRudderOptions(resolvedOptions)) {
|
|
68
|
+
console.log('Options is invalid, setting it to null');
|
|
69
|
+
resolvedOptions = undefined;
|
|
70
|
+
}
|
|
71
|
+
await nativePlugin.initialize({
|
|
72
|
+
writeKey,
|
|
73
|
+
config: sanitizeConfig(resolvedConfig),
|
|
74
|
+
options: resolvedOptions,
|
|
75
|
+
});
|
|
76
|
+
},
|
|
77
|
+
async identify(userId, traits, options) {
|
|
78
|
+
if (!isValidString(userId)) {
|
|
79
|
+
console.log('userId is Invalid, dropping identify call');
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
let resolvedTraits = traits;
|
|
83
|
+
let resolvedOptions = options;
|
|
84
|
+
if (isRudderOptions(traits)) {
|
|
85
|
+
resolvedOptions = traits;
|
|
86
|
+
resolvedTraits = undefined;
|
|
87
|
+
}
|
|
88
|
+
if (resolvedOptions !== undefined && !isRudderOptions(resolvedOptions)) {
|
|
89
|
+
console.log('Options is invalid, setting it to null');
|
|
90
|
+
resolvedOptions = undefined;
|
|
91
|
+
}
|
|
92
|
+
await nativePlugin.identify({
|
|
93
|
+
userId,
|
|
94
|
+
traits: resolvedTraits,
|
|
95
|
+
options: resolvedOptions,
|
|
96
|
+
});
|
|
97
|
+
},
|
|
98
|
+
async group(groupId, groupTraits, options) {
|
|
99
|
+
if (!isValidString(groupId)) {
|
|
100
|
+
console.log('groupId is Invalid, dropping group call');
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
let resolvedTraits = groupTraits;
|
|
104
|
+
let resolvedOptions = options;
|
|
105
|
+
if (isRudderOptions(groupTraits)) {
|
|
106
|
+
resolvedOptions = groupTraits;
|
|
107
|
+
resolvedTraits = undefined;
|
|
108
|
+
}
|
|
109
|
+
if (resolvedOptions !== undefined && !isRudderOptions(resolvedOptions)) {
|
|
110
|
+
console.log('Options is invalid, setting it to null');
|
|
111
|
+
resolvedOptions = undefined;
|
|
112
|
+
}
|
|
113
|
+
await nativePlugin.group({
|
|
114
|
+
groupId,
|
|
115
|
+
groupTraits: resolvedTraits,
|
|
116
|
+
options: resolvedOptions,
|
|
117
|
+
});
|
|
118
|
+
},
|
|
119
|
+
async track(eventName, properties, options) {
|
|
120
|
+
if (!isValidString(eventName)) {
|
|
121
|
+
console.log('eventName is Invalid, dropping track call');
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
let resolvedProperties = properties;
|
|
125
|
+
let resolvedOptions = options;
|
|
126
|
+
if (isRudderOptions(properties)) {
|
|
127
|
+
resolvedOptions = properties;
|
|
128
|
+
resolvedProperties = undefined;
|
|
129
|
+
}
|
|
130
|
+
if (resolvedOptions !== undefined && !isRudderOptions(resolvedOptions)) {
|
|
131
|
+
console.log('Options is invalid, setting it to null');
|
|
132
|
+
resolvedOptions = undefined;
|
|
133
|
+
}
|
|
134
|
+
await nativePlugin.track({
|
|
135
|
+
eventName,
|
|
136
|
+
properties: resolvedProperties,
|
|
137
|
+
options: resolvedOptions,
|
|
138
|
+
});
|
|
139
|
+
},
|
|
140
|
+
async screen(screenName, properties, options) {
|
|
141
|
+
if (!isValidString(screenName)) {
|
|
142
|
+
console.log('screenName is Invalid, dropping screen call');
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
let resolvedProperties = properties;
|
|
146
|
+
let resolvedOptions = options;
|
|
147
|
+
if (isRudderOptions(properties)) {
|
|
148
|
+
resolvedOptions = properties;
|
|
149
|
+
resolvedProperties = undefined;
|
|
150
|
+
}
|
|
151
|
+
if (resolvedOptions !== undefined && !isRudderOptions(resolvedOptions)) {
|
|
152
|
+
console.log('Options is invalid, setting it to null');
|
|
153
|
+
resolvedOptions = undefined;
|
|
154
|
+
}
|
|
155
|
+
await nativePlugin.screen({
|
|
156
|
+
screenName,
|
|
157
|
+
properties: resolvedProperties,
|
|
158
|
+
options: resolvedOptions,
|
|
159
|
+
});
|
|
160
|
+
},
|
|
161
|
+
async alias(newId, options) {
|
|
162
|
+
if (!isValidString(newId)) {
|
|
163
|
+
console.log('newId is Invalid, dropping alias call');
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
const resolvedOptions = options !== undefined && !isRudderOptions(options) ? undefined : options;
|
|
167
|
+
if (options !== undefined && resolvedOptions === undefined) {
|
|
168
|
+
console.log('Options is invalid, setting it to null');
|
|
169
|
+
}
|
|
170
|
+
await nativePlugin.alias({
|
|
171
|
+
newId,
|
|
172
|
+
options: resolvedOptions,
|
|
173
|
+
});
|
|
174
|
+
},
|
|
175
|
+
async reset() {
|
|
176
|
+
await nativePlugin.reset();
|
|
177
|
+
},
|
|
178
|
+
async flush() {
|
|
179
|
+
await nativePlugin.flush();
|
|
180
|
+
},
|
|
181
|
+
async putDeviceToken(deviceToken) {
|
|
182
|
+
await callIfValid(isValidString(deviceToken) ? deviceToken : undefined, 'deviceToken is Invalid, dropping putDeviceToken call', () => nativePlugin.putDeviceToken({ deviceToken }));
|
|
183
|
+
},
|
|
184
|
+
async setAdvertisingId(advertisingId) {
|
|
185
|
+
await this.putAdvertisingId(advertisingId);
|
|
186
|
+
},
|
|
187
|
+
async putAdvertisingId(advertisingId) {
|
|
188
|
+
await callIfValid(isValidString(advertisingId) ? advertisingId : undefined, 'advertisingId is Invalid, dropping putAdvertisingId call', () => nativePlugin.putAdvertisingId({ advertisingId }));
|
|
189
|
+
},
|
|
190
|
+
async setAnonymousId(anonymousId) {
|
|
191
|
+
await this.putAnonymousId(anonymousId);
|
|
192
|
+
},
|
|
193
|
+
async putAnonymousId(anonymousId) {
|
|
194
|
+
await callIfValid(isValidString(anonymousId) ? anonymousId : undefined, 'anonymousId is Invalid, dropping putAnonymousId call', () => nativePlugin.putAnonymousId({ anonymousId }));
|
|
195
|
+
},
|
|
196
|
+
async optOut(optOut) {
|
|
197
|
+
if (!isValidBoolean(optOut)) {
|
|
198
|
+
console.log('optOut is Invalid, dropping optOut call');
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
await nativePlugin.optOut({ optOut });
|
|
202
|
+
},
|
|
203
|
+
async getPluginVersion() {
|
|
204
|
+
return nativePlugin.getPluginVersion();
|
|
205
|
+
},
|
|
206
|
+
LogLevel: RudderLogLevel,
|
|
207
|
+
};
|
|
208
|
+
const RudderStack = RudderClient;
|
|
209
|
+
export * from './definitions';
|
|
210
|
+
export { RudderClient, RudderStack };
|
|
211
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAqFjD,MAAM,YAAY,GAAG,cAAc,CAA0B,aAAa,EAAE;IAC1E,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,cAAc,EAAE,CAAC;CAC/D,CAAC,CAAC;AAEH,MAAM,CA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AAE,CAAC,CACvD,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,WAAW;QAC9B,MAAM,IAAI,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC;IACzC,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,WAAW;QAC9B,MAAM,WAAW,CACf,aAAa,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,EACpD,sDAAsD,EACtD,GAAG,EAAE,CAAC,YAAY,CAAC,cAAc,CAAC,EAAE,WAAW,EAAE,CAAC,CACnD,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,MAAM;QACjB,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,CAAC;YAC5B,OAAO,CAAC,GAAG,CAAC,yCAAyC,CAAC,CAAC;YACvD,OAAO;QACT,CAAC;QAED,MAAM,YAAY,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;IACxC,CAAC;IAED,KAAK,CAAC,gBAAgB;QACpB,OAAO,YAAY,CAAC,gBAAgB,EAAE,CAAC;IACzC,CAAC;IAED,QAAQ,EAAE,cAAc;CACzB,CAAC;AAEF,MAAM,WAAW,GAAG,YAAY,CAAC;AAEjC,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,CAAC","sourcesContent":["import { registerPlugin } from '@capacitor/core';\n\nimport type {\n PluginVersionResult,\n RudderConfiguration,\n RudderLogLevelValue,\n RudderOptions,\n RudderProperties,\n RudderStackPlugin,\n RudderTraits,\n} from './definitions';\n\ninterface InitializeCallOptions {\n writeKey: string;\n config?: RudderConfiguration;\n options?: RudderOptions;\n}\n\ninterface IdentifyCallOptions {\n userId: string;\n traits?: RudderTraits;\n options?: RudderOptions;\n}\n\ninterface GroupCallOptions {\n groupId: string;\n groupTraits?: RudderTraits;\n options?: RudderOptions;\n}\n\ninterface TrackCallOptions {\n eventName: string;\n properties?: RudderProperties;\n options?: RudderOptions;\n}\n\ninterface ScreenCallOptions {\n screenName: string;\n properties?: RudderProperties;\n options?: RudderOptions;\n}\n\ninterface AliasCallOptions {\n newId: string;\n options?: RudderOptions;\n}\n\ninterface DeviceTokenCallOptions {\n deviceToken: string;\n}\n\ninterface AdvertisingIdCallOptions {\n advertisingId: string;\n}\n\ninterface AnonymousIdCallOptions {\n anonymousId: string;\n}\n\ninterface OptOutCallOptions {\n optOut: boolean;\n}\n\ninterface NativeRudderStackPlugin {\n initialize(options: InitializeCallOptions): Promise<void>;\n identify(options: IdentifyCallOptions): Promise<void>;\n group(options: GroupCallOptions): Promise<void>;\n track(options: TrackCallOptions): Promise<void>;\n screen(options: ScreenCallOptions): Promise<void>;\n alias(options: AliasCallOptions): Promise<void>;\n reset(): Promise<void>;\n flush(): Promise<void>;\n putDeviceToken(options: DeviceTokenCallOptions): Promise<void>;\n setAdvertisingId(options: AdvertisingIdCallOptions): Promise<void>;\n putAdvertisingId(options: AdvertisingIdCallOptions): Promise<void>;\n setAnonymousId(options: AnonymousIdCallOptions): Promise<void>;\n putAnonymousId(options: AnonymousIdCallOptions): Promise<void>;\n optOut(options: OptOutCallOptions): Promise<void>;\n getPluginVersion(): Promise<PluginVersionResult>;\n}\n\ntype RudderClientWithStatics = RudderStackPlugin & {\n LogLevel: typeof RudderLogLevel;\n};\n\nconst nativePlugin = registerPlugin<NativeRudderStackPlugin>('RudderStack', {\n web: () => import('./web').then((m) => new m.RudderStackWeb()),\n});\n\nexport const RudderLogLevel: Record<string, RudderLogLevelValue> = Object.freeze({\n VERBOSE: 5,\n DEBUG: 4,\n INFO: 3,\n WARN: 2,\n ERROR: 1,\n NONE: 0,\n});\n\nfunction isValidString(value: unknown): value is string {\n return typeof value === 'string' && value.trim().length > 0;\n}\n\nfunction isValidBoolean(value: unknown): value is boolean {\n return typeof value === 'boolean';\n}\n\nfunction isRecord(value: unknown): value is Record<string, any> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nfunction isRudderOptions(value: unknown): value is RudderOptions {\n return isRecord(value) && ('externalIds' in value || 'integrations' in value);\n}\n\nfunction sanitizeConfig(config?: RudderConfiguration): RudderConfiguration | undefined {\n if (!config) {\n return undefined;\n }\n\n if (Array.isArray(config.factories) && config.factories.length > 0) {\n console.warn(\n 'config.factories is ignored by @capgo/capacitor-rudderstack. Native Rudder destination factories are not implemented yet.',\n );\n }\n\n const { factories, ...safeConfig } = config;\n void factories;\n return safeConfig;\n}\n\nasync function callIfValid<T>(value: T | undefined, errorMessage: string, action: () => Promise<void>): Promise<void> {\n if (value === undefined) {\n console.log(errorMessage);\n return;\n }\n\n await action();\n}\n\nconst RudderClient: RudderClientWithStatics = {\n async initialize(writeKey, config, options) {\n if (!isValidString(writeKey)) {\n const message = 'WriteKey is Invalid, Aborting SDK Initialization';\n console.log(message);\n throw new Error(message);\n }\n\n let resolvedConfig = config;\n let resolvedOptions = options;\n\n if (isRudderOptions(config)) {\n resolvedOptions = config;\n resolvedConfig = undefined;\n }\n\n if (resolvedOptions !== undefined && !isRudderOptions(resolvedOptions)) {\n console.log('Options is invalid, setting it to null');\n resolvedOptions = undefined;\n }\n\n await nativePlugin.initialize({\n writeKey,\n config: sanitizeConfig(resolvedConfig as RudderConfiguration | undefined),\n options: resolvedOptions,\n });\n },\n\n async identify(userId, traits, options) {\n if (!isValidString(userId)) {\n console.log('userId is Invalid, dropping identify call');\n return;\n }\n\n let resolvedTraits = traits;\n let resolvedOptions = options;\n\n if (isRudderOptions(traits)) {\n resolvedOptions = traits;\n resolvedTraits = undefined;\n }\n\n if (resolvedOptions !== undefined && !isRudderOptions(resolvedOptions)) {\n console.log('Options is invalid, setting it to null');\n resolvedOptions = undefined;\n }\n\n await nativePlugin.identify({\n userId,\n traits: resolvedTraits as RudderTraits | undefined,\n options: resolvedOptions,\n });\n },\n\n async group(groupId, groupTraits, options) {\n if (!isValidString(groupId)) {\n console.log('groupId is Invalid, dropping group call');\n return;\n }\n\n let resolvedTraits = groupTraits;\n let resolvedOptions = options;\n\n if (isRudderOptions(groupTraits)) {\n resolvedOptions = groupTraits;\n resolvedTraits = undefined;\n }\n\n if (resolvedOptions !== undefined && !isRudderOptions(resolvedOptions)) {\n console.log('Options is invalid, setting it to null');\n resolvedOptions = undefined;\n }\n\n await nativePlugin.group({\n groupId,\n groupTraits: resolvedTraits as RudderTraits | undefined,\n options: resolvedOptions,\n });\n },\n\n async track(eventName, properties, options) {\n if (!isValidString(eventName)) {\n console.log('eventName is Invalid, dropping track call');\n return;\n }\n\n let resolvedProperties = properties;\n let resolvedOptions = options;\n\n if (isRudderOptions(properties)) {\n resolvedOptions = properties;\n resolvedProperties = undefined;\n }\n\n if (resolvedOptions !== undefined && !isRudderOptions(resolvedOptions)) {\n console.log('Options is invalid, setting it to null');\n resolvedOptions = undefined;\n }\n\n await nativePlugin.track({\n eventName,\n properties: resolvedProperties as RudderProperties | undefined,\n options: resolvedOptions,\n });\n },\n\n async screen(screenName, properties, options) {\n if (!isValidString(screenName)) {\n console.log('screenName is Invalid, dropping screen call');\n return;\n }\n\n let resolvedProperties = properties;\n let resolvedOptions = options;\n\n if (isRudderOptions(properties)) {\n resolvedOptions = properties;\n resolvedProperties = undefined;\n }\n\n if (resolvedOptions !== undefined && !isRudderOptions(resolvedOptions)) {\n console.log('Options is invalid, setting it to null');\n resolvedOptions = undefined;\n }\n\n await nativePlugin.screen({\n screenName,\n properties: resolvedProperties as RudderProperties | undefined,\n options: resolvedOptions,\n });\n },\n\n async alias(newId, options) {\n if (!isValidString(newId)) {\n console.log('newId is Invalid, dropping alias call');\n return;\n }\n\n const resolvedOptions = options !== undefined && !isRudderOptions(options) ? undefined : options;\n if (options !== undefined && resolvedOptions === undefined) {\n console.log('Options is invalid, setting it to null');\n }\n\n await nativePlugin.alias({\n newId,\n options: resolvedOptions,\n });\n },\n\n async reset() {\n await nativePlugin.reset();\n },\n\n async flush() {\n await nativePlugin.flush();\n },\n\n async putDeviceToken(deviceToken) {\n await callIfValid(\n isValidString(deviceToken) ? deviceToken : undefined,\n 'deviceToken is Invalid, dropping putDeviceToken call',\n () => nativePlugin.putDeviceToken({ deviceToken }),\n );\n },\n\n async setAdvertisingId(advertisingId) {\n await this.putAdvertisingId(advertisingId);\n },\n\n async putAdvertisingId(advertisingId) {\n await callIfValid(\n isValidString(advertisingId) ? advertisingId : undefined,\n 'advertisingId is Invalid, dropping putAdvertisingId call',\n () => nativePlugin.putAdvertisingId({ advertisingId }),\n );\n },\n\n async setAnonymousId(anonymousId) {\n await this.putAnonymousId(anonymousId);\n },\n\n async putAnonymousId(anonymousId) {\n await callIfValid(\n isValidString(anonymousId) ? anonymousId : undefined,\n 'anonymousId is Invalid, dropping putAnonymousId call',\n () => nativePlugin.putAnonymousId({ anonymousId }),\n );\n },\n\n async optOut(optOut) {\n if (!isValidBoolean(optOut)) {\n console.log('optOut is Invalid, dropping optOut call');\n return;\n }\n\n await nativePlugin.optOut({ optOut });\n },\n\n async getPluginVersion() {\n return nativePlugin.getPluginVersion();\n },\n\n LogLevel: RudderLogLevel,\n};\n\nconst RudderStack = RudderClient;\n\nexport * from './definitions';\nexport { RudderClient, RudderStack };\n"]}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { WebPlugin } from '@capacitor/core';
|
|
2
|
+
import type { PluginVersionResult, RudderConfiguration, RudderOptions, RudderProperties, RudderTraits } from './definitions';
|
|
3
|
+
interface InitializeCallOptions {
|
|
4
|
+
writeKey: string;
|
|
5
|
+
config?: RudderConfiguration;
|
|
6
|
+
options?: RudderOptions;
|
|
7
|
+
}
|
|
8
|
+
interface IdentifyCallOptions {
|
|
9
|
+
userId: string;
|
|
10
|
+
traits?: RudderTraits;
|
|
11
|
+
options?: RudderOptions;
|
|
12
|
+
}
|
|
13
|
+
interface GroupCallOptions {
|
|
14
|
+
groupId: string;
|
|
15
|
+
groupTraits?: RudderTraits;
|
|
16
|
+
options?: RudderOptions;
|
|
17
|
+
}
|
|
18
|
+
interface TrackCallOptions {
|
|
19
|
+
eventName: string;
|
|
20
|
+
properties?: RudderProperties;
|
|
21
|
+
options?: RudderOptions;
|
|
22
|
+
}
|
|
23
|
+
interface ScreenCallOptions {
|
|
24
|
+
screenName: string;
|
|
25
|
+
properties?: RudderProperties;
|
|
26
|
+
options?: RudderOptions;
|
|
27
|
+
}
|
|
28
|
+
interface AliasCallOptions {
|
|
29
|
+
newId: string;
|
|
30
|
+
options?: RudderOptions;
|
|
31
|
+
}
|
|
32
|
+
export declare class RudderStackWeb extends WebPlugin {
|
|
33
|
+
private initialized;
|
|
34
|
+
initialize(options: InitializeCallOptions): Promise<void>;
|
|
35
|
+
identify(options: IdentifyCallOptions): Promise<void>;
|
|
36
|
+
group(options: GroupCallOptions): Promise<void>;
|
|
37
|
+
track(options: TrackCallOptions): Promise<void>;
|
|
38
|
+
screen(options: ScreenCallOptions): Promise<void>;
|
|
39
|
+
alias(options: AliasCallOptions): Promise<void>;
|
|
40
|
+
reset(): Promise<void>;
|
|
41
|
+
flush(): Promise<void>;
|
|
42
|
+
putDeviceToken(options: {
|
|
43
|
+
deviceToken: string;
|
|
44
|
+
}): Promise<void>;
|
|
45
|
+
setAdvertisingId(options: {
|
|
46
|
+
advertisingId: string;
|
|
47
|
+
}): Promise<void>;
|
|
48
|
+
putAdvertisingId(options: {
|
|
49
|
+
advertisingId: string;
|
|
50
|
+
}): Promise<void>;
|
|
51
|
+
setAnonymousId(options: {
|
|
52
|
+
anonymousId: string;
|
|
53
|
+
}): Promise<void>;
|
|
54
|
+
putAnonymousId(options: {
|
|
55
|
+
anonymousId: string;
|
|
56
|
+
}): Promise<void>;
|
|
57
|
+
optOut(options: {
|
|
58
|
+
optOut: boolean;
|
|
59
|
+
}): Promise<void>;
|
|
60
|
+
getPluginVersion(): Promise<PluginVersionResult>;
|
|
61
|
+
private ensureInitialized;
|
|
62
|
+
}
|
|
63
|
+
export {};
|
package/dist/esm/web.js
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { WebPlugin } from '@capacitor/core';
|
|
2
|
+
export class RudderStackWeb extends WebPlugin {
|
|
3
|
+
constructor() {
|
|
4
|
+
super(...arguments);
|
|
5
|
+
this.initialized = false;
|
|
6
|
+
}
|
|
7
|
+
async initialize(options) {
|
|
8
|
+
if (!options.writeKey) {
|
|
9
|
+
throw new Error('writeKey is required');
|
|
10
|
+
}
|
|
11
|
+
this.initialized = true;
|
|
12
|
+
}
|
|
13
|
+
async identify(options) {
|
|
14
|
+
this.ensureInitialized();
|
|
15
|
+
void options;
|
|
16
|
+
}
|
|
17
|
+
async group(options) {
|
|
18
|
+
this.ensureInitialized();
|
|
19
|
+
void options;
|
|
20
|
+
}
|
|
21
|
+
async track(options) {
|
|
22
|
+
this.ensureInitialized();
|
|
23
|
+
void options;
|
|
24
|
+
}
|
|
25
|
+
async screen(options) {
|
|
26
|
+
this.ensureInitialized();
|
|
27
|
+
void options;
|
|
28
|
+
}
|
|
29
|
+
async alias(options) {
|
|
30
|
+
this.ensureInitialized();
|
|
31
|
+
void options;
|
|
32
|
+
}
|
|
33
|
+
async reset() {
|
|
34
|
+
this.ensureInitialized();
|
|
35
|
+
}
|
|
36
|
+
async flush() {
|
|
37
|
+
this.ensureInitialized();
|
|
38
|
+
}
|
|
39
|
+
async putDeviceToken(options) {
|
|
40
|
+
void options.deviceToken;
|
|
41
|
+
}
|
|
42
|
+
async setAdvertisingId(options) {
|
|
43
|
+
await this.putAdvertisingId(options);
|
|
44
|
+
}
|
|
45
|
+
async putAdvertisingId(options) {
|
|
46
|
+
void options.advertisingId;
|
|
47
|
+
}
|
|
48
|
+
async setAnonymousId(options) {
|
|
49
|
+
await this.putAnonymousId(options);
|
|
50
|
+
}
|
|
51
|
+
async putAnonymousId(options) {
|
|
52
|
+
void options.anonymousId;
|
|
53
|
+
}
|
|
54
|
+
async optOut(options) {
|
|
55
|
+
this.ensureInitialized();
|
|
56
|
+
void options.optOut;
|
|
57
|
+
}
|
|
58
|
+
async getPluginVersion() {
|
|
59
|
+
return {
|
|
60
|
+
version: 'web',
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
ensureInitialized() {
|
|
64
|
+
if (!this.initialized) {
|
|
65
|
+
throw new Error('RudderStack SDK is not initialized');
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=web.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AA6C5C,MAAM,OAAO,cAAe,SAAQ,SAAS;IAA7C;;QACU,gBAAW,GAAG,KAAK,CAAC;IA+E9B,CAAC;IA7EC,KAAK,CAAC,UAAU,CAAC,OAA8B;QAC7C,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;YACtB,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;QAC1C,CAAC;QAED,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;IAC1B,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,OAA4B;QACzC,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACzB,KAAK,OAAO,CAAC;IACf,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,OAAyB;QACnC,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACzB,KAAK,OAAO,CAAC;IACf,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,OAAyB;QACnC,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACzB,KAAK,OAAO,CAAC;IACf,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,OAA0B;QACrC,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACzB,KAAK,OAAO,CAAC;IACf,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,OAAyB;QACnC,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACzB,KAAK,OAAO,CAAC;IACf,CAAC;IAED,KAAK,CAAC,KAAK;QACT,IAAI,CAAC,iBAAiB,EAAE,CAAC;IAC3B,CAAC;IAED,KAAK,CAAC,KAAK;QACT,IAAI,CAAC,iBAAiB,EAAE,CAAC;IAC3B,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,OAAgC;QACnD,KAAK,OAAO,CAAC,WAAW,CAAC;IAC3B,CAAC;IAED,KAAK,CAAC,gBAAgB,CAAC,OAAkC;QACvD,MAAM,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;IACvC,CAAC;IAED,KAAK,CAAC,gBAAgB,CAAC,OAAkC;QACvD,KAAK,OAAO,CAAC,aAAa,CAAC;IAC7B,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,OAAgC;QACnD,MAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;IACrC,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,OAAgC;QACnD,KAAK,OAAO,CAAC,WAAW,CAAC;IAC3B,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,OAA4B;QACvC,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACzB,KAAK,OAAO,CAAC,MAAM,CAAC;IACtB,CAAC;IAED,KAAK,CAAC,gBAAgB;QACpB,OAAO;YACL,OAAO,EAAE,KAAK;SACf,CAAC;IACJ,CAAC;IAEO,iBAAiB;QACvB,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;YACtB,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;QACxD,CAAC;IACH,CAAC;CACF","sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\nimport type {\n PluginVersionResult,\n RudderConfiguration,\n RudderOptions,\n RudderProperties,\n RudderTraits,\n} from './definitions';\n\ninterface InitializeCallOptions {\n writeKey: string;\n config?: RudderConfiguration;\n options?: RudderOptions;\n}\n\ninterface IdentifyCallOptions {\n userId: string;\n traits?: RudderTraits;\n options?: RudderOptions;\n}\n\ninterface GroupCallOptions {\n groupId: string;\n groupTraits?: RudderTraits;\n options?: RudderOptions;\n}\n\ninterface TrackCallOptions {\n eventName: string;\n properties?: RudderProperties;\n options?: RudderOptions;\n}\n\ninterface ScreenCallOptions {\n screenName: string;\n properties?: RudderProperties;\n options?: RudderOptions;\n}\n\ninterface AliasCallOptions {\n newId: string;\n options?: RudderOptions;\n}\n\nexport class RudderStackWeb extends WebPlugin {\n private initialized = false;\n\n async initialize(options: InitializeCallOptions): Promise<void> {\n if (!options.writeKey) {\n throw new Error('writeKey is required');\n }\n\n this.initialized = true;\n }\n\n async identify(options: IdentifyCallOptions): Promise<void> {\n this.ensureInitialized();\n void options;\n }\n\n async group(options: GroupCallOptions): Promise<void> {\n this.ensureInitialized();\n void options;\n }\n\n async track(options: TrackCallOptions): Promise<void> {\n this.ensureInitialized();\n void options;\n }\n\n async screen(options: ScreenCallOptions): Promise<void> {\n this.ensureInitialized();\n void options;\n }\n\n async alias(options: AliasCallOptions): Promise<void> {\n this.ensureInitialized();\n void options;\n }\n\n async reset(): Promise<void> {\n this.ensureInitialized();\n }\n\n async flush(): Promise<void> {\n this.ensureInitialized();\n }\n\n async putDeviceToken(options: { deviceToken: string }): Promise<void> {\n void options.deviceToken;\n }\n\n async setAdvertisingId(options: { advertisingId: string }): Promise<void> {\n await this.putAdvertisingId(options);\n }\n\n async putAdvertisingId(options: { advertisingId: string }): Promise<void> {\n void options.advertisingId;\n }\n\n async setAnonymousId(options: { anonymousId: string }): Promise<void> {\n await this.putAnonymousId(options);\n }\n\n async putAnonymousId(options: { anonymousId: string }): Promise<void> {\n void options.anonymousId;\n }\n\n async optOut(options: { optOut: boolean }): Promise<void> {\n this.ensureInitialized();\n void options.optOut;\n }\n\n async getPluginVersion(): Promise<PluginVersionResult> {\n return {\n version: 'web',\n };\n }\n\n private ensureInitialized(): void {\n if (!this.initialized) {\n throw new Error('RudderStack SDK is not initialized');\n }\n }\n}\n"]}
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('@capacitor/core');
|
|
4
|
+
|
|
5
|
+
var __rest = (undefined && undefined.__rest) || function (s, e) {
|
|
6
|
+
var t = {};
|
|
7
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
8
|
+
t[p] = s[p];
|
|
9
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
10
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
11
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
12
|
+
t[p[i]] = s[p[i]];
|
|
13
|
+
}
|
|
14
|
+
return t;
|
|
15
|
+
};
|
|
16
|
+
const nativePlugin = core.registerPlugin('RudderStack', {
|
|
17
|
+
web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.RudderStackWeb()),
|
|
18
|
+
});
|
|
19
|
+
const RudderLogLevel = Object.freeze({
|
|
20
|
+
VERBOSE: 5,
|
|
21
|
+
DEBUG: 4,
|
|
22
|
+
INFO: 3,
|
|
23
|
+
WARN: 2,
|
|
24
|
+
ERROR: 1,
|
|
25
|
+
NONE: 0,
|
|
26
|
+
});
|
|
27
|
+
function isValidString(value) {
|
|
28
|
+
return typeof value === 'string' && value.trim().length > 0;
|
|
29
|
+
}
|
|
30
|
+
function isValidBoolean(value) {
|
|
31
|
+
return typeof value === 'boolean';
|
|
32
|
+
}
|
|
33
|
+
function isRecord(value) {
|
|
34
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
35
|
+
}
|
|
36
|
+
function isRudderOptions(value) {
|
|
37
|
+
return isRecord(value) && ('externalIds' in value || 'integrations' in value);
|
|
38
|
+
}
|
|
39
|
+
function sanitizeConfig(config) {
|
|
40
|
+
if (!config) {
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
if (Array.isArray(config.factories) && config.factories.length > 0) {
|
|
44
|
+
console.warn('config.factories is ignored by @capgo/capacitor-rudderstack. Native Rudder destination factories are not implemented yet.');
|
|
45
|
+
}
|
|
46
|
+
const { factories } = config, safeConfig = __rest(config, ["factories"]);
|
|
47
|
+
return safeConfig;
|
|
48
|
+
}
|
|
49
|
+
async function callIfValid(value, errorMessage, action) {
|
|
50
|
+
if (value === undefined) {
|
|
51
|
+
console.log(errorMessage);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
await action();
|
|
55
|
+
}
|
|
56
|
+
const RudderClient = {
|
|
57
|
+
async initialize(writeKey, config, options) {
|
|
58
|
+
if (!isValidString(writeKey)) {
|
|
59
|
+
const message = 'WriteKey is Invalid, Aborting SDK Initialization';
|
|
60
|
+
console.log(message);
|
|
61
|
+
throw new Error(message);
|
|
62
|
+
}
|
|
63
|
+
let resolvedConfig = config;
|
|
64
|
+
let resolvedOptions = options;
|
|
65
|
+
if (isRudderOptions(config)) {
|
|
66
|
+
resolvedOptions = config;
|
|
67
|
+
resolvedConfig = undefined;
|
|
68
|
+
}
|
|
69
|
+
if (resolvedOptions !== undefined && !isRudderOptions(resolvedOptions)) {
|
|
70
|
+
console.log('Options is invalid, setting it to null');
|
|
71
|
+
resolvedOptions = undefined;
|
|
72
|
+
}
|
|
73
|
+
await nativePlugin.initialize({
|
|
74
|
+
writeKey,
|
|
75
|
+
config: sanitizeConfig(resolvedConfig),
|
|
76
|
+
options: resolvedOptions,
|
|
77
|
+
});
|
|
78
|
+
},
|
|
79
|
+
async identify(userId, traits, options) {
|
|
80
|
+
if (!isValidString(userId)) {
|
|
81
|
+
console.log('userId is Invalid, dropping identify call');
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
let resolvedTraits = traits;
|
|
85
|
+
let resolvedOptions = options;
|
|
86
|
+
if (isRudderOptions(traits)) {
|
|
87
|
+
resolvedOptions = traits;
|
|
88
|
+
resolvedTraits = undefined;
|
|
89
|
+
}
|
|
90
|
+
if (resolvedOptions !== undefined && !isRudderOptions(resolvedOptions)) {
|
|
91
|
+
console.log('Options is invalid, setting it to null');
|
|
92
|
+
resolvedOptions = undefined;
|
|
93
|
+
}
|
|
94
|
+
await nativePlugin.identify({
|
|
95
|
+
userId,
|
|
96
|
+
traits: resolvedTraits,
|
|
97
|
+
options: resolvedOptions,
|
|
98
|
+
});
|
|
99
|
+
},
|
|
100
|
+
async group(groupId, groupTraits, options) {
|
|
101
|
+
if (!isValidString(groupId)) {
|
|
102
|
+
console.log('groupId is Invalid, dropping group call');
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
let resolvedTraits = groupTraits;
|
|
106
|
+
let resolvedOptions = options;
|
|
107
|
+
if (isRudderOptions(groupTraits)) {
|
|
108
|
+
resolvedOptions = groupTraits;
|
|
109
|
+
resolvedTraits = undefined;
|
|
110
|
+
}
|
|
111
|
+
if (resolvedOptions !== undefined && !isRudderOptions(resolvedOptions)) {
|
|
112
|
+
console.log('Options is invalid, setting it to null');
|
|
113
|
+
resolvedOptions = undefined;
|
|
114
|
+
}
|
|
115
|
+
await nativePlugin.group({
|
|
116
|
+
groupId,
|
|
117
|
+
groupTraits: resolvedTraits,
|
|
118
|
+
options: resolvedOptions,
|
|
119
|
+
});
|
|
120
|
+
},
|
|
121
|
+
async track(eventName, properties, options) {
|
|
122
|
+
if (!isValidString(eventName)) {
|
|
123
|
+
console.log('eventName is Invalid, dropping track call');
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
let resolvedProperties = properties;
|
|
127
|
+
let resolvedOptions = options;
|
|
128
|
+
if (isRudderOptions(properties)) {
|
|
129
|
+
resolvedOptions = properties;
|
|
130
|
+
resolvedProperties = undefined;
|
|
131
|
+
}
|
|
132
|
+
if (resolvedOptions !== undefined && !isRudderOptions(resolvedOptions)) {
|
|
133
|
+
console.log('Options is invalid, setting it to null');
|
|
134
|
+
resolvedOptions = undefined;
|
|
135
|
+
}
|
|
136
|
+
await nativePlugin.track({
|
|
137
|
+
eventName,
|
|
138
|
+
properties: resolvedProperties,
|
|
139
|
+
options: resolvedOptions,
|
|
140
|
+
});
|
|
141
|
+
},
|
|
142
|
+
async screen(screenName, properties, options) {
|
|
143
|
+
if (!isValidString(screenName)) {
|
|
144
|
+
console.log('screenName is Invalid, dropping screen call');
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
let resolvedProperties = properties;
|
|
148
|
+
let resolvedOptions = options;
|
|
149
|
+
if (isRudderOptions(properties)) {
|
|
150
|
+
resolvedOptions = properties;
|
|
151
|
+
resolvedProperties = undefined;
|
|
152
|
+
}
|
|
153
|
+
if (resolvedOptions !== undefined && !isRudderOptions(resolvedOptions)) {
|
|
154
|
+
console.log('Options is invalid, setting it to null');
|
|
155
|
+
resolvedOptions = undefined;
|
|
156
|
+
}
|
|
157
|
+
await nativePlugin.screen({
|
|
158
|
+
screenName,
|
|
159
|
+
properties: resolvedProperties,
|
|
160
|
+
options: resolvedOptions,
|
|
161
|
+
});
|
|
162
|
+
},
|
|
163
|
+
async alias(newId, options) {
|
|
164
|
+
if (!isValidString(newId)) {
|
|
165
|
+
console.log('newId is Invalid, dropping alias call');
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
const resolvedOptions = options !== undefined && !isRudderOptions(options) ? undefined : options;
|
|
169
|
+
if (options !== undefined && resolvedOptions === undefined) {
|
|
170
|
+
console.log('Options is invalid, setting it to null');
|
|
171
|
+
}
|
|
172
|
+
await nativePlugin.alias({
|
|
173
|
+
newId,
|
|
174
|
+
options: resolvedOptions,
|
|
175
|
+
});
|
|
176
|
+
},
|
|
177
|
+
async reset() {
|
|
178
|
+
await nativePlugin.reset();
|
|
179
|
+
},
|
|
180
|
+
async flush() {
|
|
181
|
+
await nativePlugin.flush();
|
|
182
|
+
},
|
|
183
|
+
async putDeviceToken(deviceToken) {
|
|
184
|
+
await callIfValid(isValidString(deviceToken) ? deviceToken : undefined, 'deviceToken is Invalid, dropping putDeviceToken call', () => nativePlugin.putDeviceToken({ deviceToken }));
|
|
185
|
+
},
|
|
186
|
+
async setAdvertisingId(advertisingId) {
|
|
187
|
+
await this.putAdvertisingId(advertisingId);
|
|
188
|
+
},
|
|
189
|
+
async putAdvertisingId(advertisingId) {
|
|
190
|
+
await callIfValid(isValidString(advertisingId) ? advertisingId : undefined, 'advertisingId is Invalid, dropping putAdvertisingId call', () => nativePlugin.putAdvertisingId({ advertisingId }));
|
|
191
|
+
},
|
|
192
|
+
async setAnonymousId(anonymousId) {
|
|
193
|
+
await this.putAnonymousId(anonymousId);
|
|
194
|
+
},
|
|
195
|
+
async putAnonymousId(anonymousId) {
|
|
196
|
+
await callIfValid(isValidString(anonymousId) ? anonymousId : undefined, 'anonymousId is Invalid, dropping putAnonymousId call', () => nativePlugin.putAnonymousId({ anonymousId }));
|
|
197
|
+
},
|
|
198
|
+
async optOut(optOut) {
|
|
199
|
+
if (!isValidBoolean(optOut)) {
|
|
200
|
+
console.log('optOut is Invalid, dropping optOut call');
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
await nativePlugin.optOut({ optOut });
|
|
204
|
+
},
|
|
205
|
+
async getPluginVersion() {
|
|
206
|
+
return nativePlugin.getPluginVersion();
|
|
207
|
+
},
|
|
208
|
+
LogLevel: RudderLogLevel,
|
|
209
|
+
};
|
|
210
|
+
const RudderStack = RudderClient;
|
|
211
|
+
|
|
212
|
+
class RudderStackWeb extends core.WebPlugin {
|
|
213
|
+
constructor() {
|
|
214
|
+
super(...arguments);
|
|
215
|
+
this.initialized = false;
|
|
216
|
+
}
|
|
217
|
+
async initialize(options) {
|
|
218
|
+
if (!options.writeKey) {
|
|
219
|
+
throw new Error('writeKey is required');
|
|
220
|
+
}
|
|
221
|
+
this.initialized = true;
|
|
222
|
+
}
|
|
223
|
+
async identify(options) {
|
|
224
|
+
this.ensureInitialized();
|
|
225
|
+
}
|
|
226
|
+
async group(options) {
|
|
227
|
+
this.ensureInitialized();
|
|
228
|
+
}
|
|
229
|
+
async track(options) {
|
|
230
|
+
this.ensureInitialized();
|
|
231
|
+
}
|
|
232
|
+
async screen(options) {
|
|
233
|
+
this.ensureInitialized();
|
|
234
|
+
}
|
|
235
|
+
async alias(options) {
|
|
236
|
+
this.ensureInitialized();
|
|
237
|
+
}
|
|
238
|
+
async reset() {
|
|
239
|
+
this.ensureInitialized();
|
|
240
|
+
}
|
|
241
|
+
async flush() {
|
|
242
|
+
this.ensureInitialized();
|
|
243
|
+
}
|
|
244
|
+
async putDeviceToken(options) {
|
|
245
|
+
void options.deviceToken;
|
|
246
|
+
}
|
|
247
|
+
async setAdvertisingId(options) {
|
|
248
|
+
await this.putAdvertisingId(options);
|
|
249
|
+
}
|
|
250
|
+
async putAdvertisingId(options) {
|
|
251
|
+
void options.advertisingId;
|
|
252
|
+
}
|
|
253
|
+
async setAnonymousId(options) {
|
|
254
|
+
await this.putAnonymousId(options);
|
|
255
|
+
}
|
|
256
|
+
async putAnonymousId(options) {
|
|
257
|
+
void options.anonymousId;
|
|
258
|
+
}
|
|
259
|
+
async optOut(options) {
|
|
260
|
+
this.ensureInitialized();
|
|
261
|
+
void options.optOut;
|
|
262
|
+
}
|
|
263
|
+
async getPluginVersion() {
|
|
264
|
+
return {
|
|
265
|
+
version: 'web',
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
ensureInitialized() {
|
|
269
|
+
if (!this.initialized) {
|
|
270
|
+
throw new Error('RudderStack SDK is not initialized');
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
var web = /*#__PURE__*/Object.freeze({
|
|
276
|
+
__proto__: null,
|
|
277
|
+
RudderStackWeb: RudderStackWeb
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
exports.RudderClient = RudderClient;
|
|
281
|
+
exports.RudderLogLevel = RudderLogLevel;
|
|
282
|
+
exports.RudderStack = RudderStack;
|
|
283
|
+
//# sourceMappingURL=plugin.cjs.js.map
|