@walkeros/web-destination-posthog 3.4.2 → 4.0.0-next-1777882869103
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 +33 -32
- package/dist/dev.d.mts +10 -10
- package/dist/dev.d.ts +10 -10
- package/dist/dev.js +1 -1
- package/dist/dev.js.map +1 -1
- package/dist/dev.mjs +1 -1
- package/dist/dev.mjs.map +1 -1
- package/dist/examples/index.d.mts +10 -10
- package/dist/examples/index.d.ts +10 -10
- package/dist/examples/index.js +31 -26
- package/dist/examples/index.mjs +31 -26
- package/dist/index.browser.js +1 -1
- package/dist/index.es5.js +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/walkerOS.json +37 -149
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var t,e=Object.create,n=Object.defineProperty,o=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,
|
|
1
|
+
"use strict";var t,e=Object.create,n=Object.defineProperty,o=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,c=(t,e,i,c)=>{if(e&&"object"==typeof e||"function"==typeof e)for(let s of r(e))a.call(t,s)||s===i||n(t,s,{get:()=>e[s],enumerable:!(c=o(e,s))||c.enumerable});return t},s={};((t,e)=>{for(var o in e)n(t,o,{get:e[o],enumerable:!0})})(s,{DestinationPostHog:()=>P,default:()=>I,destinationPostHog:()=>k}),module.exports=(t=s,c(n({},"__esModule",{value:!0}),t));var l=Object.defineProperty;((t,e)=>{for(var n in e)l(t,n,{get:e[n],enumerable:!0})})({},{Level:()=>f});var u,f=((u=f||{})[u.ERROR=0]="ERROR",u[u.WARN=1]="WARN",u[u.INFO=2]="INFO",u[u.DEBUG=3]="DEBUG",u);function p(t){return Array.isArray(t)}function d(t){return void 0!==t}function y(t){return"object"==typeof t&&null!==t&&!p(t)&&"[object Object]"===Object.prototype.toString.call(t)}function v(t){return"string"==typeof t}function g(t,e="",n){const o=e.split(".");let r=t;for(let t=0;t<o.length;t++){const e=o[t];if("*"===e&&p(r)){const e=o.slice(t+1).join("."),i=[];for(const t of r){const o=g(t,e,n);i.push(o)}return i}if(r=r instanceof Object?r[e]:void 0,void 0===r)break}return d(r)?r:n}function b(t){return function(t){return"boolean"==typeof t}(t)||v(t)||function(t){return"number"==typeof t&&!Number.isNaN(t)}(t)||!d(t)||p(t)&&t.every(b)||y(t)&&Object.values(t).every(b)}function O(t){return b(t)?t:void 0}function w(t,e,n){return async function(...o){try{return await t(...o)}catch(t){if(!e)return;return await e(t)}finally{await(null==n?void 0:n())}}}async function m(t,e={},n={}){var o,r;if(!d(t))return;const i=y(t)&&t.consent||n.consent||(null==(o=n.collector)?void 0:o.consent),a=null!=(r=n.event)?r:y(t)?t:{};if(!n.collector)throw new Error("getMappingValue: context.collector is required");const c={event:a,mapping:e,collector:n.collector,logger:n.collector.logger,consent:i},s=p(e)?e:[e];for(const e of s){const n=await w(j)(t,e,{...c,mapping:e});if(d(n))return n}}async function j(t,e,n){return(p(e)?e:[e]).reduce(async(e,o)=>{const r=await e;if(r)return r;const i=v(o)?{key:o}:o;if(!Object.keys(i).length)return;const{condition:a,consent:c,fn:s,key:l,loop:u,map:f,set:y,validate:b,value:_}=i,P={...n,mapping:o};if(a&&!await w(a)(t,P))return;if(c&&!function(t,e={},n={}){const o={...e,...n},r={};let i=!t||0===Object.keys(t).length;return Object.keys(o).forEach(e=>{o[e]&&(r[e]=!0,t&&t[e]&&(i=!0))}),!!i&&r}(c,P.consent))return _;let h=d(_)?_:t;if(s&&(h=await w(s)(t,P)),l&&(h=g(t,l,_)),u){const[e,n]=u,o="this"===e?[t]:await m(t,e,P);p(o)&&(h=(await Promise.all(o.map(t=>m(t,n,P)))).filter(d))}else f?h=await Object.entries(f).reduce(async(e,[n,o])=>{const r=await e,i=await m(t,o,P);return d(i)&&(r[n]=i),r},Promise.resolve({})):y&&(h=await Promise.all(y.map(e=>j(t,e,P))));b&&!await w(b)(h,P)&&(h=void 0);const k=O(h);return d(k)?k:O(_)},Promise.resolve(void 0))}var _=((t,o,r)=>(r=null!=t?e(i(t)):{},c(!o&&t&&t.__esModule?r:n(r,"default",{value:t,enumerable:!0}),t)))(require("posthog-js")),P={};function h(t){var e;return null!=(e=null==t?void 0:t.posthog)?e:_.default}var k={type:"posthog",config:{},async init({config:t,env:e}){const n=t.settings;if(!(null==n?void 0:n.apiKey))return!1;const o=h(e),{apiKey:r,identify:i,group:a,_state:c,...s}=n,l={autocapture:!1,capture_pageview:!1,capture_pageleave:!1,...s};let u=!1;o.init(r,{...l,loaded:()=>{u=!0}}),u||await Promise.resolve();return{...t,settings:{...n,_state:{lastIdentity:{},lastGroup:{}}}}},async push(t,{config:e,rule:n,env:o,data:r,collector:i}){var a,c;const s=h(o),l=e.settings||{},u=(null==n?void 0:n.settings)||{},f=l._state||{};if(void 0!==u.reset){("boolean"==typeof u.reset?u.reset:await m(t,u.reset,{collector:i}))&&(s.reset(),f.lastIdentity={},f.lastGroup={})}const p=null!=(a=u.identify)?a:l.identify;if(void 0!==p){const e=await m(t,p,{collector:i});y(e)&&(f.lastIdentity=function(t,e,n={}){const o={...n},r=e.distinctId,i=y(e.$set)?e.$set:void 0,a=y(e.$set_once)?e.$set_once:void 0;return v(r)&&""!==r?(r!==n.distinctId||i||a)&&(t.identify(r,i,a),o.distinctId=r):(i||a)&&t.setPersonProperties(i,a),o}(s,e,f.lastIdentity))}const d=null!=(c=u.group)?c:l.group;if(void 0!==d){const e=await m(t,d,{collector:i});y(e)&&(f.lastGroup=function(t,e,n={}){const o={...n},r=e.type,i=e.key,a=y(e.properties)?e.properties:void 0;return v(r)&&v(i)&&(r!==n.type||i!==n.key||a)&&(t.group(r,i,a),o.type=r,o.key=i),o}(s,e,f.lastGroup))}if(!0!==(null==n?void 0:n.silent)){const e=v(null==n?void 0:n.name)?n.name:t.name,o=y(r)?r:{};s.capture(e,o)}l._state=f},on(t,e){var n;if("consent"!==t||!(null==e?void 0:e.data))return;const o=h(e.env),r=e.data,i=null==(n=e.config)?void 0:n.consent;if(!i||0===Object.keys(i).length)return;Object.keys(i).every(t=>!0===r[t])?o.opt_in_capturing():o.opt_out_capturing()}},I=k;//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/types/index.ts"],"sourcesContent":["import type { WalkerOS } from '@walkeros/core';\nimport { getMappingValue, isObject, isString } from '@walkeros/core';\nimport posthogSDK from 'posthog-js';\nimport type {\n Destination,\n Env,\n PostHogSDK,\n RuntimeState,\n Settings,\n} from './types';\n\n// Types export\nexport * as DestinationPostHog from './types';\n\n/**\n * Resolve the PostHog SDK: use the caller-provided mock when available\n * (tests), otherwise fall back to the real `posthog-js` default export.\n * Matches @walkeros/web-destination-clarity and\n * @walkeros/server-destination-gcp (BigQuery).\n */\nfunction getPostHog(env: Env | undefined): PostHogSDK {\n return env?.posthog ?? (posthogSDK as unknown as PostHogSDK);\n}\n\n/**\n * Resolve the identify mapping value, call the right SDK method.\n *\n * - If `distinctId` is present and has changed since last push (or props present):\n * posthog.identify(distinctId, $set?, $set_once?)\n * - If `distinctId` is absent but $set/$set_once exist:\n * posthog.setPersonProperties($set, $set_once)\n * - If nothing resolves or distinctId unchanged and no props: no-op\n *\n * Returns the updated lastIdentity snapshot.\n */\nfunction applyIdentity(\n posthog: PostHogSDK,\n resolved: Record<string, unknown>,\n lastIdentity: RuntimeState['lastIdentity'] = {},\n): NonNullable<RuntimeState['lastIdentity']> {\n const updated = { ...lastIdentity };\n\n const distinctId = resolved.distinctId;\n const $set = isObject(resolved.$set)\n ? (resolved.$set as Record<string, unknown>)\n : undefined;\n const $setOnce = isObject(resolved.$set_once)\n ? (resolved.$set_once as Record<string, unknown>)\n : undefined;\n\n if (isString(distinctId) && distinctId !== '') {\n if (distinctId !== lastIdentity.distinctId || $set || $setOnce) {\n posthog.identify(distinctId, $set, $setOnce);\n updated.distinctId = distinctId;\n }\n } else if ($set || $setOnce) {\n posthog.setPersonProperties($set, $setOnce);\n }\n\n return updated;\n}\n\n/**\n * Resolve the group mapping value, call posthog.group(type, key, properties?).\n * Like identity, group changes are tracked in runtime state and only re-fired\n * when type or key changes.\n */\nfunction applyGroup(\n posthog: PostHogSDK,\n resolved: Record<string, unknown>,\n lastGroup: RuntimeState['lastGroup'] = {},\n): NonNullable<RuntimeState['lastGroup']> {\n const updated = { ...lastGroup };\n const type = resolved.type;\n const key = resolved.key;\n const properties = isObject(resolved.properties)\n ? (resolved.properties as Record<string, unknown>)\n : undefined;\n\n if (isString(type) && isString(key)) {\n if (type !== lastGroup.type || key !== lastGroup.key || properties) {\n posthog.group(type, key, properties);\n updated.type = type;\n updated.key = key;\n }\n }\n\n return updated;\n}\n\nexport const destinationPostHog: Destination = {\n type: 'posthog',\n\n config: {},\n\n async init({ config, env }) {\n const settings = config.settings;\n if (!settings?.apiKey) return false;\n\n const posthog = getPostHog(env as Env | undefined);\n\n const {\n apiKey,\n identify: _identify,\n group: _group,\n _state: _existingState,\n ...posthogOptions\n } = settings;\n\n // walkerOS defaults that override PostHog defaults: walkerOS sources\n // handle event capture, so turn off PostHog's own.\n const options = {\n autocapture: false,\n capture_pageview: false,\n capture_pageleave: false,\n ...posthogOptions,\n };\n\n // posthog.init() is synchronous and returns the singleton. It supports\n // an optional `loaded` callback for post-bootstrap hooks (feature flags\n // fetched, etc). We wait up to one microtask for it to fire so the\n // destination is truly ready before returning; otherwise we resolve\n // immediately so tests with no-op mocks don't hang.\n let loadedFired = false;\n posthog.init(apiKey, {\n ...options,\n loaded: () => {\n loadedFired = true;\n },\n });\n if (!loadedFired) {\n await Promise.resolve();\n }\n\n const _state: RuntimeState = { lastIdentity: {}, lastGroup: {} };\n return { ...config, settings: { ...settings, _state } };\n },\n\n async push(event, { config, rule, env, data, collector }) {\n const posthog = getPostHog(env as Env | undefined);\n const settings = (config.settings || {}) as Settings;\n const mappingSettings = rule?.settings || {};\n const state: RuntimeState = settings._state || {};\n\n // 1. Reset — fires first so subsequent identity calls start clean.\n if (mappingSettings.reset !== undefined) {\n const resolved =\n typeof mappingSettings.reset === 'boolean'\n ? mappingSettings.reset\n : await getMappingValue(event, mappingSettings.reset, {\n collector,\n });\n if (resolved) {\n posthog.reset();\n state.lastIdentity = {};\n state.lastGroup = {};\n }\n }\n\n // 2. Identity — rule-level override wins over destination-level.\n const identifyMapping = mappingSettings.identify ?? settings.identify;\n if (identifyMapping !== undefined) {\n const resolved = await getMappingValue(event, identifyMapping, {\n collector,\n });\n if (isObject(resolved)) {\n state.lastIdentity = applyIdentity(\n posthog,\n resolved as Record<string, unknown>,\n state.lastIdentity,\n );\n }\n }\n\n // 3. Group — rule-level override wins over destination-level.\n const groupMapping = mappingSettings.group ?? settings.group;\n if (groupMapping !== undefined) {\n const resolved = await getMappingValue(event, groupMapping, {\n collector,\n });\n if (isObject(resolved)) {\n state.lastGroup = applyGroup(\n posthog,\n resolved as Record<string, unknown>,\n state.lastGroup,\n );\n }\n }\n\n // 4. Default capture — unless rule opts out via skip.\n if (rule?.skip !== true) {\n const eventName = isString(rule?.name) ? rule.name : event.name;\n const properties = isObject(data)\n ? (data as Record<string, unknown>)\n : {};\n posthog.capture(eventName, properties);\n }\n\n // Persist state. walkerOS destinations are long-lived singletons so\n // mutating settings in place is safe (Snowplow precedent).\n settings._state = state;\n },\n\n on(type, context) {\n if (type !== 'consent' || !context?.data) return;\n const posthog = getPostHog(context.env as Env | undefined);\n\n const consent = context.data as WalkerOS.Consent;\n // Derive required consent keys from config.consent. If all declared\n // keys are granted, opt IN; otherwise opt OUT. Missing config.consent\n // means nothing to check and we take no action.\n const required = (context.config as { consent?: WalkerOS.Consent })\n ?.consent;\n if (!required || Object.keys(required).length === 0) return;\n\n const allGranted = Object.keys(required).every(\n (key) => consent[key] === true,\n );\n if (allGranted) {\n posthog.opt_in_capturing();\n } else {\n posthog.opt_out_capturing();\n }\n },\n};\n\nexport default destinationPostHog;\n","import type {\n Mapping as WalkerOSMapping,\n Destination as CoreDestination,\n} from '@walkeros/core';\nimport type { DestinationWeb } from '@walkeros/web-core';\n// Import SDK types directly — never duplicate. Verified against posthog-js@1.367.0.\nimport type { PostHogConfig, Properties } from 'posthog-js';\n\n/**\n * Destination-level settings.\n *\n * PostHog's `PostHogConfig` interface has ~80 fields — extending the SDK type\n * directly keeps IntelliSense complete and prevents drift. The destination adds:\n * - `apiKey` (required) — first arg to `posthog.init(...)`, NOT an init option\n * - `identify` — destination-level identity mapping\n * - `include` — event sections flattened into `capture()` properties\n * - `group` — destination-level group association\n * - `_state` — runtime state (not user-facing, mutated by init/push)\n *\n * All other walkerOS-specific mapping features live under mapping.settings\n * (see Mapping interface below). Built-in PostHog features (session_recording,\n * advanced_disable_flags, disable_surveys, capture_heatmaps, capture_exceptions,\n * bootstrap, cookieless_mode, ...) are passthrough via PostHogConfig.\n */\nexport interface Settings extends Partial<PostHogConfig> {\n /** PostHog project API key (e.g. \"phc_XXX\"). First arg to posthog.init(). */\n apiKey: string;\n /** Destination-level identity mapping, resolved on first push. */\n identify?: WalkerOSMapping.Value;\n /** Destination-level group association, resolved on first push. */\n group?: WalkerOSMapping.Value;\n /** Runtime state — populated by init() and mutated by push(). Not user-facing. */\n _state?: RuntimeState;\n}\n\nexport interface RuntimeState {\n /** Last-resolved identity values, used to skip redundant identify/group calls. */\n lastIdentity?: {\n distinctId?: string;\n };\n lastGroup?: {\n type?: string;\n key?: string;\n };\n}\n\nexport type InitSettings = Partial<Settings>;\n\n/**\n * Per-rule mapping settings. Every feature here is a walkerOS mapping value\n * resolved via getMappingValue(). The resolved object's keys drive which\n * SDK methods are called.\n *\n * - identify: { distinctId?, $set?, $set_once? } → posthog.identify() OR posthog.setPersonProperties()\n * - group: { type, key, properties? } → posthog.group()\n * - reset: boolean → posthog.reset()\n * - include: string[] → flattened properties (overrides destination-level)\n */\nexport interface Mapping {\n identify?: WalkerOSMapping.Value;\n group?: WalkerOSMapping.Value;\n reset?: WalkerOSMapping.Value | boolean;\n}\n\n/**\n * PostHog SDK surface — the subset of `posthog-js` the destination actually\n * uses. Mirrors the real module's default singleton export shape. Tests mock\n * via env.posthog to intercept every call.\n */\nexport interface PostHogSDK {\n init: (\n token: string,\n config?: Partial<PostHogConfig> & {\n loaded?: (posthog: PostHogSDK) => void;\n },\n name?: string,\n ) => PostHogSDK;\n capture: (eventName: string, properties?: Properties) => void;\n identify: (\n distinctId?: string,\n userPropertiesToSet?: Properties,\n userPropertiesToSetOnce?: Properties,\n ) => void;\n setPersonProperties: (\n userPropertiesToSet?: Properties,\n userPropertiesToSetOnce?: Properties,\n ) => void;\n group: (\n groupType: string,\n groupKey: string,\n groupPropertiesToSet?: Properties,\n ) => void;\n reset: (resetDeviceId?: boolean) => void;\n opt_in_capturing: (options?: {\n captureEventName?: string | null | false;\n captureProperties?: Properties;\n }) => void;\n opt_out_capturing: () => void;\n}\n\n/**\n * Env — optional SDK override. Production leaves this undefined and the\n * destination falls back to the real `posthog-js` default export. Tests\n * provide a mock via env.posthog = { ... }.\n */\nexport interface Env extends DestinationWeb.Env {\n posthog?: PostHogSDK;\n}\n\nexport type Types = CoreDestination.Types<Settings, Mapping, Env, InitSettings>;\n\nexport type Destination = DestinationWeb.Destination<Types>;\nexport type Config = DestinationWeb.Config<Types>;\n\nexport interface PostHogDestination extends Destination {\n env?: Env;\n}\n\nexport type Rule = WalkerOSMapping.Rule<Mapping>;\nexport type Rules = WalkerOSMapping.Rules<Rule>;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;A;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AAA,UACnB;AAAA,UACA;AAAA,UACA,MAAM;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAGA,UAAM,gBAAe,qBAAgB,UAAhB,YAAyB,SAAS;AACvD,QAAI,iBAAiB,QAAW;AAC9B,YAAM,WAAW,MAAM,GAAgB,OAAO,cAAc;AAAA,QAC1D;AAAA,MACF,CAAC;AACD,UAAI,EAAS,QAAQ,GAAG;AACtB,cAAM,YAAY;AAAA,UAChB;AAAA,UACA;AAAA,UACA,MAAM;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAGA,SAAI,6BAAM,UAAS,MAAM;AACvB,YAAM,YAAY,GAAS,6BAAM,IAAI,IAAI,KAAK,OAAO,MAAM;AAC3D,YAAM,aAAa,EAAS,IAAI,IAC3B,OACD,CAAC;AACL,cAAQ,QAAQ,WAAW,UAAU;AAAA,IACvC;AAIA,aAAS,SAAS;AAAA,EACpB;AAAA,EAEA,GAAG,MAAM,SAAS;AA3MpB;AA4MI,QAAI,SAAS,aAAa,EAAC,mCAAS,MAAM;AAC1C,UAAM,UAAU,WAAW,QAAQ,GAAsB;AAEzD,UAAM,UAAU,QAAQ;AAIxB,UAAM,YAAY,aAAQ,WAAR,mBACd;AACJ,QAAI,CAAC,YAAY,OAAO,KAAK,QAAQ,EAAE,WAAW,EAAG;AAErD,UAAM,aAAa,OAAO,KAAK,QAAQ,EAAE;AAAA,MACvC,CAAC,QAAQ,QAAQ,GAAG,MAAM;AAAA,IAC5B;AACA,QAAI,YAAY;AACd,cAAQ,iBAAiB;AAAA,IAC3B,OAAO;AACL,cAAQ,kBAAkB;AAAA,IAC5B;AAAA,EACF;AACF;AAEA,IAAO,gBAAQ;","names":["posthogSDK"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/types/index.ts"],"sourcesContent":["import type { WalkerOS } from '@walkeros/core';\nimport { getMappingValue, isObject, isString } from '@walkeros/core';\nimport posthogSDK from 'posthog-js';\nimport type {\n Destination,\n Env,\n PostHogSDK,\n RuntimeState,\n Settings,\n} from './types';\n\n// Types export\nexport * as DestinationPostHog from './types';\n\n/**\n * Resolve the PostHog SDK: use the caller-provided mock when available\n * (tests), otherwise fall back to the real `posthog-js` default export.\n * Matches @walkeros/web-destination-clarity and\n * @walkeros/server-destination-gcp (BigQuery).\n */\nfunction getPostHog(env: Env | undefined): PostHogSDK {\n return env?.posthog ?? (posthogSDK as unknown as PostHogSDK);\n}\n\n/**\n * Resolve the identify mapping value, call the right SDK method.\n *\n * - If `distinctId` is present and has changed since last push (or props present):\n * posthog.identify(distinctId, $set?, $set_once?)\n * - If `distinctId` is absent but $set/$set_once exist:\n * posthog.setPersonProperties($set, $set_once)\n * - If nothing resolves or distinctId unchanged and no props: no-op\n *\n * Returns the updated lastIdentity snapshot.\n */\nfunction applyIdentity(\n posthog: PostHogSDK,\n resolved: Record<string, unknown>,\n lastIdentity: RuntimeState['lastIdentity'] = {},\n): NonNullable<RuntimeState['lastIdentity']> {\n const updated = { ...lastIdentity };\n\n const distinctId = resolved.distinctId;\n const $set = isObject(resolved.$set)\n ? (resolved.$set as Record<string, unknown>)\n : undefined;\n const $setOnce = isObject(resolved.$set_once)\n ? (resolved.$set_once as Record<string, unknown>)\n : undefined;\n\n if (isString(distinctId) && distinctId !== '') {\n if (distinctId !== lastIdentity.distinctId || $set || $setOnce) {\n posthog.identify(distinctId, $set, $setOnce);\n updated.distinctId = distinctId;\n }\n } else if ($set || $setOnce) {\n posthog.setPersonProperties($set, $setOnce);\n }\n\n return updated;\n}\n\n/**\n * Resolve the group mapping value, call posthog.group(type, key, properties?).\n * Like identity, group changes are tracked in runtime state and only re-fired\n * when type or key changes.\n */\nfunction applyGroup(\n posthog: PostHogSDK,\n resolved: Record<string, unknown>,\n lastGroup: RuntimeState['lastGroup'] = {},\n): NonNullable<RuntimeState['lastGroup']> {\n const updated = { ...lastGroup };\n const type = resolved.type;\n const key = resolved.key;\n const properties = isObject(resolved.properties)\n ? (resolved.properties as Record<string, unknown>)\n : undefined;\n\n if (isString(type) && isString(key)) {\n if (type !== lastGroup.type || key !== lastGroup.key || properties) {\n posthog.group(type, key, properties);\n updated.type = type;\n updated.key = key;\n }\n }\n\n return updated;\n}\n\nexport const destinationPostHog: Destination = {\n type: 'posthog',\n\n config: {},\n\n async init({ config, env }) {\n const settings = config.settings;\n if (!settings?.apiKey) return false;\n\n const posthog = getPostHog(env as Env | undefined);\n\n const {\n apiKey,\n identify: _identify,\n group: _group,\n _state: _existingState,\n ...posthogOptions\n } = settings;\n\n // walkerOS defaults that override PostHog defaults: walkerOS sources\n // handle event capture, so turn off PostHog's own.\n const options = {\n autocapture: false,\n capture_pageview: false,\n capture_pageleave: false,\n ...posthogOptions,\n };\n\n // posthog.init() is synchronous and returns the singleton. It supports\n // an optional `loaded` callback for post-bootstrap hooks (feature flags\n // fetched, etc). We wait up to one microtask for it to fire so the\n // destination is truly ready before returning; otherwise we resolve\n // immediately so tests with no-op mocks don't hang.\n let loadedFired = false;\n posthog.init(apiKey, {\n ...options,\n loaded: () => {\n loadedFired = true;\n },\n });\n if (!loadedFired) {\n await Promise.resolve();\n }\n\n const _state: RuntimeState = { lastIdentity: {}, lastGroup: {} };\n return { ...config, settings: { ...settings, _state } };\n },\n\n async push(event, { config, rule, env, data, collector }) {\n const posthog = getPostHog(env as Env | undefined);\n const settings = (config.settings || {}) as Settings;\n const mappingSettings = rule?.settings || {};\n const state: RuntimeState = settings._state || {};\n\n // 1. Reset - fires first so subsequent identity calls start clean.\n if (mappingSettings.reset !== undefined) {\n const resolved =\n typeof mappingSettings.reset === 'boolean'\n ? mappingSettings.reset\n : await getMappingValue(event, mappingSettings.reset, {\n collector,\n });\n if (resolved) {\n posthog.reset();\n state.lastIdentity = {};\n state.lastGroup = {};\n }\n }\n\n // 2. Identity - rule-level override wins over destination-level.\n const identifyMapping = mappingSettings.identify ?? settings.identify;\n if (identifyMapping !== undefined) {\n const resolved = await getMappingValue(event, identifyMapping, {\n collector,\n });\n if (isObject(resolved)) {\n state.lastIdentity = applyIdentity(\n posthog,\n resolved as Record<string, unknown>,\n state.lastIdentity,\n );\n }\n }\n\n // 3. Group - rule-level override wins over destination-level.\n const groupMapping = mappingSettings.group ?? settings.group;\n if (groupMapping !== undefined) {\n const resolved = await getMappingValue(event, groupMapping, {\n collector,\n });\n if (isObject(resolved)) {\n state.lastGroup = applyGroup(\n posthog,\n resolved as Record<string, unknown>,\n state.lastGroup,\n );\n }\n }\n\n // 4. Default capture - unless rule opts out via silent.\n if (rule?.silent !== true) {\n const eventName = isString(rule?.name) ? rule.name : event.name;\n const properties = isObject(data)\n ? (data as Record<string, unknown>)\n : {};\n posthog.capture(eventName, properties);\n }\n\n // Persist state. walkerOS destinations are long-lived singletons so\n // mutating settings in place is safe (Snowplow precedent).\n settings._state = state;\n },\n\n on(type, context) {\n if (type !== 'consent' || !context?.data) return;\n const posthog = getPostHog(context.env as Env | undefined);\n\n const consent = context.data as WalkerOS.Consent;\n // Derive required consent keys from config.consent. If all declared\n // keys are granted, opt IN; otherwise opt OUT. Missing config.consent\n // means nothing to check and we take no action.\n const required = (context.config as { consent?: WalkerOS.Consent })\n ?.consent;\n if (!required || Object.keys(required).length === 0) return;\n\n const allGranted = Object.keys(required).every(\n (key) => consent[key] === true,\n );\n if (allGranted) {\n posthog.opt_in_capturing();\n } else {\n posthog.opt_out_capturing();\n }\n },\n};\n\nexport default destinationPostHog;\n","import type {\n Mapping as WalkerOSMapping,\n Destination as CoreDestination,\n} from '@walkeros/core';\nimport type { DestinationWeb } from '@walkeros/web-core';\n// Import SDK types directly — never duplicate. Verified against posthog-js@1.367.0.\nimport type { PostHogConfig, Properties } from 'posthog-js';\n\n/**\n * Destination-level settings.\n *\n * PostHog's `PostHogConfig` interface has ~80 fields — extending the SDK type\n * directly keeps IntelliSense complete and prevents drift. The destination adds:\n * - `apiKey` (required) — first arg to `posthog.init(...)`, NOT an init option\n * - `identify` — destination-level identity mapping\n * - `include` — event sections flattened into `capture()` properties\n * - `group` — destination-level group association\n * - `_state` — runtime state (not user-facing, mutated by init/push)\n *\n * All other walkerOS-specific mapping features live under mapping.settings\n * (see Mapping interface below). Built-in PostHog features (session_recording,\n * advanced_disable_flags, disable_surveys, capture_heatmaps, capture_exceptions,\n * bootstrap, cookieless_mode, ...) are passthrough via PostHogConfig.\n */\nexport interface Settings extends Partial<PostHogConfig> {\n /** PostHog project API key (e.g. \"phc_XXX\"). First arg to posthog.init(). */\n apiKey: string;\n /** Destination-level identity mapping, resolved on first push. */\n identify?: WalkerOSMapping.Value;\n /** Destination-level group association, resolved on first push. */\n group?: WalkerOSMapping.Value;\n /** Runtime state — populated by init() and mutated by push(). Not user-facing. */\n _state?: RuntimeState;\n}\n\nexport interface RuntimeState {\n /** Last-resolved identity values, used to skip redundant identify/group calls. */\n lastIdentity?: {\n distinctId?: string;\n };\n lastGroup?: {\n type?: string;\n key?: string;\n };\n}\n\nexport type InitSettings = Partial<Settings>;\n\n/**\n * Per-rule mapping settings. Every feature here is a walkerOS mapping value\n * resolved via getMappingValue(). The resolved object's keys drive which\n * SDK methods are called.\n *\n * - identify: { distinctId?, $set?, $set_once? } → posthog.identify() OR posthog.setPersonProperties()\n * - group: { type, key, properties? } → posthog.group()\n * - reset: boolean → posthog.reset()\n * - include: string[] → flattened properties (overrides destination-level)\n */\nexport interface Mapping {\n identify?: WalkerOSMapping.Value;\n group?: WalkerOSMapping.Value;\n reset?: WalkerOSMapping.Value | boolean;\n}\n\n/**\n * PostHog SDK surface — the subset of `posthog-js` the destination actually\n * uses. Mirrors the real module's default singleton export shape. Tests mock\n * via env.posthog to intercept every call.\n */\nexport interface PostHogSDK {\n init: (\n token: string,\n config?: Partial<PostHogConfig> & {\n loaded?: (posthog: PostHogSDK) => void;\n },\n name?: string,\n ) => PostHogSDK;\n capture: (eventName: string, properties?: Properties) => void;\n identify: (\n distinctId?: string,\n userPropertiesToSet?: Properties,\n userPropertiesToSetOnce?: Properties,\n ) => void;\n setPersonProperties: (\n userPropertiesToSet?: Properties,\n userPropertiesToSetOnce?: Properties,\n ) => void;\n group: (\n groupType: string,\n groupKey: string,\n groupPropertiesToSet?: Properties,\n ) => void;\n reset: (resetDeviceId?: boolean) => void;\n opt_in_capturing: (options?: {\n captureEventName?: string | null | false;\n captureProperties?: Properties;\n }) => void;\n opt_out_capturing: () => void;\n}\n\n/**\n * Env — optional SDK override. Production leaves this undefined and the\n * destination falls back to the real `posthog-js` default export. Tests\n * provide a mock via env.posthog = { ... }.\n */\nexport interface Env extends DestinationWeb.Env {\n posthog?: PostHogSDK;\n}\n\nexport type Types = CoreDestination.Types<Settings, Mapping, Env, InitSettings>;\n\nexport type Destination = DestinationWeb.Destination<Types>;\nexport type Config = DestinationWeb.Config<Types>;\n\nexport interface PostHogDestination extends Destination {\n env?: Env;\n}\n\nexport type Rule = WalkerOSMapping.Rule<Mapping>;\nexport type Rules = WalkerOSMapping.Rules<Rule>;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;A;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,wBAAuB;;;ACFvB;;;ADoBA,SAAS,WAAW,KAAkC;AApBtD;AAqBE,UAAO,gCAAK,YAAL,YAAiB,kBAAAA;AAC1B;AAaA,SAAS,cACP,SACA,UACA,eAA6C,CAAC,GACH;AAC3C,QAAM,UAAU,EAAE,GAAG,aAAa;AAElC,QAAM,aAAa,SAAS;AAC5B,QAAM,OAAO,GAAS,SAAS,IAAI,IAC9B,SAAS,OACV;AACJ,QAAM,WAAW,GAAS,SAAS,SAAS,IACvC,SAAS,YACV;AAEJ,MAAI,GAAS,UAAU,KAAK,eAAe,IAAI;AAC7C,QAAI,eAAe,aAAa,cAAc,QAAQ,UAAU;AAC9D,cAAQ,SAAS,YAAY,MAAM,QAAQ;AAC3C,cAAQ,aAAa;AAAA,I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AAU;AAAA,IACvC;AAIA,aAAS,SAAS;AAAA,EACpB;AAAA,EAEA,GAAG,MAAM,SAAS;AA3MpB;AA4MI,QAAI,SAAS,aAAa,EAAC,mCAAS,MAAM;AAC1C,UAAM,UAAU,WAAW,QAAQ,GAAsB;AAEzD,UAAM,UAAU,QAAQ;AAIxB,UAAM,YAAY,aAAQ,WAAR,mBACd;AACJ,QAAI,CAAC,YAAY,OAAO,KAAK,QAAQ,EAAE,WAAW,EAAG;AAErD,UAAM,aAAa,OAAO,KAAK,QAAQ,EAAE;AAAA,MACvC,CAAC,QAAQ,QAAQ,GAAG,MAAM;AAAA,IAC5B;AACA,QAAI,YAAY;AACd,cAAQ,iBAAiB;AAAA,IAC3B,OAAO;AACL,cAAQ,kBAAkB;AAAA,IAC5B;AAAA,EACF;AACF;AAEA,IAAO,gBAAQ;","names":["posthogSDK"]}
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var t=Object.defineProperty;((e,n)=>{for(var o in n)t(e,o,{get:n[o],enumerable:!0})})({},{Level:()=>n});var e,n=((e=n||{})[e.ERROR=0]="ERROR",e[e.WARN=1]="WARN",e[e.INFO=2]="INFO",e[e.DEBUG=3]="DEBUG",e);function o(t){return Array.isArray(t)}function r(t){return void 0!==t}function i(t){return"object"==typeof t&&null!==t&&!o(t)&&"[object Object]"===Object.prototype.toString.call(t)}function
|
|
1
|
+
var t=Object.defineProperty;((e,n)=>{for(var o in n)t(e,o,{get:n[o],enumerable:!0})})({},{Level:()=>n});var e,n=((e=n||{})[e.ERROR=0]="ERROR",e[e.WARN=1]="WARN",e[e.INFO=2]="INFO",e[e.DEBUG=3]="DEBUG",e);function o(t){return Array.isArray(t)}function r(t){return void 0!==t}function i(t){return"object"==typeof t&&null!==t&&!o(t)&&"[object Object]"===Object.prototype.toString.call(t)}function c(t){return"string"==typeof t}function a(t,e="",n){const i=e.split(".");let c=t;for(let t=0;t<i.length;t++){const e=i[t];if("*"===e&&o(c)){const e=i.slice(t+1).join("."),o=[];for(const t of c){const r=a(t,e,n);o.push(r)}return o}if(c=c instanceof Object?c[e]:void 0,void 0===c)break}return r(c)?c:n}function s(t){return function(t){return"boolean"==typeof t}(t)||c(t)||function(t){return"number"==typeof t&&!Number.isNaN(t)}(t)||!r(t)||o(t)&&t.every(s)||i(t)&&Object.values(t).every(s)}function l(t){return s(t)?t:void 0}function u(t,e,n){return async function(...o){try{return await t(...o)}catch(t){if(!e)return;return await e(t)}finally{await(null==n?void 0:n())}}}async function f(t,e={},n={}){var c,a;if(!r(t))return;const s=i(t)&&t.consent||n.consent||(null==(c=n.collector)?void 0:c.consent),l=null!=(a=n.event)?a:i(t)?t:{};if(!n.collector)throw new Error("getMappingValue: context.collector is required");const f={event:l,mapping:e,collector:n.collector,logger:n.collector.logger,consent:s},d=o(e)?e:[e];for(const e of d){const n=await u(p)(t,e,{...f,mapping:e});if(r(n))return n}}async function p(t,e,n){return(o(e)?e:[e]).reduce(async(e,i)=>{const s=await e;if(s)return s;const d=c(i)?{key:i}:i;if(!Object.keys(d).length)return;const{condition:v,consent:y,fn:g,key:w,loop:b,map:m,set:j,validate:O,value:h}=d,_={...n,mapping:i};if(v&&!await u(v)(t,_))return;if(y&&!function(t,e={},n={}){const o={...e,...n},r={};let i=!t||0===Object.keys(t).length;return Object.keys(o).forEach(e=>{o[e]&&(r[e]=!0,t&&t[e]&&(i=!0))}),!!i&&r}(y,_.consent))return h;let k=r(h)?h:t;if(g&&(k=await u(g)(t,_)),w&&(k=a(t,w,h)),b){const[e,n]=b,i="this"===e?[t]:await f(t,e,_);o(i)&&(k=(await Promise.all(i.map(t=>f(t,n,_)))).filter(r))}else m?k=await Object.entries(m).reduce(async(e,[n,o])=>{const i=await e,c=await f(t,o,_);return r(c)&&(i[n]=c),i},Promise.resolve({})):j&&(k=await Promise.all(j.map(e=>p(t,e,_))));O&&!await u(O)(k,_)&&(k=void 0);const I=l(k);return r(I)?I:l(h)},Promise.resolve(void 0))}import d from"posthog-js";var v={};function y(t){var e;return null!=(e=null==t?void 0:t.posthog)?e:d}var g={type:"posthog",config:{},async init({config:t,env:e}){const n=t.settings;if(!(null==n?void 0:n.apiKey))return!1;const o=y(e),{apiKey:r,identify:i,group:c,_state:a,...s}=n,l={autocapture:!1,capture_pageview:!1,capture_pageleave:!1,...s};let u=!1;o.init(r,{...l,loaded:()=>{u=!0}}),u||await Promise.resolve();return{...t,settings:{...n,_state:{lastIdentity:{},lastGroup:{}}}}},async push(t,{config:e,rule:n,env:o,data:r,collector:a}){var s,l;const u=y(o),p=e.settings||{},d=(null==n?void 0:n.settings)||{},v=p._state||{};if(void 0!==d.reset){("boolean"==typeof d.reset?d.reset:await f(t,d.reset,{collector:a}))&&(u.reset(),v.lastIdentity={},v.lastGroup={})}const g=null!=(s=d.identify)?s:p.identify;if(void 0!==g){const e=await f(t,g,{collector:a});i(e)&&(v.lastIdentity=function(t,e,n={}){const o={...n},r=e.distinctId,a=i(e.$set)?e.$set:void 0,s=i(e.$set_once)?e.$set_once:void 0;return c(r)&&""!==r?(r!==n.distinctId||a||s)&&(t.identify(r,a,s),o.distinctId=r):(a||s)&&t.setPersonProperties(a,s),o}(u,e,v.lastIdentity))}const w=null!=(l=d.group)?l:p.group;if(void 0!==w){const e=await f(t,w,{collector:a});i(e)&&(v.lastGroup=function(t,e,n={}){const o={...n},r=e.type,a=e.key,s=i(e.properties)?e.properties:void 0;return c(r)&&c(a)&&(r!==n.type||a!==n.key||s)&&(t.group(r,a,s),o.type=r,o.key=a),o}(u,e,v.lastGroup))}if(!0!==(null==n?void 0:n.silent)){const e=c(null==n?void 0:n.name)?n.name:t.name,o=i(r)?r:{};u.capture(e,o)}p._state=v},on(t,e){var n;if("consent"!==t||!(null==e?void 0:e.data))return;const o=y(e.env),r=e.data,i=null==(n=e.config)?void 0:n.consent;if(!i||0===Object.keys(i).length)return;Object.keys(i).every(t=>!0===r[t])?o.opt_in_capturing():o.opt_out_capturing()}},w=g;export{v as DestinationPostHog,w as default,g as destinationPostHog};//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/types/index.ts"],"sourcesContent":["import type { WalkerOS } from '@walkeros/core';\nimport { getMappingValue, isObject, isString } from '@walkeros/core';\nimport posthogSDK from 'posthog-js';\nimport type {\n Destination,\n Env,\n PostHogSDK,\n RuntimeState,\n Settings,\n} from './types';\n\n// Types export\nexport * as DestinationPostHog from './types';\n\n/**\n * Resolve the PostHog SDK: use the caller-provided mock when available\n * (tests), otherwise fall back to the real `posthog-js` default export.\n * Matches @walkeros/web-destination-clarity and\n * @walkeros/server-destination-gcp (BigQuery).\n */\nfunction getPostHog(env: Env | undefined): PostHogSDK {\n return env?.posthog ?? (posthogSDK as unknown as PostHogSDK);\n}\n\n/**\n * Resolve the identify mapping value, call the right SDK method.\n *\n * - If `distinctId` is present and has changed since last push (or props present):\n * posthog.identify(distinctId, $set?, $set_once?)\n * - If `distinctId` is absent but $set/$set_once exist:\n * posthog.setPersonProperties($set, $set_once)\n * - If nothing resolves or distinctId unchanged and no props: no-op\n *\n * Returns the updated lastIdentity snapshot.\n */\nfunction applyIdentity(\n posthog: PostHogSDK,\n resolved: Record<string, unknown>,\n lastIdentity: RuntimeState['lastIdentity'] = {},\n): NonNullable<RuntimeState['lastIdentity']> {\n const updated = { ...lastIdentity };\n\n const distinctId = resolved.distinctId;\n const $set = isObject(resolved.$set)\n ? (resolved.$set as Record<string, unknown>)\n : undefined;\n const $setOnce = isObject(resolved.$set_once)\n ? (resolved.$set_once as Record<string, unknown>)\n : undefined;\n\n if (isString(distinctId) && distinctId !== '') {\n if (distinctId !== lastIdentity.distinctId || $set || $setOnce) {\n posthog.identify(distinctId, $set, $setOnce);\n updated.distinctId = distinctId;\n }\n } else if ($set || $setOnce) {\n posthog.setPersonProperties($set, $setOnce);\n }\n\n return updated;\n}\n\n/**\n * Resolve the group mapping value, call posthog.group(type, key, properties?).\n * Like identity, group changes are tracked in runtime state and only re-fired\n * when type or key changes.\n */\nfunction applyGroup(\n posthog: PostHogSDK,\n resolved: Record<string, unknown>,\n lastGroup: RuntimeState['lastGroup'] = {},\n): NonNullable<RuntimeState['lastGroup']> {\n const updated = { ...lastGroup };\n const type = resolved.type;\n const key = resolved.key;\n const properties = isObject(resolved.properties)\n ? (resolved.properties as Record<string, unknown>)\n : undefined;\n\n if (isString(type) && isString(key)) {\n if (type !== lastGroup.type || key !== lastGroup.key || properties) {\n posthog.group(type, key, properties);\n updated.type = type;\n updated.key = key;\n }\n }\n\n return updated;\n}\n\nexport const destinationPostHog: Destination = {\n type: 'posthog',\n\n config: {},\n\n async init({ config, env }) {\n const settings = config.settings;\n if (!settings?.apiKey) return false;\n\n const posthog = getPostHog(env as Env | undefined);\n\n const {\n apiKey,\n identify: _identify,\n group: _group,\n _state: _existingState,\n ...posthogOptions\n } = settings;\n\n // walkerOS defaults that override PostHog defaults: walkerOS sources\n // handle event capture, so turn off PostHog's own.\n const options = {\n autocapture: false,\n capture_pageview: false,\n capture_pageleave: false,\n ...posthogOptions,\n };\n\n // posthog.init() is synchronous and returns the singleton. It supports\n // an optional `loaded` callback for post-bootstrap hooks (feature flags\n // fetched, etc). We wait up to one microtask for it to fire so the\n // destination is truly ready before returning; otherwise we resolve\n // immediately so tests with no-op mocks don't hang.\n let loadedFired = false;\n posthog.init(apiKey, {\n ...options,\n loaded: () => {\n loadedFired = true;\n },\n });\n if (!loadedFired) {\n await Promise.resolve();\n }\n\n const _state: RuntimeState = { lastIdentity: {}, lastGroup: {} };\n return { ...config, settings: { ...settings, _state } };\n },\n\n async push(event, { config, rule, env, data, collector }) {\n const posthog = getPostHog(env as Env | undefined);\n const settings = (config.settings || {}) as Settings;\n const mappingSettings = rule?.settings || {};\n const state: RuntimeState = settings._state || {};\n\n // 1. Reset — fires first so subsequent identity calls start clean.\n if (mappingSettings.reset !== undefined) {\n const resolved =\n typeof mappingSettings.reset === 'boolean'\n ? mappingSettings.reset\n : await getMappingValue(event, mappingSettings.reset, {\n collector,\n });\n if (resolved) {\n posthog.reset();\n state.lastIdentity = {};\n state.lastGroup = {};\n }\n }\n\n // 2. Identity — rule-level override wins over destination-level.\n const identifyMapping = mappingSettings.identify ?? settings.identify;\n if (identifyMapping !== undefined) {\n const resolved = await getMappingValue(event, identifyMapping, {\n collector,\n });\n if (isObject(resolved)) {\n state.lastIdentity = applyIdentity(\n posthog,\n resolved as Record<string, unknown>,\n state.lastIdentity,\n );\n }\n }\n\n // 3. Group — rule-level override wins over destination-level.\n const groupMapping = mappingSettings.group ?? settings.group;\n if (groupMapping !== undefined) {\n const resolved = await getMappingValue(event, groupMapping, {\n collector,\n });\n if (isObject(resolved)) {\n state.lastGroup = applyGroup(\n posthog,\n resolved as Record<string, unknown>,\n state.lastGroup,\n );\n }\n }\n\n // 4. Default capture — unless rule opts out via skip.\n if (rule?.skip !== true) {\n const eventName = isString(rule?.name) ? rule.name : event.name;\n const properties = isObject(data)\n ? (data as Record<string, unknown>)\n : {};\n posthog.capture(eventName, properties);\n }\n\n // Persist state. walkerOS destinations are long-lived singletons so\n // mutating settings in place is safe (Snowplow precedent).\n settings._state = state;\n },\n\n on(type, context) {\n if (type !== 'consent' || !context?.data) return;\n const posthog = getPostHog(context.env as Env | undefined);\n\n const consent = context.data as WalkerOS.Consent;\n // Derive required consent keys from config.consent. If all declared\n // keys are granted, opt IN; otherwise opt OUT. Missing config.consent\n // means nothing to check and we take no action.\n const required = (context.config as { consent?: WalkerOS.Consent })\n ?.consent;\n if (!required || Object.keys(required).length === 0) return;\n\n const allGranted = Object.keys(required).every(\n (key) => consent[key] === true,\n );\n if (allGranted) {\n posthog.opt_in_capturing();\n } else {\n posthog.opt_out_capturing();\n }\n },\n};\n\nexport default destinationPostHog;\n","import type {\n Mapping as WalkerOSMapping,\n Destination as CoreDestination,\n} from '@walkeros/core';\nimport type { DestinationWeb } from '@walkeros/web-core';\n// Import SDK types directly — never duplicate. Verified against posthog-js@1.367.0.\nimport type { PostHogConfig, Properties } from 'posthog-js';\n\n/**\n * Destination-level settings.\n *\n * PostHog's `PostHogConfig` interface has ~80 fields — extending the SDK type\n * directly keeps IntelliSense complete and prevents drift. The destination adds:\n * - `apiKey` (required) — first arg to `posthog.init(...)`, NOT an init option\n * - `identify` — destination-level identity mapping\n * - `include` — event sections flattened into `capture()` properties\n * - `group` — destination-level group association\n * - `_state` — runtime state (not user-facing, mutated by init/push)\n *\n * All other walkerOS-specific mapping features live under mapping.settings\n * (see Mapping interface below). Built-in PostHog features (session_recording,\n * advanced_disable_flags, disable_surveys, capture_heatmaps, capture_exceptions,\n * bootstrap, cookieless_mode, ...) are passthrough via PostHogConfig.\n */\nexport interface Settings extends Partial<PostHogConfig> {\n /** PostHog project API key (e.g. \"phc_XXX\"). First arg to posthog.init(). */\n apiKey: string;\n /** Destination-level identity mapping, resolved on first push. */\n identify?: WalkerOSMapping.Value;\n /** Destination-level group association, resolved on first push. */\n group?: WalkerOSMapping.Value;\n /** Runtime state — populated by init() and mutated by push(). Not user-facing. */\n _state?: RuntimeState;\n}\n\nexport interface RuntimeState {\n /** Last-resolved identity values, used to skip redundant identify/group calls. */\n lastIdentity?: {\n distinctId?: string;\n };\n lastGroup?: {\n type?: string;\n key?: string;\n };\n}\n\nexport type InitSettings = Partial<Settings>;\n\n/**\n * Per-rule mapping settings. Every feature here is a walkerOS mapping value\n * resolved via getMappingValue(). The resolved object's keys drive which\n * SDK methods are called.\n *\n * - identify: { distinctId?, $set?, $set_once? } → posthog.identify() OR posthog.setPersonProperties()\n * - group: { type, key, properties? } → posthog.group()\n * - reset: boolean → posthog.reset()\n * - include: string[] → flattened properties (overrides destination-level)\n */\nexport interface Mapping {\n identify?: WalkerOSMapping.Value;\n group?: WalkerOSMapping.Value;\n reset?: WalkerOSMapping.Value | boolean;\n}\n\n/**\n * PostHog SDK surface — the subset of `posthog-js` the destination actually\n * uses. Mirrors the real module's default singleton export shape. Tests mock\n * via env.posthog to intercept every call.\n */\nexport interface PostHogSDK {\n init: (\n token: string,\n config?: Partial<PostHogConfig> & {\n loaded?: (posthog: PostHogSDK) => void;\n },\n name?: string,\n ) => PostHogSDK;\n capture: (eventName: string, properties?: Properties) => void;\n identify: (\n distinctId?: string,\n userPropertiesToSet?: Properties,\n userPropertiesToSetOnce?: Properties,\n ) => void;\n setPersonProperties: (\n userPropertiesToSet?: Properties,\n userPropertiesToSetOnce?: Properties,\n ) => void;\n group: (\n groupType: string,\n groupKey: string,\n groupPropertiesToSet?: Properties,\n ) => void;\n reset: (resetDeviceId?: boolean) => void;\n opt_in_capturing: (options?: {\n captureEventName?: string | null | false;\n captureProperties?: Properties;\n }) => void;\n opt_out_capturing: () => void;\n}\n\n/**\n * Env — optional SDK override. Production leaves this undefined and the\n * destination falls back to the real `posthog-js` default export. Tests\n * provide a mock via env.posthog = { ... }.\n */\nexport interface Env extends DestinationWeb.Env {\n posthog?: PostHogSDK;\n}\n\nexport type Types = CoreDestination.Types<Settings, Mapping, Env, InitSettings>;\n\nexport type Destination = DestinationWeb.Destination<Types>;\nexport type Config = DestinationWeb.Config<Types>;\n\nexport interface PostHogDestination extends Destination {\n env?: Env;\n}\n\nexport type Rule = WalkerOSMapping.Rule<Mapping>;\nexport type Rules = WalkerOSMapping.Rules<Rule>;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,OAAO,gBAAgB;;;ACFvB;;;ADoBA,SAAS,WAAW,KAAkC;AApBtD;AAqBE,UAAO,gCAAK,YAAL,YAAiB;AAC1B;AAaA,SAAS,cACP,SACA,UACA,eAA6C,CAAC,GACH;AAC3C,QAAM,UAAU,EAAE,GAAG,aAAa;AAElC,QAAM,aAAa,SAAS;AAC5B,QAAM,OAAO,EAAS,SAAS,IAAI,IAC9B,SAAS,OACV;AACJ,QAAM,WAAW,EAAS,SAAS,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AAA,IACF;AAGA,SAAI,6BAAM,UAAS,MAAM;AACvB,YAAM,YAAY,GAAS,6BAAM,IAAI,IAAI,KAAK,OAAO,MAAM;AAC3D,YAAM,aAAa,EAAS,IAAI,IAC3B,OACD,CAAC;AACL,cAAQ,QAAQ,WAAW,UAAU;AAAA,IACvC;AAIA,aAAS,SAAS;AAAA,EACpB;AAAA,EAEA,GAAG,MAAM,SAAS;AA3MpB;AA4MI,QAAI,SAAS,aAAa,EAAC,mCAAS,MAAM;AAC1C,UAAM,UAAU,WAAW,QAAQ,GAAsB;AAEzD,UAAM,UAAU,QAAQ;AAIxB,UAAM,YAAY,aAAQ,WAAR,mBACd;AACJ,QAAI,CAAC,YAAY,OAAO,KAAK,QAAQ,EAAE,WAAW,EAAG;AAErD,UAAM,aAAa,OAAO,KAAK,QAAQ,EAAE;AAAA,MACvC,CAAC,QAAQ,QAAQ,GAAG,MAAM;AAAA,IAC5B;AACA,QAAI,YAAY;AACd,cAAQ,iBAAiB;AAAA,IAC3B,OAAO;AACL,cAAQ,kBAAkB;AAAA,IAC5B;AAAA,EACF;AACF;AAEA,IAAO,gBAAQ;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/types/index.ts"],"sourcesContent":["import type { WalkerOS } from '@walkeros/core';\nimport { getMappingValue, isObject, isString } from '@walkeros/core';\nimport posthogSDK from 'posthog-js';\nimport type {\n Destination,\n Env,\n PostHogSDK,\n RuntimeState,\n Settings,\n} from './types';\n\n// Types export\nexport * as DestinationPostHog from './types';\n\n/**\n * Resolve the PostHog SDK: use the caller-provided mock when available\n * (tests), otherwise fall back to the real `posthog-js` default export.\n * Matches @walkeros/web-destination-clarity and\n * @walkeros/server-destination-gcp (BigQuery).\n */\nfunction getPostHog(env: Env | undefined): PostHogSDK {\n return env?.posthog ?? (posthogSDK as unknown as PostHogSDK);\n}\n\n/**\n * Resolve the identify mapping value, call the right SDK method.\n *\n * - If `distinctId` is present and has changed since last push (or props present):\n * posthog.identify(distinctId, $set?, $set_once?)\n * - If `distinctId` is absent but $set/$set_once exist:\n * posthog.setPersonProperties($set, $set_once)\n * - If nothing resolves or distinctId unchanged and no props: no-op\n *\n * Returns the updated lastIdentity snapshot.\n */\nfunction applyIdentity(\n posthog: PostHogSDK,\n resolved: Record<string, unknown>,\n lastIdentity: RuntimeState['lastIdentity'] = {},\n): NonNullable<RuntimeState['lastIdentity']> {\n const updated = { ...lastIdentity };\n\n const distinctId = resolved.distinctId;\n const $set = isObject(resolved.$set)\n ? (resolved.$set as Record<string, unknown>)\n : undefined;\n const $setOnce = isObject(resolved.$set_once)\n ? (resolved.$set_once as Record<string, unknown>)\n : undefined;\n\n if (isString(distinctId) && distinctId !== '') {\n if (distinctId !== lastIdentity.distinctId || $set || $setOnce) {\n posthog.identify(distinctId, $set, $setOnce);\n updated.distinctId = distinctId;\n }\n } else if ($set || $setOnce) {\n posthog.setPersonProperties($set, $setOnce);\n }\n\n return updated;\n}\n\n/**\n * Resolve the group mapping value, call posthog.group(type, key, properties?).\n * Like identity, group changes are tracked in runtime state and only re-fired\n * when type or key changes.\n */\nfunction applyGroup(\n posthog: PostHogSDK,\n resolved: Record<string, unknown>,\n lastGroup: RuntimeState['lastGroup'] = {},\n): NonNullable<RuntimeState['lastGroup']> {\n const updated = { ...lastGroup };\n const type = resolved.type;\n const key = resolved.key;\n const properties = isObject(resolved.properties)\n ? (resolved.properties as Record<string, unknown>)\n : undefined;\n\n if (isString(type) && isString(key)) {\n if (type !== lastGroup.type || key !== lastGroup.key || properties) {\n posthog.group(type, key, properties);\n updated.type = type;\n updated.key = key;\n }\n }\n\n return updated;\n}\n\nexport const destinationPostHog: Destination = {\n type: 'posthog',\n\n config: {},\n\n async init({ config, env }) {\n const settings = config.settings;\n if (!settings?.apiKey) return false;\n\n const posthog = getPostHog(env as Env | undefined);\n\n const {\n apiKey,\n identify: _identify,\n group: _group,\n _state: _existingState,\n ...posthogOptions\n } = settings;\n\n // walkerOS defaults that override PostHog defaults: walkerOS sources\n // handle event capture, so turn off PostHog's own.\n const options = {\n autocapture: false,\n capture_pageview: false,\n capture_pageleave: false,\n ...posthogOptions,\n };\n\n // posthog.init() is synchronous and returns the singleton. It supports\n // an optional `loaded` callback for post-bootstrap hooks (feature flags\n // fetched, etc). We wait up to one microtask for it to fire so the\n // destination is truly ready before returning; otherwise we resolve\n // immediately so tests with no-op mocks don't hang.\n let loadedFired = false;\n posthog.init(apiKey, {\n ...options,\n loaded: () => {\n loadedFired = true;\n },\n });\n if (!loadedFired) {\n await Promise.resolve();\n }\n\n const _state: RuntimeState = { lastIdentity: {}, lastGroup: {} };\n return { ...config, settings: { ...settings, _state } };\n },\n\n async push(event, { config, rule, env, data, collector }) {\n const posthog = getPostHog(env as Env | undefined);\n const settings = (config.settings || {}) as Settings;\n const mappingSettings = rule?.settings || {};\n const state: RuntimeState = settings._state || {};\n\n // 1. Reset - fires first so subsequent identity calls start clean.\n if (mappingSettings.reset !== undefined) {\n const resolved =\n typeof mappingSettings.reset === 'boolean'\n ? mappingSettings.reset\n : await getMappingValue(event, mappingSettings.reset, {\n collector,\n });\n if (resolved) {\n posthog.reset();\n state.lastIdentity = {};\n state.lastGroup = {};\n }\n }\n\n // 2. Identity - rule-level override wins over destination-level.\n const identifyMapping = mappingSettings.identify ?? settings.identify;\n if (identifyMapping !== undefined) {\n const resolved = await getMappingValue(event, identifyMapping, {\n collector,\n });\n if (isObject(resolved)) {\n state.lastIdentity = applyIdentity(\n posthog,\n resolved as Record<string, unknown>,\n state.lastIdentity,\n );\n }\n }\n\n // 3. Group - rule-level override wins over destination-level.\n const groupMapping = mappingSettings.group ?? settings.group;\n if (groupMapping !== undefined) {\n const resolved = await getMappingValue(event, groupMapping, {\n collector,\n });\n if (isObject(resolved)) {\n state.lastGroup = applyGroup(\n posthog,\n resolved as Record<string, unknown>,\n state.lastGroup,\n );\n }\n }\n\n // 4. Default capture - unless rule opts out via silent.\n if (rule?.silent !== true) {\n const eventName = isString(rule?.name) ? rule.name : event.name;\n const properties = isObject(data)\n ? (data as Record<string, unknown>)\n : {};\n posthog.capture(eventName, properties);\n }\n\n // Persist state. walkerOS destinations are long-lived singletons so\n // mutating settings in place is safe (Snowplow precedent).\n settings._state = state;\n },\n\n on(type, context) {\n if (type !== 'consent' || !context?.data) return;\n const posthog = getPostHog(context.env as Env | undefined);\n\n const consent = context.data as WalkerOS.Consent;\n // Derive required consent keys from config.consent. If all declared\n // keys are granted, opt IN; otherwise opt OUT. Missing config.consent\n // means nothing to check and we take no action.\n const required = (context.config as { consent?: WalkerOS.Consent })\n ?.consent;\n if (!required || Object.keys(required).length === 0) return;\n\n const allGranted = Object.keys(required).every(\n (key) => consent[key] === true,\n );\n if (allGranted) {\n posthog.opt_in_capturing();\n } else {\n posthog.opt_out_capturing();\n }\n },\n};\n\nexport default destinationPostHog;\n","import type {\n Mapping as WalkerOSMapping,\n Destination as CoreDestination,\n} from '@walkeros/core';\nimport type { DestinationWeb } from '@walkeros/web-core';\n// Import SDK types directly — never duplicate. Verified against posthog-js@1.367.0.\nimport type { PostHogConfig, Properties } from 'posthog-js';\n\n/**\n * Destination-level settings.\n *\n * PostHog's `PostHogConfig` interface has ~80 fields — extending the SDK type\n * directly keeps IntelliSense complete and prevents drift. The destination adds:\n * - `apiKey` (required) — first arg to `posthog.init(...)`, NOT an init option\n * - `identify` — destination-level identity mapping\n * - `include` — event sections flattened into `capture()` properties\n * - `group` — destination-level group association\n * - `_state` — runtime state (not user-facing, mutated by init/push)\n *\n * All other walkerOS-specific mapping features live under mapping.settings\n * (see Mapping interface below). Built-in PostHog features (session_recording,\n * advanced_disable_flags, disable_surveys, capture_heatmaps, capture_exceptions,\n * bootstrap, cookieless_mode, ...) are passthrough via PostHogConfig.\n */\nexport interface Settings extends Partial<PostHogConfig> {\n /** PostHog project API key (e.g. \"phc_XXX\"). First arg to posthog.init(). */\n apiKey: string;\n /** Destination-level identity mapping, resolved on first push. */\n identify?: WalkerOSMapping.Value;\n /** Destination-level group association, resolved on first push. */\n group?: WalkerOSMapping.Value;\n /** Runtime state — populated by init() and mutated by push(). Not user-facing. */\n _state?: RuntimeState;\n}\n\nexport interface RuntimeState {\n /** Last-resolved identity values, used to skip redundant identify/group calls. */\n lastIdentity?: {\n distinctId?: string;\n };\n lastGroup?: {\n type?: string;\n key?: string;\n };\n}\n\nexport type InitSettings = Partial<Settings>;\n\n/**\n * Per-rule mapping settings. Every feature here is a walkerOS mapping value\n * resolved via getMappingValue(). The resolved object's keys drive which\n * SDK methods are called.\n *\n * - identify: { distinctId?, $set?, $set_once? } → posthog.identify() OR posthog.setPersonProperties()\n * - group: { type, key, properties? } → posthog.group()\n * - reset: boolean → posthog.reset()\n * - include: string[] → flattened properties (overrides destination-level)\n */\nexport interface Mapping {\n identify?: WalkerOSMapping.Value;\n group?: WalkerOSMapping.Value;\n reset?: WalkerOSMapping.Value | boolean;\n}\n\n/**\n * PostHog SDK surface — the subset of `posthog-js` the destination actually\n * uses. Mirrors the real module's default singleton export shape. Tests mock\n * via env.posthog to intercept every call.\n */\nexport interface PostHogSDK {\n init: (\n token: string,\n config?: Partial<PostHogConfig> & {\n loaded?: (posthog: PostHogSDK) => void;\n },\n name?: string,\n ) => PostHogSDK;\n capture: (eventName: string, properties?: Properties) => void;\n identify: (\n distinctId?: string,\n userPropertiesToSet?: Properties,\n userPropertiesToSetOnce?: Properties,\n ) => void;\n setPersonProperties: (\n userPropertiesToSet?: Properties,\n userPropertiesToSetOnce?: Properties,\n ) => void;\n group: (\n groupType: string,\n groupKey: string,\n groupPropertiesToSet?: Properties,\n ) => void;\n reset: (resetDeviceId?: boolean) => void;\n opt_in_capturing: (options?: {\n captureEventName?: string | null | false;\n captureProperties?: Properties;\n }) => void;\n opt_out_capturing: () => void;\n}\n\n/**\n * Env — optional SDK override. Production leaves this undefined and the\n * destination falls back to the real `posthog-js` default export. Tests\n * provide a mock via env.posthog = { ... }.\n */\nexport interface Env extends DestinationWeb.Env {\n posthog?: PostHogSDK;\n}\n\nexport type Types = CoreDestination.Types<Settings, Mapping, Env, InitSettings>;\n\nexport type Destination = DestinationWeb.Destination<Types>;\nexport type Config = DestinationWeb.Config<Types>;\n\nexport interface PostHogDestination extends Destination {\n env?: Env;\n}\n\nexport type Rule = WalkerOSMapping.Rule<Mapping>;\nexport type Rules = WalkerOSMapping.Rules<Rule>;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,OAAO,gBAAgB;;;ACFvB;;;ADoBA,SAAS,WAAW,KAAkC;AApBtD;AAqBE,UAAO,gCAAK,YAAL,YAAiB;AAC1B;AAaA,SAAS,cACP,SACA,UACA,eAA6C,CAAC,GACH;AAC3C,QAAM,UAAU,EAAE,GAAG,aAAa;AAElC,QAAM,aAAa,SAAS;AAC5B,QAAM,OAAO,GAAS,SAAS,IAAI,IAC9B,SAAS,OACV;AACJ,QAAM,WAAW,GAAS,SAAS,SAAS,IACvC,SAAS,YACV;AAEJ,MAAI,GAAS,UAAU,KAAK,eAAe,IAAI;AAC7C,QAAI,eAAe,aAAa,cAAc,QAAQ,UAAU;AAC9D,cAAQ,SAAS,YAAY,MAAM,QAAQ;AAC3C,cAAQ,aAAa;AAAA,IACvB;AAAA,EACF,WAAW,QAAQ,UAAU;AAC3B,YAAQ,oBAAoB,MAAM,QAAQ;AAAA,EAC5C;AAEA,SAAO;AACT;AAOA,SAAS,WACP,SACA,UACA,YAAuC,CAAC,GACA;AACxC,QAAM,UAAU,EAAE,GAAG,UAAU;AAC/B,QAAM,OAAO,SAAS;AACtB,QAAM,MAAM,SAAS;AACrB,QAAM,aAAa,GAAS,SAAS,UAAU,IAC1C,SAAS,aACV;AAEJ,MAAI,GAAS,IAAI,KAAK,GAAS,GAAG,GAAG;AACnC,QAAI,SAAS,UAAU,QAAQ,QAAQ,UAAU,OAAO,YAAY;AAClE,cAAQ,MAAM,MAAM,KAAK,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Q,iBAAiB;AAAA,IAC3B,OAAO;AACL,cAAQ,kBAAkB;AAAA,IAC5B;AAAA,EACF;AACF;AAEA,IAAO,gBAAQ;","names":[]}
|
package/dist/walkerOS.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$meta": {
|
|
3
3
|
"package": "@walkeros/web-destination-posthog",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "4.0.0-next-1777882869103",
|
|
5
5
|
"type": "destination",
|
|
6
6
|
"platform": [
|
|
7
7
|
"web"
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"description": "Group assignment. Resolves to { type, key, properties? } → posthog.group(type, key, properties)."
|
|
22
22
|
},
|
|
23
23
|
"reset": {
|
|
24
|
-
"description": "Logout trigger. Resolves to a truthy value → posthog.reset() (clears distinctId and regenerates an anonymous one). Typically used with
|
|
24
|
+
"description": "Logout trigger. Resolves to a truthy value → posthog.reset() (clears distinctId and regenerates an anonymous one). Typically used with silent: true on a user logout rule."
|
|
25
25
|
}
|
|
26
26
|
},
|
|
27
27
|
"additionalProperties": false
|
|
@@ -147,7 +147,7 @@
|
|
|
147
147
|
"init": {
|
|
148
148
|
"posthog": {
|
|
149
149
|
"init": {
|
|
150
|
-
"$code": "()=>
|
|
150
|
+
"$code": "()=>xh"
|
|
151
151
|
},
|
|
152
152
|
"capture": {
|
|
153
153
|
"$code": "()=>{}"
|
|
@@ -175,7 +175,7 @@
|
|
|
175
175
|
"push": {
|
|
176
176
|
"posthog": {
|
|
177
177
|
"init": {
|
|
178
|
-
"$code": "()=>
|
|
178
|
+
"$code": "()=>xh"
|
|
179
179
|
},
|
|
180
180
|
"capture": {
|
|
181
181
|
"$code": "()=>{}"
|
|
@@ -273,22 +273,15 @@
|
|
|
273
273
|
"consent": {
|
|
274
274
|
"functional": true
|
|
275
275
|
},
|
|
276
|
-
"id": "
|
|
276
|
+
"id": "8c792479a59705a5",
|
|
277
277
|
"trigger": "load",
|
|
278
278
|
"entity": "product",
|
|
279
279
|
"action": "view",
|
|
280
280
|
"timestamp": 1700000100,
|
|
281
281
|
"timing": 3.14,
|
|
282
|
-
"group": "gr0up",
|
|
283
|
-
"count": 1,
|
|
284
|
-
"version": {
|
|
285
|
-
"source": "3.4.2",
|
|
286
|
-
"tagging": 1
|
|
287
|
-
},
|
|
288
282
|
"source": {
|
|
289
|
-
"type": "
|
|
290
|
-
"
|
|
291
|
-
"previous_id": "http://remotehost:9001"
|
|
283
|
+
"type": "collector",
|
|
284
|
+
"schema": "4"
|
|
292
285
|
}
|
|
293
286
|
},
|
|
294
287
|
"out": [
|
|
@@ -334,35 +327,21 @@
|
|
|
334
327
|
"entity": "child",
|
|
335
328
|
"data": {
|
|
336
329
|
"is": "subordinated"
|
|
337
|
-
},
|
|
338
|
-
"nested": [],
|
|
339
|
-
"context": {
|
|
340
|
-
"element": [
|
|
341
|
-
"child",
|
|
342
|
-
0
|
|
343
|
-
]
|
|
344
330
|
}
|
|
345
331
|
}
|
|
346
332
|
],
|
|
347
333
|
"consent": {
|
|
348
334
|
"functional": true
|
|
349
335
|
},
|
|
350
|
-
"id": "
|
|
336
|
+
"id": "9d4bea638b763eab",
|
|
351
337
|
"trigger": "load",
|
|
352
338
|
"entity": "page",
|
|
353
339
|
"action": "view",
|
|
354
340
|
"timestamp": 1700000104,
|
|
355
341
|
"timing": 3.14,
|
|
356
|
-
"group": "gr0up",
|
|
357
|
-
"count": 1,
|
|
358
|
-
"version": {
|
|
359
|
-
"source": "3.4.2",
|
|
360
|
-
"tagging": 1
|
|
361
|
-
},
|
|
362
342
|
"source": {
|
|
363
|
-
"type": "
|
|
364
|
-
"
|
|
365
|
-
"previous_id": "http://remotehost:9001"
|
|
343
|
+
"type": "collector",
|
|
344
|
+
"schema": "4"
|
|
366
345
|
}
|
|
367
346
|
},
|
|
368
347
|
"settings": {
|
|
@@ -417,22 +396,15 @@
|
|
|
417
396
|
"consent": {
|
|
418
397
|
"functional": true
|
|
419
398
|
},
|
|
420
|
-
"id": "
|
|
399
|
+
"id": "695e19b131e4dda6",
|
|
421
400
|
"trigger": "load",
|
|
422
401
|
"entity": "product",
|
|
423
402
|
"action": "view",
|
|
424
403
|
"timestamp": 1700000102,
|
|
425
404
|
"timing": 3.14,
|
|
426
|
-
"group": "gr0up",
|
|
427
|
-
"count": 1,
|
|
428
|
-
"version": {
|
|
429
|
-
"source": "3.4.2",
|
|
430
|
-
"tagging": 1
|
|
431
|
-
},
|
|
432
405
|
"source": {
|
|
433
|
-
"type": "
|
|
434
|
-
"
|
|
435
|
-
"previous_id": "http://remotehost:9001"
|
|
406
|
+
"type": "collector",
|
|
407
|
+
"schema": "4"
|
|
436
408
|
}
|
|
437
409
|
},
|
|
438
410
|
"configInclude": [
|
|
@@ -485,39 +457,25 @@
|
|
|
485
457
|
"entity": "child",
|
|
486
458
|
"data": {
|
|
487
459
|
"is": "subordinated"
|
|
488
|
-
},
|
|
489
|
-
"nested": [],
|
|
490
|
-
"context": {
|
|
491
|
-
"element": [
|
|
492
|
-
"child",
|
|
493
|
-
0
|
|
494
|
-
]
|
|
495
460
|
}
|
|
496
461
|
}
|
|
497
462
|
],
|
|
498
463
|
"consent": {
|
|
499
464
|
"functional": true
|
|
500
465
|
},
|
|
501
|
-
"id": "
|
|
466
|
+
"id": "b9b46d8b423aa8c2",
|
|
502
467
|
"trigger": "test",
|
|
503
468
|
"entity": "company",
|
|
504
469
|
"action": "update",
|
|
505
470
|
"timestamp": 1700000108,
|
|
506
471
|
"timing": 3.14,
|
|
507
|
-
"group": "gr0up",
|
|
508
|
-
"count": 1,
|
|
509
|
-
"version": {
|
|
510
|
-
"source": "3.4.2",
|
|
511
|
-
"tagging": 1
|
|
512
|
-
},
|
|
513
472
|
"source": {
|
|
514
|
-
"type": "
|
|
515
|
-
"
|
|
516
|
-
"previous_id": "http://remotehost:9001"
|
|
473
|
+
"type": "collector",
|
|
474
|
+
"schema": "4"
|
|
517
475
|
}
|
|
518
476
|
},
|
|
519
477
|
"mapping": {
|
|
520
|
-
"
|
|
478
|
+
"silent": true,
|
|
521
479
|
"settings": {
|
|
522
480
|
"group": {
|
|
523
481
|
"map": {
|
|
@@ -629,22 +587,15 @@
|
|
|
629
587
|
"consent": {
|
|
630
588
|
"functional": true
|
|
631
589
|
},
|
|
632
|
-
"id": "
|
|
590
|
+
"id": "2732732d268c1d55",
|
|
633
591
|
"trigger": "load",
|
|
634
592
|
"entity": "order",
|
|
635
593
|
"action": "complete",
|
|
636
594
|
"timestamp": 1700000109,
|
|
637
595
|
"timing": 3.14,
|
|
638
|
-
"group": "gr0up",
|
|
639
|
-
"count": 1,
|
|
640
|
-
"version": {
|
|
641
|
-
"source": "3.4.2",
|
|
642
|
-
"tagging": 1
|
|
643
|
-
},
|
|
644
596
|
"source": {
|
|
645
|
-
"type": "
|
|
646
|
-
"
|
|
647
|
-
"previous_id": "http://remotehost:9001"
|
|
597
|
+
"type": "collector",
|
|
598
|
+
"schema": "4"
|
|
648
599
|
}
|
|
649
600
|
},
|
|
650
601
|
"mapping": {
|
|
@@ -699,35 +650,21 @@
|
|
|
699
650
|
"entity": "child",
|
|
700
651
|
"data": {
|
|
701
652
|
"is": "subordinated"
|
|
702
|
-
},
|
|
703
|
-
"nested": [],
|
|
704
|
-
"context": {
|
|
705
|
-
"element": [
|
|
706
|
-
"child",
|
|
707
|
-
0
|
|
708
|
-
]
|
|
709
653
|
}
|
|
710
654
|
}
|
|
711
655
|
],
|
|
712
656
|
"consent": {
|
|
713
657
|
"functional": true
|
|
714
658
|
},
|
|
715
|
-
"id": "
|
|
659
|
+
"id": "1c08ba5fd939afae",
|
|
716
660
|
"trigger": "test",
|
|
717
661
|
"entity": "profile",
|
|
718
662
|
"action": "update",
|
|
719
663
|
"timestamp": 1700000106,
|
|
720
664
|
"timing": 3.14,
|
|
721
|
-
"group": "gr0up",
|
|
722
|
-
"count": 1,
|
|
723
|
-
"version": {
|
|
724
|
-
"source": "3.4.2",
|
|
725
|
-
"tagging": 1
|
|
726
|
-
},
|
|
727
665
|
"source": {
|
|
728
|
-
"type": "
|
|
729
|
-
"
|
|
730
|
-
"previous_id": "http://remotehost:9001"
|
|
666
|
+
"type": "collector",
|
|
667
|
+
"schema": "4"
|
|
731
668
|
}
|
|
732
669
|
},
|
|
733
670
|
"mapping": {
|
|
@@ -840,22 +777,15 @@
|
|
|
840
777
|
"consent": {
|
|
841
778
|
"functional": true
|
|
842
779
|
},
|
|
843
|
-
"id": "
|
|
780
|
+
"id": "1f428070fb75196e",
|
|
844
781
|
"trigger": "load",
|
|
845
782
|
"entity": "order",
|
|
846
783
|
"action": "complete",
|
|
847
784
|
"timestamp": 1700000103,
|
|
848
785
|
"timing": 3.14,
|
|
849
|
-
"group": "gr0up",
|
|
850
|
-
"count": 1,
|
|
851
|
-
"version": {
|
|
852
|
-
"source": "3.4.2",
|
|
853
|
-
"tagging": 1
|
|
854
|
-
},
|
|
855
786
|
"source": {
|
|
856
|
-
"type": "
|
|
857
|
-
"
|
|
858
|
-
"previous_id": "http://remotehost:9001"
|
|
787
|
+
"type": "collector",
|
|
788
|
+
"schema": "4"
|
|
859
789
|
}
|
|
860
790
|
},
|
|
861
791
|
"configInclude": [
|
|
@@ -910,39 +840,25 @@
|
|
|
910
840
|
"entity": "child",
|
|
911
841
|
"data": {
|
|
912
842
|
"is": "subordinated"
|
|
913
|
-
},
|
|
914
|
-
"nested": [],
|
|
915
|
-
"context": {
|
|
916
|
-
"element": [
|
|
917
|
-
"child",
|
|
918
|
-
0
|
|
919
|
-
]
|
|
920
843
|
}
|
|
921
844
|
}
|
|
922
845
|
],
|
|
923
846
|
"consent": {
|
|
924
847
|
"functional": true
|
|
925
848
|
},
|
|
926
|
-
"id": "
|
|
849
|
+
"id": "38b2547a259aa493",
|
|
927
850
|
"trigger": "test",
|
|
928
851
|
"entity": "user",
|
|
929
852
|
"action": "login",
|
|
930
853
|
"timestamp": 1700000105,
|
|
931
854
|
"timing": 3.14,
|
|
932
|
-
"group": "gr0up",
|
|
933
|
-
"count": 1,
|
|
934
|
-
"version": {
|
|
935
|
-
"source": "3.4.2",
|
|
936
|
-
"tagging": 1
|
|
937
|
-
},
|
|
938
855
|
"source": {
|
|
939
|
-
"type": "
|
|
940
|
-
"
|
|
941
|
-
"previous_id": "http://remotehost:9001"
|
|
856
|
+
"type": "collector",
|
|
857
|
+
"schema": "4"
|
|
942
858
|
}
|
|
943
859
|
},
|
|
944
860
|
"mapping": {
|
|
945
|
-
"
|
|
861
|
+
"silent": true,
|
|
946
862
|
"settings": {
|
|
947
863
|
"identify": {
|
|
948
864
|
"map": {
|
|
@@ -1017,39 +933,25 @@
|
|
|
1017
933
|
"entity": "child",
|
|
1018
934
|
"data": {
|
|
1019
935
|
"is": "subordinated"
|
|
1020
|
-
},
|
|
1021
|
-
"nested": [],
|
|
1022
|
-
"context": {
|
|
1023
|
-
"element": [
|
|
1024
|
-
"child",
|
|
1025
|
-
0
|
|
1026
|
-
]
|
|
1027
936
|
}
|
|
1028
937
|
}
|
|
1029
938
|
],
|
|
1030
939
|
"consent": {
|
|
1031
940
|
"functional": true
|
|
1032
941
|
},
|
|
1033
|
-
"id": "
|
|
942
|
+
"id": "ff6297f0af1661eb",
|
|
1034
943
|
"trigger": "test",
|
|
1035
944
|
"entity": "user",
|
|
1036
945
|
"action": "logout",
|
|
1037
946
|
"timestamp": 1700000107,
|
|
1038
947
|
"timing": 3.14,
|
|
1039
|
-
"group": "gr0up",
|
|
1040
|
-
"count": 1,
|
|
1041
|
-
"version": {
|
|
1042
|
-
"source": "3.4.2",
|
|
1043
|
-
"tagging": 1
|
|
1044
|
-
},
|
|
1045
948
|
"source": {
|
|
1046
|
-
"type": "
|
|
1047
|
-
"
|
|
1048
|
-
"previous_id": "http://remotehost:9001"
|
|
949
|
+
"type": "collector",
|
|
950
|
+
"schema": "4"
|
|
1049
951
|
}
|
|
1050
952
|
},
|
|
1051
953
|
"mapping": {
|
|
1052
|
-
"
|
|
954
|
+
"silent": true,
|
|
1053
955
|
"settings": {
|
|
1054
956
|
"reset": true
|
|
1055
957
|
}
|
|
@@ -1096,35 +998,21 @@
|
|
|
1096
998
|
"entity": "child",
|
|
1097
999
|
"data": {
|
|
1098
1000
|
"is": "subordinated"
|
|
1099
|
-
},
|
|
1100
|
-
"nested": [],
|
|
1101
|
-
"context": {
|
|
1102
|
-
"element": [
|
|
1103
|
-
"child",
|
|
1104
|
-
0
|
|
1105
|
-
]
|
|
1106
1001
|
}
|
|
1107
1002
|
}
|
|
1108
1003
|
],
|
|
1109
1004
|
"consent": {
|
|
1110
1005
|
"functional": true
|
|
1111
1006
|
},
|
|
1112
|
-
"id": "
|
|
1007
|
+
"id": "d239fbbf80ef5fda",
|
|
1113
1008
|
"trigger": "test",
|
|
1114
1009
|
"entity": "debug",
|
|
1115
1010
|
"action": "noise",
|
|
1116
1011
|
"timestamp": 1700000101,
|
|
1117
1012
|
"timing": 3.14,
|
|
1118
|
-
"group": "gr0up",
|
|
1119
|
-
"count": 1,
|
|
1120
|
-
"version": {
|
|
1121
|
-
"source": "3.4.2",
|
|
1122
|
-
"tagging": 1
|
|
1123
|
-
},
|
|
1124
1013
|
"source": {
|
|
1125
|
-
"type": "
|
|
1126
|
-
"
|
|
1127
|
-
"previous_id": "http://remotehost:9001"
|
|
1014
|
+
"type": "collector",
|
|
1015
|
+
"schema": "4"
|
|
1128
1016
|
}
|
|
1129
1017
|
},
|
|
1130
1018
|
"mapping": {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@walkeros/web-destination-posthog",
|
|
3
3
|
"description": "PostHog web destination for walkerOS (product analytics, session replay, feature flags, surveys)",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "4.0.0-next-1777882869103",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"module": "./dist/index.mjs",
|
|
@@ -38,10 +38,10 @@
|
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"posthog-js": "^1.367.0",
|
|
41
|
-
"@walkeros/web-core": "
|
|
41
|
+
"@walkeros/web-core": "4.0.0-next-1777882869103"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@walkeros/collector": "
|
|
44
|
+
"@walkeros/collector": "4.0.0-next-1777882869103"
|
|
45
45
|
},
|
|
46
46
|
"repository": {
|
|
47
47
|
"url": "git+https://github.com/elbwalker/walkerOS.git",
|