@analyticscli/sdk 0.1.0-preview.5 → 0.1.0-preview.7

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.
@@ -196,7 +196,28 @@ var randomId = () => {
196
196
  if (globalThis.crypto?.randomUUID) {
197
197
  return globalThis.crypto.randomUUID();
198
198
  }
199
- return `${Date.now()}-${Math.random().toString(16).slice(2, 12)}`;
199
+ const bytes = new Uint8Array(16);
200
+ if (globalThis.crypto?.getRandomValues) {
201
+ globalThis.crypto.getRandomValues(bytes);
202
+ } else {
203
+ for (let index = 0; index < bytes.length; index += 1) {
204
+ bytes[index] = Math.floor(Math.random() * 256);
205
+ }
206
+ }
207
+ const byte6 = bytes[6] ?? 0;
208
+ const byte8 = bytes[8] ?? 0;
209
+ bytes[6] = byte6 & 15 | 64;
210
+ bytes[8] = byte8 & 63 | 128;
211
+ let output = "";
212
+ for (let index = 0; index < bytes.length; index += 1) {
213
+ const byte = bytes[index] ?? 0;
214
+ const hex = byte.toString(16).padStart(2, "0");
215
+ output += hex;
216
+ if (index === 3 || index === 5 || index === 7 || index === 9) {
217
+ output += "-";
218
+ }
219
+ }
220
+ return output;
200
221
  };
201
222
  var readStorageSync = (storage, key) => {
202
223
  if (!storage) {
@@ -1557,75 +1578,78 @@ var AnalyticsClient = class {
1557
1578
  }
1558
1579
  };
1559
1580
 
1560
- // src/bootstrap.ts
1561
- var DEFAULT_API_KEY_ENV_KEYS = [
1562
- "ANALYTICSCLI_PUBLISHABLE_API_KEY",
1563
- "NEXT_PUBLIC_ANALYTICSCLI_PUBLISHABLE_API_KEY",
1564
- "EXPO_PUBLIC_ANALYTICSCLI_PUBLISHABLE_API_KEY",
1565
- "VITE_ANALYTICSCLI_PUBLISHABLE_API_KEY"
1566
- ];
1567
- var readTrimmedString2 = (value) => {
1568
- if (typeof value === "string") {
1569
- return value.trim();
1570
- }
1571
- if (typeof value === "number" || typeof value === "boolean") {
1572
- return String(value).trim();
1573
- }
1574
- return "";
1575
- };
1576
- var resolveDefaultEnv = () => {
1577
- const withProcess = globalThis;
1578
- if (typeof withProcess.process?.env === "object" && withProcess.process.env !== null) {
1579
- return withProcess.process.env;
1581
+ // src/context.ts
1582
+ var normalizeInitInput = (input) => {
1583
+ if (typeof input === "string") {
1584
+ return { apiKey: input };
1580
1585
  }
1581
- return {};
1582
- };
1583
- var resolveValueFromEnv = (env, keys) => {
1584
- for (const key of keys) {
1585
- const value = readTrimmedString2(env[key]);
1586
- if (value.length > 0) {
1587
- return value;
1588
- }
1586
+ if (input === null || input === void 0) {
1587
+ return {};
1589
1588
  }
1590
- return "";
1589
+ return input;
1591
1590
  };
1592
- var toMissingMessage = (details) => {
1593
- const parts = [];
1594
- if (details.missingApiKey) {
1595
- parts.push(`apiKey (searched: ${details.searchedApiKeyEnvKeys.join(", ") || "none"})`);
1591
+ var resolveClient = (input) => {
1592
+ if (input instanceof AnalyticsClient) {
1593
+ return input;
1596
1594
  }
1597
- return `[analyticscli-sdk] Missing required configuration: ${parts.join("; ")}.`;
1595
+ return new AnalyticsClient(normalizeInitInput(input ?? {}));
1598
1596
  };
1599
- var initFromEnv = (options = {}) => {
1600
- const {
1601
- env,
1602
- apiKey,
1603
- apiKeyEnvKeys,
1604
- missingConfigMode = "noop",
1605
- onMissingConfig,
1606
- ...clientOptions
1607
- } = options;
1608
- const resolvedApiKeyEnvKeys = [...apiKeyEnvKeys ?? DEFAULT_API_KEY_ENV_KEYS];
1609
- const envSource = env ?? resolveDefaultEnv();
1610
- const resolvedApiKey = readTrimmedString2(apiKey) || resolveValueFromEnv(envSource, resolvedApiKeyEnvKeys);
1611
- const missingConfig = {
1612
- missingApiKey: resolvedApiKey.length === 0,
1613
- searchedApiKeyEnvKeys: resolvedApiKeyEnvKeys
1597
+ var createAnalyticsContext = (options = {}) => {
1598
+ const client = resolveClient(options.client);
1599
+ let onboardingTracker = client.createOnboardingTracker(options.onboarding ?? {});
1600
+ let paywallTracker = options.paywall ? client.createPaywallTracker(options.paywall) : null;
1601
+ const consent = {
1602
+ get: () => client.getConsent(),
1603
+ getState: () => client.getConsentState(),
1604
+ set: (granted, setOptions) => client.setConsent(granted, setOptions),
1605
+ optIn: (setOptions) => client.optIn(setOptions),
1606
+ optOut: (setOptions) => client.optOut(setOptions),
1607
+ setFullTracking: (granted, setOptions) => client.setFullTrackingConsent(granted, setOptions),
1608
+ optInFullTracking: (setOptions) => client.optInFullTracking(setOptions),
1609
+ optOutFullTracking: (setOptions) => client.optOutFullTracking(setOptions),
1610
+ isFullTrackingEnabled: () => client.isFullTrackingEnabled()
1611
+ };
1612
+ const user = {
1613
+ identify: (userId, traits) => client.identify(userId, traits),
1614
+ set: (userId, traits) => client.setUser(userId, traits),
1615
+ clear: () => client.clearUser()
1616
+ };
1617
+ return {
1618
+ client,
1619
+ get onboarding() {
1620
+ return onboardingTracker;
1621
+ },
1622
+ get paywall() {
1623
+ return paywallTracker;
1624
+ },
1625
+ consent,
1626
+ user,
1627
+ track: (eventName, properties) => client.track(eventName, properties),
1628
+ trackOnboardingEvent: (eventName, properties) => client.trackOnboardingEvent(eventName, properties),
1629
+ trackOnboardingSurveyResponse: (input, eventName) => client.trackOnboardingSurveyResponse(input, eventName),
1630
+ trackPaywallEvent: (eventName, properties) => client.trackPaywallEvent(eventName, properties),
1631
+ screen: (name, properties) => client.screen(name, properties),
1632
+ page: (name, properties) => client.page(name, properties),
1633
+ feedback: (message, rating, properties) => client.feedback(message, rating, properties),
1634
+ setContext: (context) => client.setContext(context),
1635
+ createOnboarding: (defaults) => client.createOnboardingTracker(defaults),
1636
+ createPaywall: (defaults) => client.createPaywallTracker(defaults),
1637
+ configureOnboarding: (defaults) => {
1638
+ onboardingTracker = client.createOnboardingTracker(defaults);
1639
+ return onboardingTracker;
1640
+ },
1641
+ configurePaywall: (defaults) => {
1642
+ paywallTracker = client.createPaywallTracker(defaults);
1643
+ return paywallTracker;
1644
+ },
1645
+ ready: () => client.ready(),
1646
+ flush: () => client.flush(),
1647
+ shutdown: () => client.shutdown()
1614
1648
  };
1615
- if (missingConfig.missingApiKey) {
1616
- onMissingConfig?.(missingConfig);
1617
- if (missingConfigMode === "throw") {
1618
- throw new Error(toMissingMessage(missingConfig));
1619
- }
1620
- }
1621
- return new AnalyticsClient({
1622
- ...clientOptions,
1623
- apiKey: resolvedApiKey
1624
- });
1625
1649
  };
1626
1650
 
1627
1651
  // src/index.ts
1628
- var normalizeInitInput = (input) => {
1652
+ var normalizeInitInput2 = (input) => {
1629
1653
  if (typeof input === "string") {
1630
1654
  return { apiKey: input };
1631
1655
  }
@@ -1635,17 +1659,17 @@ var normalizeInitInput = (input) => {
1635
1659
  return input;
1636
1660
  };
1637
1661
  var init = (input = {}) => {
1638
- return new AnalyticsClient(normalizeInitInput(input));
1662
+ return new AnalyticsClient(normalizeInitInput2(input));
1639
1663
  };
1640
1664
  var initConsentFirst = (input = {}) => {
1641
- const normalized = normalizeInitInput(input);
1665
+ const normalized = normalizeInitInput2(input);
1642
1666
  return new AnalyticsClient({
1643
1667
  ...normalized,
1644
1668
  initialConsentGranted: false
1645
1669
  });
1646
1670
  };
1647
1671
  var initAsync = async (input = {}) => {
1648
- const client = new AnalyticsClient(normalizeInitInput(input));
1672
+ const client = new AnalyticsClient(normalizeInitInput2(input));
1649
1673
  await client.ready();
1650
1674
  return client;
1651
1675
  };
@@ -1654,31 +1678,6 @@ var initConsentFirstAsync = async (input = {}) => {
1654
1678
  await client.ready();
1655
1679
  return client;
1656
1680
  };
1657
- var BROWSER_API_KEY_ENV_KEYS = [
1658
- "ANALYTICSCLI_PUBLISHABLE_API_KEY",
1659
- "NEXT_PUBLIC_ANALYTICSCLI_PUBLISHABLE_API_KEY",
1660
- "PUBLIC_ANALYTICSCLI_PUBLISHABLE_API_KEY",
1661
- "VITE_ANALYTICSCLI_PUBLISHABLE_API_KEY",
1662
- "EXPO_PUBLIC_ANALYTICSCLI_PUBLISHABLE_API_KEY"
1663
- ];
1664
- var REACT_NATIVE_API_KEY_ENV_KEYS = [
1665
- "ANALYTICSCLI_PUBLISHABLE_API_KEY",
1666
- "EXPO_PUBLIC_ANALYTICSCLI_PUBLISHABLE_API_KEY"
1667
- ];
1668
- var initBrowserFromEnv = (options = {}) => {
1669
- const { apiKeyEnvKeys, ...rest } = options;
1670
- return initFromEnv({
1671
- ...rest,
1672
- apiKeyEnvKeys: [...apiKeyEnvKeys ?? BROWSER_API_KEY_ENV_KEYS]
1673
- });
1674
- };
1675
- var initReactNativeFromEnv = (options = {}) => {
1676
- const { apiKeyEnvKeys, ...rest } = options;
1677
- return initFromEnv({
1678
- ...rest,
1679
- apiKeyEnvKeys: [...apiKeyEnvKeys ?? REACT_NATIVE_API_KEY_ENV_KEYS]
1680
- });
1681
- };
1682
1681
 
1683
1682
  export {
1684
1683
  ONBOARDING_EVENTS,
@@ -1692,14 +1691,9 @@ export {
1692
1691
  PAYWALL_SKIP_EVENT_CANDIDATES,
1693
1692
  PURCHASE_SUCCESS_EVENT_CANDIDATES,
1694
1693
  AnalyticsClient,
1695
- DEFAULT_API_KEY_ENV_KEYS,
1696
- initFromEnv,
1694
+ createAnalyticsContext,
1697
1695
  init,
1698
1696
  initConsentFirst,
1699
1697
  initAsync,
1700
- initConsentFirstAsync,
1701
- BROWSER_API_KEY_ENV_KEYS,
1702
- REACT_NATIVE_API_KEY_ENV_KEYS,
1703
- initBrowserFromEnv,
1704
- initReactNativeFromEnv
1698
+ initConsentFirstAsync
1705
1699
  };
package/dist/index.cjs CHANGED
@@ -21,8 +21,6 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
23
  AnalyticsClient: () => AnalyticsClient,
24
- BROWSER_API_KEY_ENV_KEYS: () => BROWSER_API_KEY_ENV_KEYS,
25
- DEFAULT_API_KEY_ENV_KEYS: () => DEFAULT_API_KEY_ENV_KEYS,
26
24
  ONBOARDING_EVENTS: () => ONBOARDING_EVENTS,
27
25
  ONBOARDING_PROGRESS_EVENT_ORDER: () => ONBOARDING_PROGRESS_EVENT_ORDER,
28
26
  ONBOARDING_SCREEN_EVENT_PREFIXES: () => ONBOARDING_SCREEN_EVENT_PREFIXES,
@@ -33,14 +31,11 @@ __export(index_exports, {
33
31
  PAYWALL_SKIP_EVENT_CANDIDATES: () => PAYWALL_SKIP_EVENT_CANDIDATES,
34
32
  PURCHASE_EVENTS: () => PURCHASE_EVENTS,
35
33
  PURCHASE_SUCCESS_EVENT_CANDIDATES: () => PURCHASE_SUCCESS_EVENT_CANDIDATES,
36
- REACT_NATIVE_API_KEY_ENV_KEYS: () => REACT_NATIVE_API_KEY_ENV_KEYS,
34
+ createAnalyticsContext: () => createAnalyticsContext,
37
35
  init: () => init,
38
36
  initAsync: () => initAsync,
39
- initBrowserFromEnv: () => initBrowserFromEnv,
40
37
  initConsentFirst: () => initConsentFirst,
41
- initConsentFirstAsync: () => initConsentFirstAsync,
42
- initFromEnv: () => initFromEnv,
43
- initReactNativeFromEnv: () => initReactNativeFromEnv
38
+ initConsentFirstAsync: () => initConsentFirstAsync
44
39
  });
45
40
  module.exports = __toCommonJS(index_exports);
46
41
 
@@ -242,7 +237,28 @@ var randomId = () => {
242
237
  if (globalThis.crypto?.randomUUID) {
243
238
  return globalThis.crypto.randomUUID();
244
239
  }
245
- return `${Date.now()}-${Math.random().toString(16).slice(2, 12)}`;
240
+ const bytes = new Uint8Array(16);
241
+ if (globalThis.crypto?.getRandomValues) {
242
+ globalThis.crypto.getRandomValues(bytes);
243
+ } else {
244
+ for (let index = 0; index < bytes.length; index += 1) {
245
+ bytes[index] = Math.floor(Math.random() * 256);
246
+ }
247
+ }
248
+ const byte6 = bytes[6] ?? 0;
249
+ const byte8 = bytes[8] ?? 0;
250
+ bytes[6] = byte6 & 15 | 64;
251
+ bytes[8] = byte8 & 63 | 128;
252
+ let output = "";
253
+ for (let index = 0; index < bytes.length; index += 1) {
254
+ const byte = bytes[index] ?? 0;
255
+ const hex = byte.toString(16).padStart(2, "0");
256
+ output += hex;
257
+ if (index === 3 || index === 5 || index === 7 || index === 9) {
258
+ output += "-";
259
+ }
260
+ }
261
+ return output;
246
262
  };
247
263
  var readStorageSync = (storage, key) => {
248
264
  if (!storage) {
@@ -1603,75 +1619,78 @@ var AnalyticsClient = class {
1603
1619
  }
1604
1620
  };
1605
1621
 
1606
- // src/bootstrap.ts
1607
- var DEFAULT_API_KEY_ENV_KEYS = [
1608
- "ANALYTICSCLI_PUBLISHABLE_API_KEY",
1609
- "NEXT_PUBLIC_ANALYTICSCLI_PUBLISHABLE_API_KEY",
1610
- "EXPO_PUBLIC_ANALYTICSCLI_PUBLISHABLE_API_KEY",
1611
- "VITE_ANALYTICSCLI_PUBLISHABLE_API_KEY"
1612
- ];
1613
- var readTrimmedString2 = (value) => {
1614
- if (typeof value === "string") {
1615
- return value.trim();
1616
- }
1617
- if (typeof value === "number" || typeof value === "boolean") {
1618
- return String(value).trim();
1619
- }
1620
- return "";
1621
- };
1622
- var resolveDefaultEnv = () => {
1623
- const withProcess = globalThis;
1624
- if (typeof withProcess.process?.env === "object" && withProcess.process.env !== null) {
1625
- return withProcess.process.env;
1622
+ // src/context.ts
1623
+ var normalizeInitInput = (input) => {
1624
+ if (typeof input === "string") {
1625
+ return { apiKey: input };
1626
1626
  }
1627
- return {};
1628
- };
1629
- var resolveValueFromEnv = (env, keys) => {
1630
- for (const key of keys) {
1631
- const value = readTrimmedString2(env[key]);
1632
- if (value.length > 0) {
1633
- return value;
1634
- }
1627
+ if (input === null || input === void 0) {
1628
+ return {};
1635
1629
  }
1636
- return "";
1630
+ return input;
1637
1631
  };
1638
- var toMissingMessage = (details) => {
1639
- const parts = [];
1640
- if (details.missingApiKey) {
1641
- parts.push(`apiKey (searched: ${details.searchedApiKeyEnvKeys.join(", ") || "none"})`);
1632
+ var resolveClient = (input) => {
1633
+ if (input instanceof AnalyticsClient) {
1634
+ return input;
1642
1635
  }
1643
- return `[analyticscli-sdk] Missing required configuration: ${parts.join("; ")}.`;
1636
+ return new AnalyticsClient(normalizeInitInput(input ?? {}));
1644
1637
  };
1645
- var initFromEnv = (options = {}) => {
1646
- const {
1647
- env,
1648
- apiKey,
1649
- apiKeyEnvKeys,
1650
- missingConfigMode = "noop",
1651
- onMissingConfig,
1652
- ...clientOptions
1653
- } = options;
1654
- const resolvedApiKeyEnvKeys = [...apiKeyEnvKeys ?? DEFAULT_API_KEY_ENV_KEYS];
1655
- const envSource = env ?? resolveDefaultEnv();
1656
- const resolvedApiKey = readTrimmedString2(apiKey) || resolveValueFromEnv(envSource, resolvedApiKeyEnvKeys);
1657
- const missingConfig = {
1658
- missingApiKey: resolvedApiKey.length === 0,
1659
- searchedApiKeyEnvKeys: resolvedApiKeyEnvKeys
1638
+ var createAnalyticsContext = (options = {}) => {
1639
+ const client = resolveClient(options.client);
1640
+ let onboardingTracker = client.createOnboardingTracker(options.onboarding ?? {});
1641
+ let paywallTracker = options.paywall ? client.createPaywallTracker(options.paywall) : null;
1642
+ const consent = {
1643
+ get: () => client.getConsent(),
1644
+ getState: () => client.getConsentState(),
1645
+ set: (granted, setOptions) => client.setConsent(granted, setOptions),
1646
+ optIn: (setOptions) => client.optIn(setOptions),
1647
+ optOut: (setOptions) => client.optOut(setOptions),
1648
+ setFullTracking: (granted, setOptions) => client.setFullTrackingConsent(granted, setOptions),
1649
+ optInFullTracking: (setOptions) => client.optInFullTracking(setOptions),
1650
+ optOutFullTracking: (setOptions) => client.optOutFullTracking(setOptions),
1651
+ isFullTrackingEnabled: () => client.isFullTrackingEnabled()
1652
+ };
1653
+ const user = {
1654
+ identify: (userId, traits) => client.identify(userId, traits),
1655
+ set: (userId, traits) => client.setUser(userId, traits),
1656
+ clear: () => client.clearUser()
1657
+ };
1658
+ return {
1659
+ client,
1660
+ get onboarding() {
1661
+ return onboardingTracker;
1662
+ },
1663
+ get paywall() {
1664
+ return paywallTracker;
1665
+ },
1666
+ consent,
1667
+ user,
1668
+ track: (eventName, properties) => client.track(eventName, properties),
1669
+ trackOnboardingEvent: (eventName, properties) => client.trackOnboardingEvent(eventName, properties),
1670
+ trackOnboardingSurveyResponse: (input, eventName) => client.trackOnboardingSurveyResponse(input, eventName),
1671
+ trackPaywallEvent: (eventName, properties) => client.trackPaywallEvent(eventName, properties),
1672
+ screen: (name, properties) => client.screen(name, properties),
1673
+ page: (name, properties) => client.page(name, properties),
1674
+ feedback: (message, rating, properties) => client.feedback(message, rating, properties),
1675
+ setContext: (context) => client.setContext(context),
1676
+ createOnboarding: (defaults) => client.createOnboardingTracker(defaults),
1677
+ createPaywall: (defaults) => client.createPaywallTracker(defaults),
1678
+ configureOnboarding: (defaults) => {
1679
+ onboardingTracker = client.createOnboardingTracker(defaults);
1680
+ return onboardingTracker;
1681
+ },
1682
+ configurePaywall: (defaults) => {
1683
+ paywallTracker = client.createPaywallTracker(defaults);
1684
+ return paywallTracker;
1685
+ },
1686
+ ready: () => client.ready(),
1687
+ flush: () => client.flush(),
1688
+ shutdown: () => client.shutdown()
1660
1689
  };
1661
- if (missingConfig.missingApiKey) {
1662
- onMissingConfig?.(missingConfig);
1663
- if (missingConfigMode === "throw") {
1664
- throw new Error(toMissingMessage(missingConfig));
1665
- }
1666
- }
1667
- return new AnalyticsClient({
1668
- ...clientOptions,
1669
- apiKey: resolvedApiKey
1670
- });
1671
1690
  };
1672
1691
 
1673
1692
  // src/index.ts
1674
- var normalizeInitInput = (input) => {
1693
+ var normalizeInitInput2 = (input) => {
1675
1694
  if (typeof input === "string") {
1676
1695
  return { apiKey: input };
1677
1696
  }
@@ -1681,17 +1700,17 @@ var normalizeInitInput = (input) => {
1681
1700
  return input;
1682
1701
  };
1683
1702
  var init = (input = {}) => {
1684
- return new AnalyticsClient(normalizeInitInput(input));
1703
+ return new AnalyticsClient(normalizeInitInput2(input));
1685
1704
  };
1686
1705
  var initConsentFirst = (input = {}) => {
1687
- const normalized = normalizeInitInput(input);
1706
+ const normalized = normalizeInitInput2(input);
1688
1707
  return new AnalyticsClient({
1689
1708
  ...normalized,
1690
1709
  initialConsentGranted: false
1691
1710
  });
1692
1711
  };
1693
1712
  var initAsync = async (input = {}) => {
1694
- const client = new AnalyticsClient(normalizeInitInput(input));
1713
+ const client = new AnalyticsClient(normalizeInitInput2(input));
1695
1714
  await client.ready();
1696
1715
  return client;
1697
1716
  };
@@ -1700,36 +1719,9 @@ var initConsentFirstAsync = async (input = {}) => {
1700
1719
  await client.ready();
1701
1720
  return client;
1702
1721
  };
1703
- var BROWSER_API_KEY_ENV_KEYS = [
1704
- "ANALYTICSCLI_PUBLISHABLE_API_KEY",
1705
- "NEXT_PUBLIC_ANALYTICSCLI_PUBLISHABLE_API_KEY",
1706
- "PUBLIC_ANALYTICSCLI_PUBLISHABLE_API_KEY",
1707
- "VITE_ANALYTICSCLI_PUBLISHABLE_API_KEY",
1708
- "EXPO_PUBLIC_ANALYTICSCLI_PUBLISHABLE_API_KEY"
1709
- ];
1710
- var REACT_NATIVE_API_KEY_ENV_KEYS = [
1711
- "ANALYTICSCLI_PUBLISHABLE_API_KEY",
1712
- "EXPO_PUBLIC_ANALYTICSCLI_PUBLISHABLE_API_KEY"
1713
- ];
1714
- var initBrowserFromEnv = (options = {}) => {
1715
- const { apiKeyEnvKeys, ...rest } = options;
1716
- return initFromEnv({
1717
- ...rest,
1718
- apiKeyEnvKeys: [...apiKeyEnvKeys ?? BROWSER_API_KEY_ENV_KEYS]
1719
- });
1720
- };
1721
- var initReactNativeFromEnv = (options = {}) => {
1722
- const { apiKeyEnvKeys, ...rest } = options;
1723
- return initFromEnv({
1724
- ...rest,
1725
- apiKeyEnvKeys: [...apiKeyEnvKeys ?? REACT_NATIVE_API_KEY_ENV_KEYS]
1726
- });
1727
- };
1728
1722
  // Annotate the CommonJS export names for ESM import in node:
1729
1723
  0 && (module.exports = {
1730
1724
  AnalyticsClient,
1731
- BROWSER_API_KEY_ENV_KEYS,
1732
- DEFAULT_API_KEY_ENV_KEYS,
1733
1725
  ONBOARDING_EVENTS,
1734
1726
  ONBOARDING_PROGRESS_EVENT_ORDER,
1735
1727
  ONBOARDING_SCREEN_EVENT_PREFIXES,
@@ -1740,12 +1732,9 @@ var initReactNativeFromEnv = (options = {}) => {
1740
1732
  PAYWALL_SKIP_EVENT_CANDIDATES,
1741
1733
  PURCHASE_EVENTS,
1742
1734
  PURCHASE_SUCCESS_EVENT_CANDIDATES,
1743
- REACT_NATIVE_API_KEY_ENV_KEYS,
1735
+ createAnalyticsContext,
1744
1736
  init,
1745
1737
  initAsync,
1746
- initBrowserFromEnv,
1747
1738
  initConsentFirst,
1748
- initConsentFirstAsync,
1749
- initFromEnv,
1750
- initReactNativeFromEnv
1739
+ initConsentFirstAsync
1751
1740
  });
package/dist/index.d.cts CHANGED
@@ -236,36 +236,6 @@ type AnalyticsClientOptions = {
236
236
  useCookieStorage?: boolean | null;
237
237
  };
238
238
  type InitOptions = AnalyticsClientOptions;
239
- type InitFromEnvMissingConfigMode = 'noop' | 'throw';
240
- type InitFromEnvMissingConfig = {
241
- missingApiKey: boolean;
242
- searchedApiKeyEnvKeys: string[];
243
- };
244
- type InitFromEnvOptions = Omit<AnalyticsClientOptions, 'apiKey'> & {
245
- /**
246
- * Optional environment-like object.
247
- * Defaults to `globalThis.process?.env` when available.
248
- */
249
- env?: Record<string, unknown> | null;
250
- /**
251
- * Explicit api key override.
252
- */
253
- apiKey?: string | null;
254
- /**
255
- * Candidate env keys resolved in order.
256
- */
257
- apiKeyEnvKeys?: string[] | null;
258
- /**
259
- * How missing config is handled.
260
- * - `noop` (default): returns a safe no-op client
261
- * - `throw`: throws when required config is missing
262
- */
263
- missingConfigMode?: InitFromEnvMissingConfigMode | null;
264
- /**
265
- * Optional callback for custom logging when config is missing.
266
- */
267
- onMissingConfig?: ((details: InitFromEnvMissingConfig) => void) | null;
268
- };
269
239
  type InitInput = InitOptions | string | null | undefined;
270
240
 
271
241
  declare class AnalyticsClient {
@@ -445,12 +415,64 @@ declare class AnalyticsClient {
445
415
  private reportMissingApiKey;
446
416
  }
447
417
 
448
- declare const DEFAULT_API_KEY_ENV_KEYS: readonly ["ANALYTICSCLI_PUBLISHABLE_API_KEY", "NEXT_PUBLIC_ANALYTICSCLI_PUBLISHABLE_API_KEY", "EXPO_PUBLIC_ANALYTICSCLI_PUBLISHABLE_API_KEY", "VITE_ANALYTICSCLI_PUBLISHABLE_API_KEY"];
418
+ type ContextClientInput = InitInput | AnalyticsClient | null | undefined;
419
+ type AnalyticsContextConsentControls = {
420
+ get: () => boolean;
421
+ getState: () => AnalyticsConsentState;
422
+ set: (granted: boolean, options?: SetConsentOptions) => void;
423
+ optIn: (options?: SetConsentOptions) => void;
424
+ optOut: (options?: SetConsentOptions) => void;
425
+ setFullTracking: (granted: boolean, options?: SetConsentOptions) => void;
426
+ optInFullTracking: (options?: SetConsentOptions) => void;
427
+ optOutFullTracking: (options?: SetConsentOptions) => void;
428
+ isFullTrackingEnabled: () => boolean;
429
+ };
430
+ type AnalyticsContextUserControls = {
431
+ identify: (userId: string, traits?: EventProperties) => void;
432
+ set: (userId: string | null | undefined, traits?: EventProperties) => void;
433
+ clear: () => void;
434
+ };
435
+ type AnalyticsContext = {
436
+ client: AnalyticsClient;
437
+ onboarding: OnboardingTracker;
438
+ paywall: PaywallTracker | null;
439
+ consent: AnalyticsContextConsentControls;
440
+ user: AnalyticsContextUserControls;
441
+ track: (eventName: string, properties?: EventProperties) => void;
442
+ trackOnboardingEvent: (eventName: OnboardingEventName, properties?: OnboardingEventProperties) => void;
443
+ trackOnboardingSurveyResponse: (input: OnboardingSurveyResponseInput, eventName?: OnboardingSurveyEventName) => void;
444
+ trackPaywallEvent: (eventName: PaywallJourneyEventName, properties: PaywallEventProperties) => void;
445
+ screen: (name: string, properties?: EventProperties) => void;
446
+ page: (name: string, properties?: EventProperties) => void;
447
+ feedback: (message: string, rating?: number, properties?: EventProperties) => void;
448
+ setContext: (context: EventContext) => void;
449
+ createOnboarding: (defaults: OnboardingTrackerDefaults) => OnboardingTracker;
450
+ createPaywall: (defaults: PaywallTrackerDefaults) => PaywallTracker;
451
+ configureOnboarding: (defaults: OnboardingTrackerDefaults) => OnboardingTracker;
452
+ configurePaywall: (defaults: PaywallTrackerDefaults) => PaywallTracker;
453
+ ready: () => Promise<void>;
454
+ flush: () => Promise<void>;
455
+ shutdown: () => void;
456
+ };
457
+ type CreateAnalyticsContextOptions = {
458
+ /**
459
+ * Either an existing client instance or standard `init(...)` input.
460
+ */
461
+ client?: ContextClientInput;
462
+ /**
463
+ * Defaults used for the exported `context.onboarding` tracker instance.
464
+ */
465
+ onboarding?: OnboardingTrackerDefaults | null;
466
+ /**
467
+ * Optional defaults used for the exported `context.paywall` tracker instance.
468
+ */
469
+ paywall?: PaywallTrackerDefaults | null;
470
+ };
449
471
  /**
450
- * Minimal host-app bootstrap helper.
451
- * Resolves `apiKey` (required) from explicit options or env-like objects.
472
+ * Host-app friendly SDK context with low boilerplate and rich defaults.
473
+ * Provides pre-wired onboarding + consent/user controls and optional paywall tracker binding.
452
474
  */
453
- declare const initFromEnv: (options?: InitFromEnvOptions) => AnalyticsClient;
475
+ declare const createAnalyticsContext: (options?: CreateAnalyticsContextOptions) => AnalyticsContext;
454
476
 
455
477
  /**
456
478
  * Creates a browser analytics client instance.
@@ -466,23 +488,5 @@ declare const initConsentFirst: (input?: InitInput) => AnalyticsClient;
466
488
  */
467
489
  declare const initAsync: (input?: InitInput) => Promise<AnalyticsClient>;
468
490
  declare const initConsentFirstAsync: (input?: InitInput) => Promise<AnalyticsClient>;
469
- declare const BROWSER_API_KEY_ENV_KEYS: readonly ["ANALYTICSCLI_PUBLISHABLE_API_KEY", "NEXT_PUBLIC_ANALYTICSCLI_PUBLISHABLE_API_KEY", "PUBLIC_ANALYTICSCLI_PUBLISHABLE_API_KEY", "VITE_ANALYTICSCLI_PUBLISHABLE_API_KEY", "EXPO_PUBLIC_ANALYTICSCLI_PUBLISHABLE_API_KEY"];
470
- declare const REACT_NATIVE_API_KEY_ENV_KEYS: readonly ["ANALYTICSCLI_PUBLISHABLE_API_KEY", "EXPO_PUBLIC_ANALYTICSCLI_PUBLISHABLE_API_KEY"];
471
- type BrowserInitFromEnvOptions = Omit<InitFromEnvOptions, 'apiKeyEnvKeys'> & {
472
- apiKeyEnvKeys?: readonly string[];
473
- };
474
- type ReactNativeInitFromEnvOptions = Omit<InitFromEnvOptions, 'apiKeyEnvKeys'> & {
475
- apiKeyEnvKeys?: readonly string[];
476
- };
477
- /**
478
- * Browser-focused env bootstrap.
479
- * Supports common env prefixes across Next.js, Astro/Vite and Expo web.
480
- */
481
- declare const initBrowserFromEnv: (options?: BrowserInitFromEnvOptions) => AnalyticsClient;
482
- /**
483
- * React Native-focused env bootstrap.
484
- * Defaults to native-friendly env keys while still allowing explicit overrides.
485
- */
486
- declare const initReactNativeFromEnv: (options?: ReactNativeInitFromEnvOptions) => AnalyticsClient;
487
491
 
488
- export { AnalyticsClient, type AnalyticsClientOptions, type AnalyticsConsentState, type AnalyticsStorageAdapter, BROWSER_API_KEY_ENV_KEYS, type BrowserInitFromEnvOptions, DEFAULT_API_KEY_ENV_KEYS, type EventContext, type EventProperties, type IdentityTrackingMode, type InitFromEnvMissingConfig, type InitFromEnvMissingConfigMode, type InitFromEnvOptions, type InitInput, type InitOptions, ONBOARDING_EVENTS, ONBOARDING_PROGRESS_EVENT_ORDER, ONBOARDING_SCREEN_EVENT_PREFIXES, ONBOARDING_SURVEY_EVENTS, type OnboardingEventName, type OnboardingEventProperties, type OnboardingStepTracker, type OnboardingSurveyAnswerType, type OnboardingSurveyEventName, type OnboardingSurveyResponseInput, type OnboardingTracker, type OnboardingTrackerDefaults, type OnboardingTrackerSurveyInput, PAYWALL_ANCHOR_EVENT_CANDIDATES, PAYWALL_EVENTS, PAYWALL_JOURNEY_EVENT_ORDER, PAYWALL_SKIP_EVENT_CANDIDATES, PURCHASE_EVENTS, PURCHASE_SUCCESS_EVENT_CANDIDATES, type PaywallEventName, type PaywallEventProperties, type PaywallJourneyEventName, type PaywallTracker, type PaywallTrackerDefaults, type PaywallTrackerProperties, type PurchaseEventName, REACT_NATIVE_API_KEY_ENV_KEYS, type ReactNativeInitFromEnvOptions, type SetConsentOptions, init, initAsync, initBrowserFromEnv, initConsentFirst, initConsentFirstAsync, initFromEnv, initReactNativeFromEnv };
492
+ export { AnalyticsClient, type AnalyticsClientOptions, type AnalyticsConsentState, type AnalyticsContext, type AnalyticsContextConsentControls, type AnalyticsContextUserControls, type AnalyticsStorageAdapter, type CreateAnalyticsContextOptions, type EventContext, type EventProperties, type IdentityTrackingMode, type InitInput, type InitOptions, ONBOARDING_EVENTS, ONBOARDING_PROGRESS_EVENT_ORDER, ONBOARDING_SCREEN_EVENT_PREFIXES, ONBOARDING_SURVEY_EVENTS, type OnboardingEventName, type OnboardingEventProperties, type OnboardingStepTracker, type OnboardingSurveyAnswerType, type OnboardingSurveyEventName, type OnboardingSurveyResponseInput, type OnboardingTracker, type OnboardingTrackerDefaults, type OnboardingTrackerSurveyInput, PAYWALL_ANCHOR_EVENT_CANDIDATES, PAYWALL_EVENTS, PAYWALL_JOURNEY_EVENT_ORDER, PAYWALL_SKIP_EVENT_CANDIDATES, PURCHASE_EVENTS, PURCHASE_SUCCESS_EVENT_CANDIDATES, type PaywallEventName, type PaywallEventProperties, type PaywallJourneyEventName, type PaywallTracker, type PaywallTrackerDefaults, type PaywallTrackerProperties, type PurchaseEventName, type SetConsentOptions, createAnalyticsContext, init, initAsync, initConsentFirst, initConsentFirstAsync };