posthog-node 3.4.0 → 3.6.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/CHANGELOG.md +9 -0
- package/lib/index.cjs.js +187 -75
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +19 -13
- package/lib/index.esm.js +187 -75
- package/lib/index.esm.js.map +1 -1
- package/lib/posthog-core/src/index.d.ts +13 -12
- package/lib/posthog-core/src/types.d.ts +4 -1
- package/lib/posthog-node/src/posthog-node.d.ts +4 -3
- package/lib/posthog-node/src/types.d.ts +5 -4
- package/package.json +1 -1
- package/src/feature-flags.ts +10 -6
- package/src/posthog-node.ts +113 -24
- package/src/types.ts +5 -4
- package/test/extensions/sentry-integration.spec.ts +3 -0
- package/test/feature-flags.spec.ts +17 -2
- package/test/posthog-node.spec.ts +427 -10
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PostHogFetchOptions, PostHogFetchResponse, PostHogAutocaptureElement, PostHogDecideResponse, PosthogCoreOptions, PostHogEventProperties, PostHogPersistedProperty,
|
|
1
|
+
import { PostHogFetchOptions, PostHogFetchResponse, PostHogAutocaptureElement, PostHogDecideResponse, PosthogCoreOptions, PostHogEventProperties, PostHogPersistedProperty, PostHogCaptureOptions, JsonType } from './types';
|
|
2
2
|
import { RetriableOptions } from './utils';
|
|
3
3
|
export * as utils from './utils';
|
|
4
4
|
import { LZString } from './lz-string';
|
|
@@ -12,9 +12,9 @@ export declare abstract class PostHogCoreStateless {
|
|
|
12
12
|
private captureMode;
|
|
13
13
|
private removeDebugCallback?;
|
|
14
14
|
private debugMode;
|
|
15
|
-
private pendingPromises;
|
|
16
15
|
private disableGeoip;
|
|
17
16
|
private _optoutOverride;
|
|
17
|
+
private pendingPromises;
|
|
18
18
|
protected _events: SimpleEventEmitter;
|
|
19
19
|
protected _flushTimer?: any;
|
|
20
20
|
protected _retryOptions: RetriableOptions;
|
|
@@ -32,20 +32,21 @@ export declare abstract class PostHogCoreStateless {
|
|
|
32
32
|
on(event: string, cb: (...args: any[]) => void): () => void;
|
|
33
33
|
debug(enabled?: boolean): void;
|
|
34
34
|
private buildPayload;
|
|
35
|
+
protected addPendingPromise(promise: Promise<any>): void;
|
|
35
36
|
/***
|
|
36
37
|
*** TRACKING
|
|
37
38
|
***/
|
|
38
|
-
protected identifyStateless(distinctId: string, properties?: PostHogEventProperties, options?:
|
|
39
|
+
protected identifyStateless(distinctId: string, properties?: PostHogEventProperties, options?: PostHogCaptureOptions): this;
|
|
39
40
|
protected captureStateless(distinctId: string, event: string, properties?: {
|
|
40
41
|
[key: string]: any;
|
|
41
|
-
}, options?:
|
|
42
|
+
}, options?: PostHogCaptureOptions): this;
|
|
42
43
|
protected aliasStateless(alias: string, distinctId: string, properties?: {
|
|
43
44
|
[key: string]: any;
|
|
44
|
-
}, options?:
|
|
45
|
+
}, options?: PostHogCaptureOptions): this;
|
|
45
46
|
/***
|
|
46
47
|
*** GROUPS
|
|
47
48
|
***/
|
|
48
|
-
protected groupIdentifyStateless(groupType: string, groupKey: string | number, groupProperties?: PostHogEventProperties, options?:
|
|
49
|
+
protected groupIdentifyStateless(groupType: string, groupKey: string | number, groupProperties?: PostHogEventProperties, options?: PostHogCaptureOptions, distinctId?: string, eventProperties?: PostHogEventProperties): this;
|
|
49
50
|
/***
|
|
50
51
|
*** FEATURE FLAGS
|
|
51
52
|
***/
|
|
@@ -62,7 +63,7 @@ export declare abstract class PostHogCoreStateless {
|
|
|
62
63
|
/***
|
|
63
64
|
*** QUEUEING AND FLUSHING
|
|
64
65
|
***/
|
|
65
|
-
protected enqueue(type: string, _message: any, options?:
|
|
66
|
+
protected enqueue(type: string, _message: any, options?: PostHogCaptureOptions): void;
|
|
66
67
|
flushAsync(): Promise<any>;
|
|
67
68
|
flush(callback?: (err?: any, data?: any) => void): void;
|
|
68
69
|
private fetchWithRetry;
|
|
@@ -100,20 +101,20 @@ export declare abstract class PostHogCore extends PostHogCoreStateless {
|
|
|
100
101
|
/***
|
|
101
102
|
*** TRACKING
|
|
102
103
|
***/
|
|
103
|
-
identify(distinctId?: string, properties?: PostHogEventProperties, options?:
|
|
104
|
+
identify(distinctId?: string, properties?: PostHogEventProperties, options?: PostHogCaptureOptions): this;
|
|
104
105
|
capture(event: string, properties?: {
|
|
105
106
|
[key: string]: any;
|
|
106
|
-
}, options?:
|
|
107
|
+
}, options?: PostHogCaptureOptions): this;
|
|
107
108
|
alias(alias: string): this;
|
|
108
|
-
autocapture(eventType: string, elements: PostHogAutocaptureElement[], properties?: PostHogEventProperties, options?:
|
|
109
|
+
autocapture(eventType: string, elements: PostHogAutocaptureElement[], properties?: PostHogEventProperties, options?: PostHogCaptureOptions): this;
|
|
109
110
|
/***
|
|
110
111
|
*** GROUPS
|
|
111
112
|
***/
|
|
112
113
|
groups(groups: {
|
|
113
114
|
[type: string]: string | number;
|
|
114
115
|
}): this;
|
|
115
|
-
group(groupType: string, groupKey: string | number, groupProperties?: PostHogEventProperties, options?:
|
|
116
|
-
groupIdentify(groupType: string, groupKey: string | number, groupProperties?: PostHogEventProperties, options?:
|
|
116
|
+
group(groupType: string, groupKey: string | number, groupProperties?: PostHogEventProperties, options?: PostHogCaptureOptions): this;
|
|
117
|
+
groupIdentify(groupType: string, groupKey: string | number, groupProperties?: PostHogEventProperties, options?: PostHogCaptureOptions): this;
|
|
117
118
|
/***
|
|
118
119
|
* PROPERTIES
|
|
119
120
|
***/
|
|
@@ -45,7 +45,10 @@ export declare type PostHogFetchOptions = {
|
|
|
45
45
|
body?: string;
|
|
46
46
|
signal?: AbortSignal;
|
|
47
47
|
};
|
|
48
|
-
export declare type
|
|
48
|
+
export declare type PostHogCaptureOptions = {
|
|
49
|
+
/** If provided overrides the auto-generated event ID */
|
|
50
|
+
uuid?: string;
|
|
51
|
+
/** If provided overrides the auto-generated timestamp */
|
|
49
52
|
timestamp?: Date;
|
|
50
53
|
disableGeoip?: boolean;
|
|
51
54
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { JsonType, PosthogCoreOptions, PostHogCoreStateless, PostHogFetchOptions, PostHogFetchResponse, PosthogFlagsAndPayloadsResponse, PostHogPersistedProperty } from '../../posthog-core/src';
|
|
2
|
-
import {
|
|
2
|
+
import { EventMessage, GroupIdentifyMessage, IdentifyMessage, PostHogNodeV1 } from './types';
|
|
3
3
|
export declare type PostHogOptions = PosthogCoreOptions & {
|
|
4
4
|
persistence?: 'memory';
|
|
5
5
|
personalApiKey?: string;
|
|
@@ -24,8 +24,8 @@ export declare class PostHog extends PostHogCoreStateless implements PostHogNode
|
|
|
24
24
|
enable(): void;
|
|
25
25
|
disable(): void;
|
|
26
26
|
debug(enabled?: boolean): void;
|
|
27
|
-
capture({ distinctId, event, properties, groups, sendFeatureFlags, timestamp, disableGeoip }:
|
|
28
|
-
identify({ distinctId, properties, disableGeoip }:
|
|
27
|
+
capture({ distinctId, event, properties, groups, sendFeatureFlags, timestamp, disableGeoip, uuid, }: EventMessage): void;
|
|
28
|
+
identify({ distinctId, properties, disableGeoip }: IdentifyMessage): void;
|
|
29
29
|
alias(data: {
|
|
30
30
|
distinctId: string;
|
|
31
31
|
alias: string;
|
|
@@ -73,4 +73,5 @@ export declare class PostHog extends PostHogCoreStateless implements PostHogNode
|
|
|
73
73
|
reloadFeatureFlags(): Promise<void>;
|
|
74
74
|
shutdown(): void;
|
|
75
75
|
shutdownAsync(): Promise<void>;
|
|
76
|
+
private addLocalPersonAndGroupProperties;
|
|
76
77
|
}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { JsonType } from '../../posthog-core/src';
|
|
2
|
-
export interface
|
|
2
|
+
export interface IdentifyMessage {
|
|
3
3
|
distinctId: string;
|
|
4
4
|
properties?: Record<string | number, any>;
|
|
5
5
|
disableGeoip?: boolean;
|
|
6
6
|
}
|
|
7
|
-
export interface
|
|
7
|
+
export interface EventMessage extends IdentifyMessage {
|
|
8
8
|
event: string;
|
|
9
9
|
groups?: Record<string, string | number>;
|
|
10
10
|
sendFeatureFlags?: boolean;
|
|
11
11
|
timestamp?: Date;
|
|
12
|
+
uuid?: string;
|
|
12
13
|
}
|
|
13
14
|
export interface GroupIdentifyMessage {
|
|
14
15
|
groupType: string;
|
|
@@ -67,7 +68,7 @@ export declare type PostHogNodeV1 = {
|
|
|
67
68
|
* @param groups OPTIONAL | object of what groups are related to this event, example: { company: 'id:5' }. Can be used to analyze companies instead of users.
|
|
68
69
|
* @param sendFeatureFlags OPTIONAL | Used with experiments. Determines whether to send feature flag values with the event.
|
|
69
70
|
*/
|
|
70
|
-
capture({ distinctId, event, properties, groups, sendFeatureFlags }:
|
|
71
|
+
capture({ distinctId, event, properties, groups, sendFeatureFlags }: EventMessage): void;
|
|
71
72
|
/**
|
|
72
73
|
* @description Identify lets you add metadata on your users so you can more easily identify who they are in PostHog,
|
|
73
74
|
* and even do things like segment users by these properties.
|
|
@@ -75,7 +76,7 @@ export declare type PostHogNodeV1 = {
|
|
|
75
76
|
* @param distinctId which uniquely identifies your user
|
|
76
77
|
* @param properties with a dict with any key: value pairs
|
|
77
78
|
*/
|
|
78
|
-
identify({ distinctId, properties }:
|
|
79
|
+
identify({ distinctId, properties }: IdentifyMessage): void;
|
|
79
80
|
/**
|
|
80
81
|
* @description To marry up whatever a user does before they sign up or log in with what they do after you need to make an alias call.
|
|
81
82
|
* This will allow you to answer questions like "Which marketing channels leads to users churning after a month?"
|
package/package.json
CHANGED
package/src/feature-flags.ts
CHANGED
|
@@ -121,7 +121,7 @@ class FeatureFlagsPoller {
|
|
|
121
121
|
console.debug(`InconclusiveMatchError when computing flag locally: ${key}: ${e}`)
|
|
122
122
|
}
|
|
123
123
|
} else if (e instanceof Error) {
|
|
124
|
-
|
|
124
|
+
this.onError?.(new Error(`Error computing flag locally: ${key}: ${e}`))
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
127
|
}
|
|
@@ -211,14 +211,18 @@ class FeatureFlagsPoller {
|
|
|
211
211
|
const groupName = this.groupTypeMapping[String(aggregation_group_type_index)]
|
|
212
212
|
|
|
213
213
|
if (!groupName) {
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
214
|
+
if (this.debugMode) {
|
|
215
|
+
console.warn(
|
|
216
|
+
`[FEATURE FLAGS] Unknown group type index ${aggregation_group_type_index} for feature flag ${flag.key}`
|
|
217
|
+
)
|
|
218
|
+
}
|
|
217
219
|
throw new InconclusiveMatchError('Flag has unknown group type index')
|
|
218
220
|
}
|
|
219
221
|
|
|
220
222
|
if (!(groupName in groups)) {
|
|
221
|
-
|
|
223
|
+
if (this.debugMode) {
|
|
224
|
+
console.warn(`[FEATURE FLAGS] Can't compute group feature flag: ${flag.key} without group names passed in`)
|
|
225
|
+
}
|
|
222
226
|
return false
|
|
223
227
|
}
|
|
224
228
|
|
|
@@ -383,7 +387,7 @@ class FeatureFlagsPoller {
|
|
|
383
387
|
|
|
384
388
|
const responseJson = await res.json()
|
|
385
389
|
if (!('flags' in responseJson)) {
|
|
386
|
-
|
|
390
|
+
this.onError?.(new Error(`Invalid response when getting feature flags: ${JSON.stringify(responseJson)}`))
|
|
387
391
|
}
|
|
388
392
|
|
|
389
393
|
this.featureFlags = responseJson.flags || []
|
package/src/posthog-node.ts
CHANGED
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
PostHogPersistedProperty,
|
|
11
11
|
} from '../../posthog-core/src'
|
|
12
12
|
import { PostHogMemoryStorage } from '../../posthog-core/src/storage-memory'
|
|
13
|
-
import {
|
|
13
|
+
import { EventMessage, GroupIdentifyMessage, IdentifyMessage, PostHogNodeV1 } from './types'
|
|
14
14
|
import { FeatureFlagsPoller } from './feature-flags'
|
|
15
15
|
import fetch from './fetch'
|
|
16
16
|
|
|
@@ -100,34 +100,71 @@ export class PostHog extends PostHogCoreStateless implements PostHogNodeV1 {
|
|
|
100
100
|
this.featureFlagsPoller?.debug(enabled)
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
-
capture({
|
|
104
|
-
|
|
105
|
-
|
|
103
|
+
capture({
|
|
104
|
+
distinctId,
|
|
105
|
+
event,
|
|
106
|
+
properties,
|
|
107
|
+
groups,
|
|
108
|
+
sendFeatureFlags,
|
|
109
|
+
timestamp,
|
|
110
|
+
disableGeoip,
|
|
111
|
+
uuid,
|
|
112
|
+
}: EventMessage): void {
|
|
113
|
+
const _capture = (props: EventMessage['properties']): void => {
|
|
114
|
+
super.captureStateless(distinctId, event, props, { timestamp, disableGeoip, uuid })
|
|
106
115
|
}
|
|
107
116
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
117
|
+
// :TRICKY: If we flush, or need to shut down, to not lose events we want this promise to resolve before we flush
|
|
118
|
+
const capturePromise = Promise.resolve()
|
|
119
|
+
.then(async () => {
|
|
120
|
+
if (sendFeatureFlags) {
|
|
121
|
+
// If we are sending feature flags, we need to make sure we have the latest flags
|
|
122
|
+
return await super.getFeatureFlagsStateless(distinctId, groups, undefined, undefined, disableGeoip)
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if ((this.featureFlagsPoller?.featureFlags?.length || 0) > 0) {
|
|
126
|
+
// Otherwise we may as well check for the flags locally and include them if there
|
|
127
|
+
const groupsWithStringValues: Record<string, string> = {}
|
|
128
|
+
for (const [key, value] of Object.entries(groups || {})) {
|
|
129
|
+
groupsWithStringValues[key] = String(value)
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return await this.getAllFlags(distinctId, {
|
|
133
|
+
groups: groupsWithStringValues,
|
|
134
|
+
disableGeoip,
|
|
135
|
+
onlyEvaluateLocally: true,
|
|
136
|
+
})
|
|
137
|
+
}
|
|
138
|
+
return {}
|
|
139
|
+
})
|
|
140
|
+
.then((flags) => {
|
|
141
|
+
// Derive the relevant flag properties to add
|
|
142
|
+
const additionalProperties: Record<string, any> = {}
|
|
111
143
|
if (flags) {
|
|
112
144
|
for (const [feature, variant] of Object.entries(flags)) {
|
|
113
|
-
|
|
114
|
-
featureVariantProperties[`$feature/${feature}`] = variant
|
|
115
|
-
}
|
|
145
|
+
additionalProperties[`$feature/${feature}`] = variant
|
|
116
146
|
}
|
|
117
147
|
}
|
|
118
148
|
const activeFlags = Object.keys(flags || {}).filter((flag) => flags?.[flag] !== false)
|
|
119
|
-
|
|
120
|
-
$active_feature_flags
|
|
121
|
-
...featureVariantProperties,
|
|
149
|
+
if (activeFlags.length > 0) {
|
|
150
|
+
additionalProperties['$active_feature_flags'] = activeFlags
|
|
122
151
|
}
|
|
123
|
-
|
|
152
|
+
|
|
153
|
+
return additionalProperties
|
|
124
154
|
})
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
155
|
+
.catch(() => {
|
|
156
|
+
// Something went wrong getting the flag info - we should capture the event anyways
|
|
157
|
+
return {}
|
|
158
|
+
})
|
|
159
|
+
.then((additionalProperties) => {
|
|
160
|
+
// No matter what - capture the event
|
|
161
|
+
_capture({ ...additionalProperties, ...properties, $groups: groups })
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
this.addPendingPromise(capturePromise)
|
|
128
165
|
}
|
|
129
166
|
|
|
130
|
-
identify({ distinctId, properties, disableGeoip }:
|
|
167
|
+
identify({ distinctId, properties, disableGeoip }: IdentifyMessage): void {
|
|
131
168
|
// Catch properties passed as $set and move them to the top level
|
|
132
169
|
const personProperties = properties?.$set || properties
|
|
133
170
|
|
|
@@ -156,8 +193,18 @@ export class PostHog extends PostHogCoreStateless implements PostHogNodeV1 {
|
|
|
156
193
|
disableGeoip?: boolean
|
|
157
194
|
}
|
|
158
195
|
): Promise<string | boolean | undefined> {
|
|
159
|
-
const { groups,
|
|
160
|
-
let { onlyEvaluateLocally, sendFeatureFlagEvents } = options || {}
|
|
196
|
+
const { groups, disableGeoip } = options || {}
|
|
197
|
+
let { onlyEvaluateLocally, sendFeatureFlagEvents, personProperties, groupProperties } = options || {}
|
|
198
|
+
|
|
199
|
+
const adjustedProperties = this.addLocalPersonAndGroupProperties(
|
|
200
|
+
distinctId,
|
|
201
|
+
groups,
|
|
202
|
+
personProperties,
|
|
203
|
+
groupProperties
|
|
204
|
+
)
|
|
205
|
+
|
|
206
|
+
personProperties = adjustedProperties.allPersonProperties
|
|
207
|
+
groupProperties = adjustedProperties.allGroupProperties
|
|
161
208
|
|
|
162
209
|
// set defaults
|
|
163
210
|
if (onlyEvaluateLocally == undefined) {
|
|
@@ -232,8 +279,19 @@ export class PostHog extends PostHogCoreStateless implements PostHogNodeV1 {
|
|
|
232
279
|
disableGeoip?: boolean
|
|
233
280
|
}
|
|
234
281
|
): Promise<JsonType | undefined> {
|
|
235
|
-
const { groups,
|
|
236
|
-
let { onlyEvaluateLocally, sendFeatureFlagEvents } = options || {}
|
|
282
|
+
const { groups, disableGeoip } = options || {}
|
|
283
|
+
let { onlyEvaluateLocally, sendFeatureFlagEvents, personProperties, groupProperties } = options || {}
|
|
284
|
+
|
|
285
|
+
const adjustedProperties = this.addLocalPersonAndGroupProperties(
|
|
286
|
+
distinctId,
|
|
287
|
+
groups,
|
|
288
|
+
personProperties,
|
|
289
|
+
groupProperties
|
|
290
|
+
)
|
|
291
|
+
|
|
292
|
+
personProperties = adjustedProperties.allPersonProperties
|
|
293
|
+
groupProperties = adjustedProperties.allGroupProperties
|
|
294
|
+
|
|
237
295
|
let response = undefined
|
|
238
296
|
|
|
239
297
|
// Try to get match value locally if not provided
|
|
@@ -324,8 +382,18 @@ export class PostHog extends PostHogCoreStateless implements PostHogNodeV1 {
|
|
|
324
382
|
disableGeoip?: boolean
|
|
325
383
|
}
|
|
326
384
|
): Promise<PosthogFlagsAndPayloadsResponse> {
|
|
327
|
-
const { groups,
|
|
328
|
-
let { onlyEvaluateLocally } = options || {}
|
|
385
|
+
const { groups, disableGeoip } = options || {}
|
|
386
|
+
let { onlyEvaluateLocally, personProperties, groupProperties } = options || {}
|
|
387
|
+
|
|
388
|
+
const adjustedProperties = this.addLocalPersonAndGroupProperties(
|
|
389
|
+
distinctId,
|
|
390
|
+
groups,
|
|
391
|
+
personProperties,
|
|
392
|
+
groupProperties
|
|
393
|
+
)
|
|
394
|
+
|
|
395
|
+
personProperties = adjustedProperties.allPersonProperties
|
|
396
|
+
groupProperties = adjustedProperties.allGroupProperties
|
|
329
397
|
|
|
330
398
|
// set defaults
|
|
331
399
|
if (onlyEvaluateLocally == undefined) {
|
|
@@ -385,4 +453,25 @@ export class PostHog extends PostHogCoreStateless implements PostHogNodeV1 {
|
|
|
385
453
|
this.featureFlagsPoller?.stopPoller()
|
|
386
454
|
return super.shutdownAsync()
|
|
387
455
|
}
|
|
456
|
+
|
|
457
|
+
private addLocalPersonAndGroupProperties(
|
|
458
|
+
distinctId: string,
|
|
459
|
+
groups?: Record<string, string>,
|
|
460
|
+
personProperties?: Record<string, string>,
|
|
461
|
+
groupProperties?: Record<string, Record<string, string>>
|
|
462
|
+
): { allPersonProperties: Record<string, string>; allGroupProperties: Record<string, Record<string, string>> } {
|
|
463
|
+
const allPersonProperties = { $current_distinct_id: distinctId, ...(personProperties || {}) }
|
|
464
|
+
|
|
465
|
+
const allGroupProperties: Record<string, Record<string, string>> = {}
|
|
466
|
+
if (groups) {
|
|
467
|
+
for (const groupName of Object.keys(groups)) {
|
|
468
|
+
allGroupProperties[groupName] = {
|
|
469
|
+
$group_key: groups[groupName],
|
|
470
|
+
...(groupProperties?.[groupName] || {}),
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
return { allPersonProperties, allGroupProperties }
|
|
476
|
+
}
|
|
388
477
|
}
|
package/src/types.ts
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { JsonType } from '../../posthog-core/src'
|
|
2
2
|
|
|
3
|
-
export interface
|
|
3
|
+
export interface IdentifyMessage {
|
|
4
4
|
distinctId: string
|
|
5
5
|
properties?: Record<string | number, any>
|
|
6
6
|
disableGeoip?: boolean
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
export interface
|
|
9
|
+
export interface EventMessage extends IdentifyMessage {
|
|
10
10
|
event: string
|
|
11
11
|
groups?: Record<string, string | number> // Mapping of group type to group id
|
|
12
12
|
sendFeatureFlags?: boolean
|
|
13
13
|
timestamp?: Date
|
|
14
|
+
uuid?: string
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
export interface GroupIdentifyMessage {
|
|
@@ -75,7 +76,7 @@ export type PostHogNodeV1 = {
|
|
|
75
76
|
* @param groups OPTIONAL | object of what groups are related to this event, example: { company: 'id:5' }. Can be used to analyze companies instead of users.
|
|
76
77
|
* @param sendFeatureFlags OPTIONAL | Used with experiments. Determines whether to send feature flag values with the event.
|
|
77
78
|
*/
|
|
78
|
-
capture({ distinctId, event, properties, groups, sendFeatureFlags }:
|
|
79
|
+
capture({ distinctId, event, properties, groups, sendFeatureFlags }: EventMessage): void
|
|
79
80
|
|
|
80
81
|
/**
|
|
81
82
|
* @description Identify lets you add metadata on your users so you can more easily identify who they are in PostHog,
|
|
@@ -84,7 +85,7 @@ export type PostHogNodeV1 = {
|
|
|
84
85
|
* @param distinctId which uniquely identifies your user
|
|
85
86
|
* @param properties with a dict with any key: value pairs
|
|
86
87
|
*/
|
|
87
|
-
identify({ distinctId, properties }:
|
|
88
|
+
identify({ distinctId, properties }: IdentifyMessage): void
|
|
88
89
|
|
|
89
90
|
/**
|
|
90
91
|
* @description To marry up whatever a user does before they sign up or log in with what they do after you need to make an alias call.
|
|
@@ -3,6 +3,7 @@ import { PostHog as PostHog } from '../../src/posthog-node'
|
|
|
3
3
|
import { PostHogSentryIntegration } from '../../src/extensions/sentry-integration'
|
|
4
4
|
jest.mock('../../src/fetch')
|
|
5
5
|
import fetch from '../../src/fetch'
|
|
6
|
+
import { waitForPromises } from 'posthog-core/test/test-utils/test-utils'
|
|
6
7
|
|
|
7
8
|
jest.mock('../../package.json', () => ({ version: '1.2.3' }))
|
|
8
9
|
|
|
@@ -108,6 +109,7 @@ describe('PostHogSentryIntegration', () => {
|
|
|
108
109
|
|
|
109
110
|
processorFunction(createMockSentryException())
|
|
110
111
|
|
|
112
|
+
await waitForPromises()
|
|
111
113
|
jest.runOnlyPendingTimers()
|
|
112
114
|
const batchEvents = getLastBatchEvents()
|
|
113
115
|
|
|
@@ -144,6 +146,7 @@ describe('PostHogSentryIntegration', () => {
|
|
|
144
146
|
library: 'posthog-node',
|
|
145
147
|
library_version: '1.2.3',
|
|
146
148
|
timestamp: expect.any(String),
|
|
149
|
+
uuid: expect.any(String),
|
|
147
150
|
},
|
|
148
151
|
])
|
|
149
152
|
})
|
|
@@ -50,6 +50,17 @@ export const apiImplementation = ({
|
|
|
50
50
|
}) as any
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
+
if ((url as any).includes('batch/')) {
|
|
54
|
+
return Promise.resolve({
|
|
55
|
+
status: 200,
|
|
56
|
+
text: () => Promise.resolve('ok'),
|
|
57
|
+
json: () =>
|
|
58
|
+
Promise.resolve({
|
|
59
|
+
status: 'ok',
|
|
60
|
+
}),
|
|
61
|
+
}) as any
|
|
62
|
+
}
|
|
63
|
+
|
|
53
64
|
return Promise.resolve({
|
|
54
65
|
status: 400,
|
|
55
66
|
text: () => Promise.resolve('ok'),
|
|
@@ -342,7 +353,11 @@ describe('local evaluation', () => {
|
|
|
342
353
|
token: 'TEST_API_KEY',
|
|
343
354
|
distinct_id: 'some-distinct-id_outside_rollout?',
|
|
344
355
|
groups: {},
|
|
345
|
-
person_properties: {
|
|
356
|
+
person_properties: {
|
|
357
|
+
$current_distinct_id: 'some-distinct-id_outside_rollout?',
|
|
358
|
+
region: 'USA',
|
|
359
|
+
email: 'a@b.com',
|
|
360
|
+
},
|
|
346
361
|
group_properties: {},
|
|
347
362
|
geoip_disable: true,
|
|
348
363
|
}),
|
|
@@ -361,7 +376,7 @@ describe('local evaluation', () => {
|
|
|
361
376
|
token: 'TEST_API_KEY',
|
|
362
377
|
distinct_id: 'some-distinct-id',
|
|
363
378
|
groups: {},
|
|
364
|
-
person_properties: { doesnt_matter: '1' },
|
|
379
|
+
person_properties: { $current_distinct_id: 'some-distinct-id', doesnt_matter: '1' },
|
|
365
380
|
group_properties: {},
|
|
366
381
|
geoip_disable: true,
|
|
367
382
|
}),
|