posthog-node 4.2.2 → 4.2.3
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 +4 -0
- package/lib/index.cjs.js +9 -4
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.esm.js +9 -4
- package/lib/index.esm.js.map +1 -1
- package/lib/posthog-core/src/index.d.ts +1 -1
- package/package.json +1 -1
- package/src/posthog-node.ts +9 -2
- package/test/posthog-node.spec.ts +29 -3
|
@@ -6,7 +6,7 @@ import { SimpleEventEmitter } from './eventemitter';
|
|
|
6
6
|
export declare abstract class PostHogCoreStateless {
|
|
7
7
|
readonly apiKey: string;
|
|
8
8
|
readonly host: string;
|
|
9
|
-
|
|
9
|
+
readonly flushAt: number;
|
|
10
10
|
private maxBatchSize;
|
|
11
11
|
private maxQueueSize;
|
|
12
12
|
private flushInterval;
|
package/package.json
CHANGED
package/src/posthog-node.ts
CHANGED
|
@@ -174,12 +174,19 @@ export class PostHog extends PostHogCoreStateless implements PostHogNodeV1 {
|
|
|
174
174
|
|
|
175
175
|
identify({ distinctId, properties, disableGeoip }: IdentifyMessage): void {
|
|
176
176
|
// Catch properties passed as $set and move them to the top level
|
|
177
|
-
|
|
177
|
+
|
|
178
|
+
// promote $set and $set_once to top level
|
|
179
|
+
const userPropsOnce = properties?.$set_once
|
|
180
|
+
delete properties?.$set_once
|
|
181
|
+
|
|
182
|
+
// if no $set is provided we assume all properties are $set
|
|
183
|
+
const userProps = properties?.$set || properties
|
|
178
184
|
|
|
179
185
|
super.identifyStateless(
|
|
180
186
|
distinctId,
|
|
181
187
|
{
|
|
182
|
-
$set:
|
|
188
|
+
$set: userProps,
|
|
189
|
+
$set_once: userPropsOnce,
|
|
183
190
|
},
|
|
184
191
|
{ disableGeoip }
|
|
185
192
|
)
|
|
@@ -154,9 +154,9 @@ describe('PostHog Node.js', () => {
|
|
|
154
154
|
])
|
|
155
155
|
})
|
|
156
156
|
|
|
157
|
-
it('should handle identify
|
|
157
|
+
it('should handle identify using $set and $set_once', async () => {
|
|
158
158
|
expect(mockedFetch).toHaveBeenCalledTimes(0)
|
|
159
|
-
posthog.identify({ distinctId: '123', properties: { foo: 'bar', $
|
|
159
|
+
posthog.identify({ distinctId: '123', properties: { $set: { foo: 'bar' }, $set_once: { vip: true } } })
|
|
160
160
|
jest.runOnlyPendingTimers()
|
|
161
161
|
await waitForPromises()
|
|
162
162
|
const batchEvents = getLastBatchEvents()
|
|
@@ -166,7 +166,33 @@ describe('PostHog Node.js', () => {
|
|
|
166
166
|
event: '$identify',
|
|
167
167
|
properties: {
|
|
168
168
|
$set: {
|
|
169
|
-
foo: '
|
|
169
|
+
foo: 'bar',
|
|
170
|
+
},
|
|
171
|
+
$set_once: {
|
|
172
|
+
vip: true,
|
|
173
|
+
},
|
|
174
|
+
$geoip_disable: true,
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
])
|
|
178
|
+
})
|
|
179
|
+
|
|
180
|
+
it('should handle identify using $set_once', async () => {
|
|
181
|
+
expect(mockedFetch).toHaveBeenCalledTimes(0)
|
|
182
|
+
posthog.identify({ distinctId: '123', properties: { foo: 'bar', $set_once: { vip: true } } })
|
|
183
|
+
jest.runOnlyPendingTimers()
|
|
184
|
+
await waitForPromises()
|
|
185
|
+
const batchEvents = getLastBatchEvents()
|
|
186
|
+
expect(batchEvents).toMatchObject([
|
|
187
|
+
{
|
|
188
|
+
distinct_id: '123',
|
|
189
|
+
event: '$identify',
|
|
190
|
+
properties: {
|
|
191
|
+
$set: {
|
|
192
|
+
foo: 'bar',
|
|
193
|
+
},
|
|
194
|
+
$set_once: {
|
|
195
|
+
vip: true,
|
|
170
196
|
},
|
|
171
197
|
$geoip_disable: true,
|
|
172
198
|
},
|