Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added historical migration option #251

Merged
merged 2 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion posthog-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -573,12 +575,16 @@ export abstract class PostHogCoreStateless {
this.setPersistedProperty<PostHogQueueItem[]>(PostHogPersistedProperty.Queue, refreshedQueue.slice(items.length))
}

const data = {
const data: Record<string, any> = {
api_key: this.apiKey,
batch: messages,
sent_at: currentISOTime(),
}

if (this.historicalMigration) {
data.historical_migration = true
}

const payload = JSON.stringify(data)

const url =
Expand Down
2 changes: 2 additions & 0 deletions posthog-core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions posthog-node/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
2 changes: 1 addition & 1 deletion posthog-node/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "posthog-node",
"version": "4.1.1",
"version": "4.2.0",
"description": "PostHog Node.js integration",
"repository": {
"type": "git",
Expand Down