From 418da1ba8b3a6639921f3f85e214d46f0fedb305 Mon Sep 17 00:00:00 2001 From: Ben White Date: Mon, 26 Aug 2024 13:53:22 +0100 Subject: [PATCH 1/2] Added flag for historical migration --- posthog-core/src/index.ts | 8 +++++++- posthog-core/src/types.ts | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/posthog-core/src/index.ts b/posthog-core/src/index.ts index 2a49f266..edf9032f 100644 --- a/posthog-core/src/index.ts +++ b/posthog-core/src/index.ts @@ -61,6 +61,7 @@ export abstract class PostHogCoreStateless { private captureMode: 'form' | 'json' private removeDebugCallback?: () => void private disableGeoip: boolean = true + private historicalMigration: boolean = false public disabled = false private defaultOptIn: boolean = true @@ -106,6 +107,7 @@ export abstract class PostHogCoreStateless { this.featureFlagsRequestTimeoutMs = options?.featureFlagsRequestTimeoutMs ?? 3000 // 3 seconds this.disableGeoip = options?.disableGeoip ?? true this.disabled = options?.disabled ?? false + this.historicalMigration = options?.historicalMigration ?? false // Init promise allows the derived class to block calls until it is ready this._initPromise = Promise.resolve() this._isInitialized = true @@ -573,12 +575,16 @@ export abstract class PostHogCoreStateless { this.setPersistedProperty(PostHogPersistedProperty.Queue, refreshedQueue.slice(items.length)) } - const data = { + const data: Record = { api_key: this.apiKey, batch: messages, sent_at: currentISOTime(), } + if (this.historicalMigration) { + data.historical_migration = true + } + const payload = JSON.stringify(data) const url = diff --git a/posthog-core/src/types.ts b/posthog-core/src/types.ts index 1bcf5caa..7dc09816 100644 --- a/posthog-core/src/types.ts +++ b/posthog-core/src/types.ts @@ -39,6 +39,8 @@ export type PostHogCoreOptions = { /** Whether to post events to PostHog in JSON or compressed format. Defaults to 'form' */ captureMode?: 'json' | 'form' disableGeoip?: boolean + /** Special flag to indicate ingested data is for a historical migration. */ + historicalMigration?: boolean } export enum PostHogPersistedProperty { From 697f33e0ee8a263b15d6d022454947d29d23da23 Mon Sep 17 00:00:00 2001 From: Ben White Date: Mon, 26 Aug 2024 13:54:41 +0100 Subject: [PATCH 2/2] Updated packages --- posthog-node/CHANGELOG.md | 5 +++++ posthog-node/package.json | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/posthog-node/CHANGELOG.md b/posthog-node/CHANGELOG.md index a09d5c73..a3385f24 100644 --- a/posthog-node/CHANGELOG.md +++ b/posthog-node/CHANGELOG.md @@ -1,8 +1,13 @@ # Next +# 4.2.0 - 2024-08-26 + +1. Added `historicalMigration` option for use in tools that are migrating large data to PostHog + # 4.1.1 - 2024-08-20 1. Local evaluation returns correct results on `undefined/null` values + # 4.1.0 - 2024-08-14 1. chore: change host to new address. diff --git a/posthog-node/package.json b/posthog-node/package.json index d029dc2e..ad304d43 100644 --- a/posthog-node/package.json +++ b/posthog-node/package.json @@ -1,6 +1,6 @@ { "name": "posthog-node", - "version": "4.1.1", + "version": "4.2.0", "description": "PostHog Node.js integration", "repository": { "type": "git",