posthog-js 1.157.2 → 1.158.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/array.full.js +2 -2
- package/dist/array.full.js.map +1 -1
- package/dist/array.js +1 -1
- package/dist/array.js.map +1 -1
- package/dist/lib/src/extensions/segment-integration.d.ts +2 -2
- package/dist/main.js +1 -1
- package/dist/main.js.map +1 -1
- package/dist/module.js +1 -1
- package/dist/module.js.map +1 -1
- package/lib/package.json +2 -2
- package/lib/src/extensions/segment-integration.d.ts +2 -2
- package/lib/src/extensions/segment-integration.js +3 -4
- package/lib/src/extensions/segment-integration.js.map +1 -1
- package/package.json +2 -2
package/lib/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "posthog-js",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.158.0",
|
|
4
4
|
"description": "Posthog-js allows you to automatically capture usage and send events to PostHog.",
|
|
5
5
|
"repository": "https://github.com/PostHog/posthog-js",
|
|
6
6
|
"author": "hey@posthog.com",
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"babel-eslint": "10.1.0",
|
|
69
69
|
"babel-jest": "^26.6.3",
|
|
70
70
|
"compare-versions": "^6.1.0",
|
|
71
|
-
"cypress": "13.
|
|
71
|
+
"cypress": "13.6.3",
|
|
72
72
|
"cypress-localstorage-commands": "^2.2.6",
|
|
73
73
|
"date-fns": "^3.6.0",
|
|
74
74
|
"eslint": "8.56.0",
|
|
@@ -25,7 +25,7 @@ export type SegmentAnalytics = {
|
|
|
25
25
|
user: () => SegmentUser | Promise<SegmentUser>;
|
|
26
26
|
register: (integration: SegmentPlugin) => Promise<void>;
|
|
27
27
|
};
|
|
28
|
-
interface SegmentContext {
|
|
28
|
+
export interface SegmentContext {
|
|
29
29
|
event: {
|
|
30
30
|
event: string;
|
|
31
31
|
userId?: string;
|
|
@@ -34,7 +34,7 @@ interface SegmentContext {
|
|
|
34
34
|
};
|
|
35
35
|
}
|
|
36
36
|
type SegmentFunction = (ctx: SegmentContext) => Promise<SegmentContext> | SegmentContext;
|
|
37
|
-
interface SegmentPlugin {
|
|
37
|
+
export interface SegmentPlugin {
|
|
38
38
|
name: string;
|
|
39
39
|
version: string;
|
|
40
40
|
type: 'enrichment';
|
|
@@ -13,13 +13,12 @@ var createSegmentIntegration = function (posthog) {
|
|
|
13
13
|
}
|
|
14
14
|
if (!ctx.event.userId && ctx.event.anonymousId !== posthog.get_distinct_id()) {
|
|
15
15
|
// This is our only way of detecting that segment's analytics.reset() has been called so we also call it
|
|
16
|
+
logger.info('Segment integration does not have a userId set, resetting PostHog');
|
|
16
17
|
posthog.reset();
|
|
17
18
|
}
|
|
18
19
|
if (ctx.event.userId && ctx.event.userId !== posthog.get_distinct_id()) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
});
|
|
22
|
-
posthog.reloadFeatureFlags();
|
|
20
|
+
logger.info('Segment integration has a userId set, identifying with PostHog');
|
|
21
|
+
posthog.identify(ctx.event.userId);
|
|
23
22
|
}
|
|
24
23
|
var additionalProperties = posthog._calculate_event_properties(eventName, (_a = ctx.event.properties) !== null && _a !== void 0 ? _a : {}, new Date());
|
|
25
24
|
ctx.event.properties = Object.assign({}, additionalProperties, ctx.event.properties);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"segment-integration.js","sourceRoot":"","sources":["../../../src/extensions/segment-integration.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAExC,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAwCzC,IAAM,wBAAwB,GAAG,UAAC,OAAgB;IAC9C,IAAI,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE;QAC9B,MAAM,CAAC,IAAI,CAAC,qFAAqF,CAAC,CAAA;KACrG;IAED,IAAM,WAAW,GAAG,UAAC,GAAmB,EAAE,SAA6B;;QACnE,IAAI,CAAC,SAAS,EAAE;YACZ,OAAO,GAAG,CAAA;SACb;QACD,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,IAAI,GAAG,CAAC,KAAK,CAAC,WAAW,KAAK,OAAO,CAAC,eAAe,EAAE,EAAE;YAC1E,wGAAwG;YACxG,OAAO,CAAC,KAAK,EAAE,CAAA;SAClB;QACD,IAAI,GAAG,CAAC,KAAK,CAAC,MAAM,IAAI,GAAG,CAAC,KAAK,CAAC,MAAM,KAAK,OAAO,CAAC,eAAe,EAAE,EAAE;YACpE,
|
|
1
|
+
{"version":3,"file":"segment-integration.js","sourceRoot":"","sources":["../../../src/extensions/segment-integration.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAExC,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAwCzC,IAAM,wBAAwB,GAAG,UAAC,OAAgB;IAC9C,IAAI,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE;QAC9B,MAAM,CAAC,IAAI,CAAC,qFAAqF,CAAC,CAAA;KACrG;IAED,IAAM,WAAW,GAAG,UAAC,GAAmB,EAAE,SAA6B;;QACnE,IAAI,CAAC,SAAS,EAAE;YACZ,OAAO,GAAG,CAAA;SACb;QACD,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,IAAI,GAAG,CAAC,KAAK,CAAC,WAAW,KAAK,OAAO,CAAC,eAAe,EAAE,EAAE;YAC1E,wGAAwG;YACxG,MAAM,CAAC,IAAI,CAAC,mEAAmE,CAAC,CAAA;YAChF,OAAO,CAAC,KAAK,EAAE,CAAA;SACl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C,wBAAwB,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC;YACrD,IAAI,EAAE,CAAA;QACV,CAAC,CAAC,CAAA;IACN,CAAC,CAAC,CAAA;AACN,CAAC","sourcesContent":["/**\n * Extend Segment with extra PostHog JS functionality. Required for things like Recordings and feature flags to work correctly.\n *\n * ### Usage\n *\n * ```js\n * // After your standard segment anyalytics install\n * analytics.load(\"GOEDfA21zZTtR7clsBuDvmBKAtAdZ6Np\");\n *\n * analytics.ready(() => {\n * posthog.init('<posthog-api-key>', {\n * capture_pageview: false,\n * segment: window.analytics, // NOTE: Be sure to use window.analytics here!\n * });\n * window.analytics.page();\n * })\n * ```\n */\nimport { PostHog } from '../posthog-core'\nimport { logger } from '../utils/logger'\n\nimport { uuidv7 } from '../uuidv7'\nimport { isFunction } from '../utils/type-utils'\nimport { USER_STATE } from '../constants'\n\nexport type SegmentUser = {\n anonymousId(): string | undefined\n id(): string | undefined\n}\n\nexport type SegmentAnalytics = {\n user: () => SegmentUser | Promise<SegmentUser>\n register: (integration: SegmentPlugin) => Promise<void>\n}\n\n// Loosely based on https://github.com/segmentio/analytics-next/blob/master/packages/core/src/plugins/index.ts\nexport interface SegmentContext {\n event: {\n event: string\n userId?: string\n anonymousId?: string\n properties: any\n }\n}\n\ntype SegmentFunction = (ctx: SegmentContext) => Promise<SegmentContext> | SegmentContext\n\nexport interface SegmentPlugin {\n name: string\n version: string\n type: 'enrichment'\n isLoaded: () => boolean\n load: (ctx: SegmentContext, instance: any, config?: any) => Promise<unknown>\n unload?: (ctx: SegmentContext, instance: any) => Promise<unknown> | unknown\n ready?: () => Promise<unknown>\n track?: SegmentFunction\n identify?: SegmentFunction\n page?: SegmentFunction\n group?: SegmentFunction\n alias?: SegmentFunction\n screen?: SegmentFunction\n}\n\nconst createSegmentIntegration = (posthog: PostHog): SegmentPlugin => {\n if (!Promise || !Promise.resolve) {\n logger.warn('This browser does not have Promise support, and can not use the segment integration')\n }\n\n const enrichEvent = (ctx: SegmentContext, eventName: string | undefined) => {\n if (!eventName) {\n return ctx\n }\n if (!ctx.event.userId && ctx.event.anonymousId !== posthog.get_distinct_id()) {\n // This is our only way of detecting that segment's analytics.reset() has been called so we also call it\n logger.info('Segment integration does not have a userId set, resetting PostHog')\n posthog.reset()\n }\n if (ctx.event.userId && ctx.event.userId !== posthog.get_distinct_id()) {\n logger.info('Segment integration has a userId set, identifying with PostHog')\n posthog.identify(ctx.event.userId)\n }\n\n const additionalProperties = posthog._calculate_event_properties(\n eventName,\n ctx.event.properties ?? {},\n new Date()\n )\n ctx.event.properties = Object.assign({}, additionalProperties, ctx.event.properties)\n return ctx\n }\n\n return {\n name: 'PostHog JS',\n type: 'enrichment',\n version: '1.0.0',\n isLoaded: () => true,\n // check and early return above\n // eslint-disable-next-line compat/compat\n load: () => Promise.resolve(),\n track: (ctx) => enrichEvent(ctx, ctx.event.event),\n page: (ctx) => enrichEvent(ctx, '$pageview'),\n identify: (ctx) => enrichEvent(ctx, '$identify'),\n screen: (ctx) => enrichEvent(ctx, '$screen'),\n }\n}\n\nfunction setupPostHogFromSegment(posthog: PostHog, done: () => void) {\n const segment = posthog.config.segment\n if (!segment) {\n return done()\n }\n\n const bootstrapUser = (user: SegmentUser) => {\n // Use segments anonymousId instead\n const getSegmentAnonymousId = () => user.anonymousId() || uuidv7()\n posthog.config.get_device_id = getSegmentAnonymousId\n\n // If a segment user ID exists, set it as the distinct_id\n if (user.id()) {\n posthog.register({\n distinct_id: user.id(),\n $device_id: getSegmentAnonymousId(),\n })\n posthog.persistence!.set_property(USER_STATE, 'identified')\n }\n\n done()\n }\n\n const segmentUser = segment.user()\n\n // If segmentUser is a promise then we need to wait for it to resolve\n if ('then' in segmentUser && isFunction(segmentUser.then)) {\n segmentUser.then((user) => bootstrapUser(user))\n } else {\n bootstrapUser(segmentUser as SegmentUser)\n }\n}\n\nexport function setupSegmentIntegration(posthog: PostHog, done: () => void) {\n const segment = posthog.config.segment\n if (!segment) {\n return done()\n }\n\n setupPostHogFromSegment(posthog, () => {\n segment.register(createSegmentIntegration(posthog)).then(() => {\n done()\n })\n })\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "posthog-js",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.158.0",
|
|
4
4
|
"description": "Posthog-js allows you to automatically capture usage and send events to PostHog.",
|
|
5
5
|
"repository": "https://github.com/PostHog/posthog-js",
|
|
6
6
|
"author": "hey@posthog.com",
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"babel-eslint": "10.1.0",
|
|
69
69
|
"babel-jest": "^26.6.3",
|
|
70
70
|
"compare-versions": "^6.1.0",
|
|
71
|
-
"cypress": "13.
|
|
71
|
+
"cypress": "13.6.3",
|
|
72
72
|
"cypress-localstorage-commands": "^2.2.6",
|
|
73
73
|
"date-fns": "^3.6.0",
|
|
74
74
|
"eslint": "8.56.0",
|