@wireai/activation 0.4.0 → 0.8.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/AGENTS.md +1 -1
- package/CHANGELOG.md +92 -0
- package/dist/analytics/index.d.mts +19 -2
- package/dist/analytics/index.d.ts +19 -2
- package/dist/analytics/index.js +258 -18
- package/dist/analytics/index.js.map +1 -1
- package/dist/analytics/index.mjs +256 -19
- package/dist/analytics/index.mjs.map +1 -1
- package/dist/{eventQueue-CA1d8Fmn.d.mts → currentSession-d9CrBxwe.d.mts} +152 -16
- package/dist/{eventQueue-CrNB9gzH.d.ts → currentSession-f7LWcdWG.d.ts} +152 -16
- package/dist/index.d.mts +96 -32
- package/dist/index.d.ts +96 -32
- package/dist/index.js +214 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +201 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/WireOnboarding.tsx +4 -3
- package/src/analytics/analyticsFacade.ts +120 -12
- package/src/analytics/contextEnvelope.ts +13 -7
- package/src/analytics/currentSession.ts +35 -0
- package/src/analytics/index.ts +3 -0
- package/src/context/deviceId.ts +43 -0
- package/src/context/userContext.ts +210 -0
- package/src/device/appVersion.ts +103 -0
- package/src/device/deviceContext.ts +31 -6
- package/src/device/deviceModel.ts +93 -0
- package/src/identity/userIdentity.ts +5 -0
- package/src/index.ts +25 -0
- package/src/session-analytics/reportSessionStart.ts +7 -0
- package/src/session-analytics/useLifecycleEvents.ts +4 -2
- package/src/session-analytics/useSessionStart.ts +2 -1
- package/src/types.ts +6 -5
package/dist/index.mjs
CHANGED
|
@@ -6,6 +6,12 @@ import { SafeAreaView } from 'react-native-safe-area-context';
|
|
|
6
6
|
import { z } from 'zod';
|
|
7
7
|
|
|
8
8
|
var __defProp = Object.defineProperty;
|
|
9
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
10
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
11
|
+
}) : x)(function(x) {
|
|
12
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
13
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
14
|
+
});
|
|
9
15
|
var __export = (target, all) => {
|
|
10
16
|
for (var name in all)
|
|
11
17
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -2343,6 +2349,98 @@ var onboardingComponents = [
|
|
|
2343
2349
|
NumberStepperCard,
|
|
2344
2350
|
InterstitialCard
|
|
2345
2351
|
];
|
|
2352
|
+
|
|
2353
|
+
// src/device/appVersion.ts
|
|
2354
|
+
var coerceVersion = (value) => {
|
|
2355
|
+
if (typeof value !== "string") return void 0;
|
|
2356
|
+
const trimmed = value.trim();
|
|
2357
|
+
return trimmed.length > 0 ? trimmed : void 0;
|
|
2358
|
+
};
|
|
2359
|
+
var runtimeRequire = (moduleName) => {
|
|
2360
|
+
try {
|
|
2361
|
+
if (typeof __require !== "function") return void 0;
|
|
2362
|
+
return __require(moduleName);
|
|
2363
|
+
} catch {
|
|
2364
|
+
return void 0;
|
|
2365
|
+
}
|
|
2366
|
+
};
|
|
2367
|
+
var interop = (mod) => {
|
|
2368
|
+
if (!mod || typeof mod !== "object") return void 0;
|
|
2369
|
+
const def = mod.default;
|
|
2370
|
+
if (def && typeof def === "object") return def;
|
|
2371
|
+
return mod;
|
|
2372
|
+
};
|
|
2373
|
+
var safeInterop = (requireModule, moduleName) => {
|
|
2374
|
+
try {
|
|
2375
|
+
return interop(requireModule(moduleName));
|
|
2376
|
+
} catch {
|
|
2377
|
+
return void 0;
|
|
2378
|
+
}
|
|
2379
|
+
};
|
|
2380
|
+
var detectAppVersion = (requireModule = runtimeRequire) => {
|
|
2381
|
+
try {
|
|
2382
|
+
const constants = safeInterop(requireModule, "expo-constants");
|
|
2383
|
+
if (constants) {
|
|
2384
|
+
const expoConfig = constants.expoConfig;
|
|
2385
|
+
if (expoConfig && typeof expoConfig === "object") {
|
|
2386
|
+
const fromExpoConfig = coerceVersion(expoConfig.version);
|
|
2387
|
+
if (fromExpoConfig) return fromExpoConfig;
|
|
2388
|
+
}
|
|
2389
|
+
const fromNative = coerceVersion(constants.nativeAppVersion);
|
|
2390
|
+
if (fromNative) return fromNative;
|
|
2391
|
+
}
|
|
2392
|
+
const application = safeInterop(requireModule, "expo-application");
|
|
2393
|
+
if (application) {
|
|
2394
|
+
const fromApplication = coerceVersion(application.nativeApplicationVersion);
|
|
2395
|
+
if (fromApplication) return fromApplication;
|
|
2396
|
+
}
|
|
2397
|
+
} catch {
|
|
2398
|
+
}
|
|
2399
|
+
return void 0;
|
|
2400
|
+
};
|
|
2401
|
+
|
|
2402
|
+
// src/device/deviceModel.ts
|
|
2403
|
+
var coerceModel = (value) => {
|
|
2404
|
+
if (typeof value !== "string") return void 0;
|
|
2405
|
+
const trimmed = value.trim();
|
|
2406
|
+
return trimmed.length > 0 ? trimmed : void 0;
|
|
2407
|
+
};
|
|
2408
|
+
var runtimeRequire2 = (moduleName) => {
|
|
2409
|
+
try {
|
|
2410
|
+
if (typeof __require !== "function") return void 0;
|
|
2411
|
+
return __require(moduleName);
|
|
2412
|
+
} catch {
|
|
2413
|
+
return void 0;
|
|
2414
|
+
}
|
|
2415
|
+
};
|
|
2416
|
+
var interop2 = (mod) => {
|
|
2417
|
+
if (!mod || typeof mod !== "object") return void 0;
|
|
2418
|
+
const def = mod.default;
|
|
2419
|
+
if (def && typeof def === "object") return def;
|
|
2420
|
+
return mod;
|
|
2421
|
+
};
|
|
2422
|
+
var safeInterop2 = (requireModule, moduleName) => {
|
|
2423
|
+
try {
|
|
2424
|
+
return interop2(requireModule(moduleName));
|
|
2425
|
+
} catch {
|
|
2426
|
+
return void 0;
|
|
2427
|
+
}
|
|
2428
|
+
};
|
|
2429
|
+
var detectNativeModel = (requireModule = runtimeRequire2) => {
|
|
2430
|
+
try {
|
|
2431
|
+
const device = safeInterop2(requireModule, "expo-device");
|
|
2432
|
+
if (device) {
|
|
2433
|
+
const modelName = coerceModel(device.modelName);
|
|
2434
|
+
if (modelName) return modelName;
|
|
2435
|
+
const modelId = coerceModel(device.modelId);
|
|
2436
|
+
if (modelId) return modelId;
|
|
2437
|
+
}
|
|
2438
|
+
} catch {
|
|
2439
|
+
}
|
|
2440
|
+
return void 0;
|
|
2441
|
+
};
|
|
2442
|
+
|
|
2443
|
+
// src/device/deviceContext.ts
|
|
2346
2444
|
var deriveFormFactor = (iosIdiom, width, height) => {
|
|
2347
2445
|
if (iosIdiom === "pad") return "tablet";
|
|
2348
2446
|
if (iosIdiom === "phone") return "phone";
|
|
@@ -2388,6 +2486,8 @@ var collectDeviceContext = () => {
|
|
|
2388
2486
|
ctx.interfaceIdiom = idiom;
|
|
2389
2487
|
iosIdiom = idiom;
|
|
2390
2488
|
}
|
|
2489
|
+
const iosModel = detectNativeModel();
|
|
2490
|
+
if (iosModel) ctx.model = iosModel;
|
|
2391
2491
|
}
|
|
2392
2492
|
} catch {
|
|
2393
2493
|
}
|
|
@@ -2412,9 +2512,21 @@ var collectDeviceContext = () => {
|
|
|
2412
2512
|
if (resolved.timeZone) ctx.timeZone = resolved.timeZone;
|
|
2413
2513
|
} catch {
|
|
2414
2514
|
}
|
|
2515
|
+
const appVersion = detectAppVersion();
|
|
2516
|
+
if (appVersion) ctx.appVersion = appVersion;
|
|
2415
2517
|
return ctx;
|
|
2416
2518
|
};
|
|
2417
2519
|
|
|
2520
|
+
// src/analytics/currentSession.ts
|
|
2521
|
+
var _currentSessionId;
|
|
2522
|
+
var setCurrentSessionId = (id) => {
|
|
2523
|
+
if (typeof id === "string" && id.length > 0) _currentSessionId = id;
|
|
2524
|
+
};
|
|
2525
|
+
var getCurrentSessionId = () => _currentSessionId;
|
|
2526
|
+
var resetCurrentSessionId = () => {
|
|
2527
|
+
_currentSessionId = void 0;
|
|
2528
|
+
};
|
|
2529
|
+
|
|
2418
2530
|
// src/session/persistedSession.ts
|
|
2419
2531
|
var DEFAULT_SESSION_TTL_MS = 36e5;
|
|
2420
2532
|
var READ_TIMEOUT_MS = 1500;
|
|
@@ -2493,6 +2605,7 @@ var identifyOnboarding = async (opts) => {
|
|
|
2493
2605
|
contextId = stored == null ? void 0 : stored.id;
|
|
2494
2606
|
}
|
|
2495
2607
|
}
|
|
2608
|
+
if (!contextId) contextId = getCurrentSessionId();
|
|
2496
2609
|
if (!contextId) return false;
|
|
2497
2610
|
reportClientEvent(
|
|
2498
2611
|
{ serverUrl: opts.config.serverUrl, apiKey: opts.config.apiKey },
|
|
@@ -3149,6 +3262,89 @@ var attributionMetadata = (a) => {
|
|
|
3149
3262
|
return { attribution };
|
|
3150
3263
|
};
|
|
3151
3264
|
|
|
3265
|
+
// src/context/userContext.ts
|
|
3266
|
+
var RESERVED_USER_CONTEXT_KEYS = [
|
|
3267
|
+
"device_key",
|
|
3268
|
+
"app_version",
|
|
3269
|
+
"app_build",
|
|
3270
|
+
"network_type",
|
|
3271
|
+
"session_count",
|
|
3272
|
+
"returning",
|
|
3273
|
+
"platform",
|
|
3274
|
+
"user_email",
|
|
3275
|
+
"user_email_hashed"
|
|
3276
|
+
];
|
|
3277
|
+
var EXTRA_KEY_PREFIX = "custom.";
|
|
3278
|
+
var isWireScalar = (value) => {
|
|
3279
|
+
const t = typeof value;
|
|
3280
|
+
if (t === "string" || t === "boolean") return true;
|
|
3281
|
+
if (t === "number") return Number.isFinite(value);
|
|
3282
|
+
return false;
|
|
3283
|
+
};
|
|
3284
|
+
var hashEmailFnv1a = (email) => {
|
|
3285
|
+
const normalized = email.trim().toLowerCase();
|
|
3286
|
+
let hash = 2166136261;
|
|
3287
|
+
for (let i = 0; i < normalized.length; i++) {
|
|
3288
|
+
hash ^= normalized.charCodeAt(i);
|
|
3289
|
+
hash = Math.imul(hash, 16777619);
|
|
3290
|
+
}
|
|
3291
|
+
return (hash >>> 0).toString(16).padStart(8, "0");
|
|
3292
|
+
};
|
|
3293
|
+
var cleanString = (value) => {
|
|
3294
|
+
if (typeof value !== "string") return void 0;
|
|
3295
|
+
const trimmed = value.trim();
|
|
3296
|
+
return trimmed.length > 0 ? trimmed : void 0;
|
|
3297
|
+
};
|
|
3298
|
+
var namespaceExtra = (extra) => {
|
|
3299
|
+
const out = {};
|
|
3300
|
+
if (!extra || typeof extra !== "object") return out;
|
|
3301
|
+
for (const [key, value] of Object.entries(extra)) {
|
|
3302
|
+
const cleanKey = cleanString(key);
|
|
3303
|
+
if (!cleanKey) continue;
|
|
3304
|
+
if (!isWireScalar(value)) continue;
|
|
3305
|
+
out[`${EXTRA_KEY_PREFIX}${cleanKey}`] = value;
|
|
3306
|
+
}
|
|
3307
|
+
return out;
|
|
3308
|
+
};
|
|
3309
|
+
var resolveUserContext = (ctx = {}, opts = {}) => {
|
|
3310
|
+
var _a;
|
|
3311
|
+
const result = {};
|
|
3312
|
+
const bucket = {};
|
|
3313
|
+
const userId = sanitizeUserId(ctx.userId);
|
|
3314
|
+
if (userId) result.userId = userId;
|
|
3315
|
+
const deviceKey = cleanString(ctx.deviceKey);
|
|
3316
|
+
if (deviceKey) {
|
|
3317
|
+
result.deviceKey = deviceKey;
|
|
3318
|
+
bucket.device_key = deviceKey;
|
|
3319
|
+
}
|
|
3320
|
+
const appVersion = (_a = cleanString(ctx.appVersion)) != null ? _a : cleanString(opts.autoAppVersion);
|
|
3321
|
+
if (appVersion) {
|
|
3322
|
+
result.appVersion = appVersion;
|
|
3323
|
+
bucket.app_version = appVersion;
|
|
3324
|
+
}
|
|
3325
|
+
const email = cleanString(ctx.userEmail);
|
|
3326
|
+
if (email) {
|
|
3327
|
+
if (ctx.hashEmail) {
|
|
3328
|
+
bucket.user_email = hashEmailFnv1a(email);
|
|
3329
|
+
bucket.user_email_hashed = true;
|
|
3330
|
+
} else {
|
|
3331
|
+
bucket.user_email = email;
|
|
3332
|
+
}
|
|
3333
|
+
}
|
|
3334
|
+
Object.assign(bucket, namespaceExtra(ctx.extra));
|
|
3335
|
+
if (Object.keys(bucket).length > 0) result.userContext = bucket;
|
|
3336
|
+
return result;
|
|
3337
|
+
};
|
|
3338
|
+
|
|
3339
|
+
// src/context/deviceId.ts
|
|
3340
|
+
var AUTO_DEVICE_ID_PREFIX = "wdev_";
|
|
3341
|
+
var deviceIdStorageKey = (appId) => `wireai:analytics:deviceKey:${appId != null ? appId : "default"}`;
|
|
3342
|
+
var randomChunk = () => Math.floor(Math.random() * 4294967296).toString(36).padStart(6, "0");
|
|
3343
|
+
var mintDeviceId = () => {
|
|
3344
|
+
const time = Date.now().toString(36);
|
|
3345
|
+
return `${AUTO_DEVICE_ID_PREFIX}${time}_${randomChunk()}${randomChunk()}`;
|
|
3346
|
+
};
|
|
3347
|
+
|
|
3152
3348
|
// src/session-analytics/reportSessionStart.ts
|
|
3153
3349
|
var SESSION_STARTED_EVENT = "app.session_started";
|
|
3154
3350
|
var _emitted = /* @__PURE__ */ new Set();
|
|
@@ -3161,6 +3357,7 @@ var reportSessionStart = (opts) => {
|
|
|
3161
3357
|
const target = opts.target;
|
|
3162
3358
|
if (!opts.sink && !(target == null ? void 0 : target.serverUrl)) return;
|
|
3163
3359
|
const sessionId = (_a = opts.sessionId) != null ? _a : makeSessionId();
|
|
3360
|
+
setCurrentSessionId(sessionId);
|
|
3164
3361
|
if (opts.once !== false) {
|
|
3165
3362
|
if (_emitted.has(sessionId)) return;
|
|
3166
3363
|
if (_emitted.size >= _GUARD_MAX) {
|
|
@@ -3217,7 +3414,7 @@ var useSessionStart = (config, options = {}) => {
|
|
|
3217
3414
|
if (opts.enabled === false) return;
|
|
3218
3415
|
const target = { serverUrl: cfg.serverUrl, apiKey: (_a = cfg.apiKey) != null ? _a : "" };
|
|
3219
3416
|
const device = collectDeviceContext();
|
|
3220
|
-
if (cfg.appVersion
|
|
3417
|
+
if (cfg.appVersion) device.appVersion = cfg.appVersion;
|
|
3221
3418
|
reportSessionStart({
|
|
3222
3419
|
target,
|
|
3223
3420
|
// A fresh per-open id each fire; the emitter's once-guard dedupes within the open.
|
|
@@ -3591,7 +3788,7 @@ var useLifecycleEvents = (config, options = {}) => {
|
|
|
3591
3788
|
const { config: cfg, options: opts } = latest.current;
|
|
3592
3789
|
if (opts.enabled !== false) {
|
|
3593
3790
|
const device = collectDeviceContext();
|
|
3594
|
-
if (
|
|
3791
|
+
if (cfg == null ? void 0 : cfg.appVersion) device.appVersion = cfg.appVersion;
|
|
3595
3792
|
reportFirstOpen({
|
|
3596
3793
|
target: targetOf(cfg),
|
|
3597
3794
|
sink: resolveSink(),
|
|
@@ -3613,7 +3810,7 @@ var useLifecycleEvents = (config, options = {}) => {
|
|
|
3613
3810
|
if (opts.enabled === false) return;
|
|
3614
3811
|
if (!(cfg == null ? void 0 : cfg.serverUrl) && !opts.sink) return;
|
|
3615
3812
|
const device = collectDeviceContext();
|
|
3616
|
-
if (
|
|
3813
|
+
if (cfg == null ? void 0 : cfg.appVersion) device.appVersion = cfg.appVersion;
|
|
3617
3814
|
reportSessionStart({
|
|
3618
3815
|
target: targetOf(cfg),
|
|
3619
3816
|
sink: resolveSink(),
|
|
@@ -3647,6 +3844,6 @@ var useLifecycleEvents = (config, options = {}) => {
|
|
|
3647
3844
|
}, []);
|
|
3648
3845
|
};
|
|
3649
3846
|
|
|
3650
|
-
export { AnimatedSparkle, BACKGROUND_SESSION_MS, CardHandoff, CenteredModal, ChipSelectCard, CompletionView, DEFAULT_FEATURES_TTL_MS, DEFAULT_SESSION_TTL_MS, DemoOnboarding, DoneBlock, ErrorBlock, FIRST_OPEN_EVENT, IllustrationProvider, InterstitialCard, LoadingBlock, LoadingScreen, NumberStepperCard, Button as OnboardingButton, OnboardingFlow, OnboardingScaffold, OnboardingThemeProvider, SESSION_STARTED_EVENT, SelectionCard, StatusCard, StepProgress, TextInputCard, USER_ID_MAX_LENGTH, WIRE_ONBOARDING_EVENTS, WireFeaturesProvider, WireOnboarding, attributionMetadata, clearPersistedSession, collectDeviceContext, defaultIllustrations, defaultOnboardingTheme, defaultWireFeatures, deriveAnswers, featuresCacheKey, featuresEqual, fetchWireFeatures, firstOpenStorageKey, identifyOnboarding, isFeaturesFresh, isOnboardingEnabled, loadPersistedSession, makeSessionId, mergeTheme, motionSpec_exports as motionSpec, onboardingComponents, parseWireFeatures, peekPersistedSession, readCachedFeatures, readProgress, reportClientEvent, reportClientEvents, reportFirstOpen, reportSessionStart, resetFirstOpenLatch, resetSessionStartGuard, sanitizeUserId, savePersistedSession, sessionStorageKey, themeFromBrand, toAnalyticsEvent, useIllustration, useLifecycleEvents, useOnboardingTheme, useReducedMotion, useResolvedFeatures, useSessionStart, useWireFeatures, useWireFeaturesContext, wireConfigFromEnv, wireLifecycleEvents, writeCachedFeatures };
|
|
3847
|
+
export { AUTO_DEVICE_ID_PREFIX, AnimatedSparkle, BACKGROUND_SESSION_MS, CardHandoff, CenteredModal, ChipSelectCard, CompletionView, DEFAULT_FEATURES_TTL_MS, DEFAULT_SESSION_TTL_MS, DemoOnboarding, DoneBlock, EXTRA_KEY_PREFIX, ErrorBlock, FIRST_OPEN_EVENT, IllustrationProvider, InterstitialCard, LoadingBlock, LoadingScreen, NumberStepperCard, Button as OnboardingButton, OnboardingFlow, OnboardingScaffold, OnboardingThemeProvider, RESERVED_USER_CONTEXT_KEYS, SESSION_STARTED_EVENT, SelectionCard, StatusCard, StepProgress, TextInputCard, USER_ID_MAX_LENGTH, WIRE_ONBOARDING_EVENTS, WireFeaturesProvider, WireOnboarding, attributionMetadata, clearPersistedSession, collectDeviceContext, defaultIllustrations, defaultOnboardingTheme, defaultWireFeatures, deriveAnswers, detectAppVersion, detectNativeModel, deviceIdStorageKey, featuresCacheKey, featuresEqual, fetchWireFeatures, firstOpenStorageKey, getCurrentSessionId, hashEmailFnv1a, identifyOnboarding, isFeaturesFresh, isOnboardingEnabled, isWireScalar, loadPersistedSession, makeSessionId, mergeTheme, mintDeviceId, motionSpec_exports as motionSpec, namespaceExtra, onboardingComponents, parseWireFeatures, peekPersistedSession, readCachedFeatures, readProgress, reportClientEvent, reportClientEvents, reportFirstOpen, reportSessionStart, resetCurrentSessionId, resetFirstOpenLatch, resetSessionStartGuard, resolveUserContext, sanitizeUserId, savePersistedSession, sessionStorageKey, setCurrentSessionId, themeFromBrand, toAnalyticsEvent, useIllustration, useLifecycleEvents, useOnboardingTheme, useReducedMotion, useResolvedFeatures, useSessionStart, useWireFeatures, useWireFeaturesContext, wireConfigFromEnv, wireLifecycleEvents, writeCachedFeatures };
|
|
3651
3848
|
//# sourceMappingURL=index.mjs.map
|
|
3652
3849
|
//# sourceMappingURL=index.mjs.map
|