posthog-node 2.3.0 → 2.4.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 -1
- package/lib/index.cjs.js +31 -30
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +3 -4
- package/lib/index.esm.js +31 -30
- package/lib/index.esm.js.map +1 -1
- package/lib/posthog-core/src/index.d.ts +6 -9
- package/lib/posthog-core/src/types.d.ts +3 -0
- package/lib/posthog-node/src/posthog-node.d.ts +1 -1
- package/lib/posthog-node/src/types.d.ts +2 -1
- package/package.json +1 -1
- package/src/posthog-node.ts +13 -2
- package/src/types.ts +2 -1
- package/test/posthog-node.spec.ts +14 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PostHogFetchOptions, PostHogFetchResponse, PostHogAutocaptureElement, PostHogDecideResponse, PosthogCoreOptions, PostHogEventProperties, PostHogPersistedProperty, JsonType } from './types';
|
|
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';
|
|
@@ -50,20 +50,20 @@ export declare abstract class PostHogCore {
|
|
|
50
50
|
/***
|
|
51
51
|
*** TRACKING
|
|
52
52
|
***/
|
|
53
|
-
identify(distinctId?: string, properties?: PostHogEventProperties): this;
|
|
53
|
+
identify(distinctId?: string, properties?: PostHogEventProperties, options?: PosthogCaptureOptions): this;
|
|
54
54
|
capture(event: string, properties?: {
|
|
55
55
|
[key: string]: any;
|
|
56
|
-
},
|
|
56
|
+
}, options?: PosthogCaptureOptions): this;
|
|
57
57
|
alias(alias: string): this;
|
|
58
|
-
autocapture(eventType: string, elements: PostHogAutocaptureElement[], properties?: PostHogEventProperties): this;
|
|
58
|
+
autocapture(eventType: string, elements: PostHogAutocaptureElement[], properties?: PostHogEventProperties, options?: PosthogCaptureOptions): this;
|
|
59
59
|
/***
|
|
60
60
|
*** GROUPS
|
|
61
61
|
***/
|
|
62
62
|
groups(groups: {
|
|
63
63
|
[type: string]: string | number;
|
|
64
64
|
}): this;
|
|
65
|
-
group(groupType: string, groupKey: string | number, groupProperties?: PostHogEventProperties): this;
|
|
66
|
-
groupIdentify(groupType: string, groupKey: string | number, groupProperties?: PostHogEventProperties): this;
|
|
65
|
+
group(groupType: string, groupKey: string | number, groupProperties?: PostHogEventProperties, options?: PosthogCaptureOptions): this;
|
|
66
|
+
groupIdentify(groupType: string, groupKey: string | number, groupProperties?: PostHogEventProperties, options?: PosthogCaptureOptions): this;
|
|
67
67
|
/***
|
|
68
68
|
* PROPERTIES
|
|
69
69
|
***/
|
|
@@ -94,9 +94,6 @@ export declare abstract class PostHogCore {
|
|
|
94
94
|
onFeatureFlags(cb: (flags: PostHogDecideResponse['featureFlags']) => void): () => void;
|
|
95
95
|
onFeatureFlag(key: string, cb: (value: string | boolean) => void): () => void;
|
|
96
96
|
overrideFeatureFlag(flags: PostHogDecideResponse['featureFlags'] | null): void;
|
|
97
|
-
_sendFeatureFlags(event: string, properties?: {
|
|
98
|
-
[key: string]: any;
|
|
99
|
-
}): void;
|
|
100
97
|
/***
|
|
101
98
|
*** QUEUEING AND FLUSHING
|
|
102
99
|
***/
|
|
@@ -42,6 +42,9 @@ export declare type PostHogFetchOptions = {
|
|
|
42
42
|
body?: string;
|
|
43
43
|
signal?: AbortSignal;
|
|
44
44
|
};
|
|
45
|
+
export declare type PosthogCaptureOptions = {
|
|
46
|
+
timestamp?: Date;
|
|
47
|
+
};
|
|
45
48
|
export declare type PostHogFetchResponse = {
|
|
46
49
|
status: number;
|
|
47
50
|
text: () => Promise<string>;
|
|
@@ -17,7 +17,7 @@ export declare class PostHog implements PostHogNodeV1 {
|
|
|
17
17
|
private reInit;
|
|
18
18
|
enable(): void;
|
|
19
19
|
disable(): void;
|
|
20
|
-
capture({ distinctId, event, properties, groups, sendFeatureFlags }: EventMessageV1): void;
|
|
20
|
+
capture({ distinctId, event, properties, groups, sendFeatureFlags, timestamp }: EventMessageV1): void;
|
|
21
21
|
identify({ distinctId, properties }: IdentifyMessageV1): void;
|
|
22
22
|
alias(data: {
|
|
23
23
|
distinctId: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { JsonType } from 'posthog-core/src';
|
|
1
|
+
import { JsonType } from '../../posthog-core/src';
|
|
2
2
|
export interface IdentifyMessageV1 {
|
|
3
3
|
distinctId: string;
|
|
4
4
|
properties?: Record<string | number, any>;
|
|
@@ -7,6 +7,7 @@ export interface EventMessageV1 extends IdentifyMessageV1 {
|
|
|
7
7
|
event: string;
|
|
8
8
|
groups?: Record<string, string | number>;
|
|
9
9
|
sendFeatureFlags?: boolean;
|
|
10
|
+
timestamp?: Date;
|
|
10
11
|
}
|
|
11
12
|
export interface GroupIdentifyMessage {
|
|
12
13
|
groupType: string;
|
package/package.json
CHANGED
package/src/posthog-node.ts
CHANGED
|
@@ -109,12 +109,23 @@ export class PostHog implements PostHogNodeV1 {
|
|
|
109
109
|
return this._sharedClient.optOut()
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
-
capture({ distinctId, event, properties, groups, sendFeatureFlags }: EventMessageV1): void {
|
|
112
|
+
capture({ distinctId, event, properties, groups, sendFeatureFlags, timestamp }: EventMessageV1): void {
|
|
113
113
|
this.reInit(distinctId)
|
|
114
114
|
if (groups) {
|
|
115
115
|
this._sharedClient.groups(groups)
|
|
116
116
|
}
|
|
117
|
-
|
|
117
|
+
|
|
118
|
+
const _capture = (): void => {
|
|
119
|
+
this._sharedClient.capture(event, properties, { timestamp })
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (sendFeatureFlags) {
|
|
123
|
+
this._sharedClient.reloadFeatureFlagsAsync(false).finally(() => {
|
|
124
|
+
_capture()
|
|
125
|
+
})
|
|
126
|
+
} else {
|
|
127
|
+
_capture()
|
|
128
|
+
}
|
|
118
129
|
}
|
|
119
130
|
|
|
120
131
|
identify({ distinctId, properties }: IdentifyMessageV1): void {
|
package/src/types.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { JsonType } from 'posthog-core/src'
|
|
1
|
+
import { JsonType } from '../../posthog-core/src'
|
|
2
2
|
|
|
3
3
|
export interface IdentifyMessageV1 {
|
|
4
4
|
distinctId: string
|
|
@@ -9,6 +9,7 @@ export interface EventMessageV1 extends IdentifyMessageV1 {
|
|
|
9
9
|
event: string
|
|
10
10
|
groups?: Record<string, string | number> // Mapping of group type to group id
|
|
11
11
|
sendFeatureFlags?: boolean
|
|
12
|
+
timestamp?: Date
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
export interface GroupIdentifyMessage {
|
|
@@ -136,6 +136,20 @@ describe('PostHog Node.js', () => {
|
|
|
136
136
|
},
|
|
137
137
|
])
|
|
138
138
|
})
|
|
139
|
+
|
|
140
|
+
it('should allow overriding timestamp', async () => {
|
|
141
|
+
expect(mockedFetch).toHaveBeenCalledTimes(0)
|
|
142
|
+
posthog.capture({ event: 'custom-time', distinctId: '123', timestamp: new Date('2021-02-03') })
|
|
143
|
+
jest.runOnlyPendingTimers()
|
|
144
|
+
const batchEvents = getLastBatchEvents()
|
|
145
|
+
expect(batchEvents).toMatchObject([
|
|
146
|
+
{
|
|
147
|
+
distinct_id: '123',
|
|
148
|
+
timestamp: '2021-02-03T00:00:00.000Z',
|
|
149
|
+
event: 'custom-time',
|
|
150
|
+
},
|
|
151
|
+
])
|
|
152
|
+
})
|
|
139
153
|
})
|
|
140
154
|
|
|
141
155
|
describe('groupIdentify', () => {
|