Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(managed-migrations): single project secret field for mixpanel (#62975)

Paweł Ledwoń9c2173c2658e
diff --git a/products/managed_migrations/backend/api/batch_imports.py b/products/managed_migrations/backend/api/batch_imports.py
index bd23cffeda30..3dcf5b162bc8 100644
--- a/products/managed_migrations/backend/api/batch_imports.py
+++ b/products/managed_migrations/backend/api/batch_imports.py
@@ -293,8 +293,18 @@ class BatchImportDateRangeSourceCreateSerializer(BatchImportSerializer):
write_only=True,
required=True,
)
- access_key = serializers.CharField(write_only=True, required=True)
- secret_key = serializers.CharField(write_only=True, required=True)
+ access_key = serializers.CharField(
+ write_only=True,
+ required=False,
+ allow_blank=True,
+ default="",
+ help_text="Source access key / API key. Required for Amplitude; unused for Mixpanel, which authenticates with the project secret alone.",
+ )
+ secret_key = serializers.CharField(
+ write_only=True,
+ required=True,
+ help_text="Source secret. For Mixpanel this is the project API secret, found under Project settings → Access keys.",
+ )
is_eu_region = serializers.BooleanField(write_only=True, required=False, default=False)
import_events = serializers.BooleanField(write_only=True, required=False, default=True)
generate_identify_events = serializers.BooleanField(write_only=True, required=False, default=True)
@@ -354,9 +364,12 @@ class BatchImportDateRangeSourceCreateSerializer(BatchImportSerializer):
if source_type == "amplitude" and (end_date - start_date) < timedelta(hours=1):
raise serializers.ValidationError("Date range must be at least 1 hour for Amplitude migrations.")
- # For Amplitude, ensure at least one of import_events or generate_identify_events is enabled
+ # For Amplitude, validate required fields and event-type selection
source_type = data.get("source_type")
if source_type == "amplitude":
+ if not data.get("access_key"):
+ raise serializers.ValidationError("Access key is required for Amplitude migrations.")
+
import_events = data.get("import_events", True)
generate_identify_events = data.get("generate_identify_events", True)
diff --git a/products/managed_migrations/frontend/ManagedMigration.tsx b/products/managed_migrations/frontend/ManagedMigration.tsx
index 5e8bc04d932e..2ea567a0d88b 100644
--- a/products/managed_migrations/frontend/ManagedMigration.tsx
+++ b/products/managed_migrations/frontend/ManagedMigration.tsx
@@ -2,7 +2,7 @@ import { useActions, useValues } from 'kea'
import { Form } from 'kea-forms'
import { IconSort } from '@posthog/icons'
-import { LemonButton, LemonTable, LemonTag } from '@posthog/lemon-ui'
+import { LemonButton, LemonTable, LemonTag, Link } from '@posthog/lemon-ui'
import { FlaggedFeature } from 'lib/components/FlaggedFeature'
import { TZLabel } from 'lib/components/TZLabel'
@@ -237,15 +237,36 @@ export function ManagedMigration(): JSX.Element {
/>
)}
- <div className="flex gap-4">
- <LemonField name="access_key" label="Access Key ID" className="flex-1">
+ {managedMigration.source_type === 'mixpanel' ? (
+ <LemonField
+ name="secret_key"
+ label="Project secret"
+ help={
+ <span>
+ Find this under Project settings → Access keys in Mixpanel. See{' '}
+ <Link
+ to="https://docs.mixpanel.com/docs/orgs-and-projects/managing-projects#access-keys"
+ target="_blank"
+ >
+ Mixpanel's docs
+ </Link>
+ .
+ </span>
+ }
+ >
<LemonInput type="password" />
</LemonField>
+ ) : (
+ <div className="flex gap-4">
+ <LemonField name="access_key" label="Access Key ID" className="flex-1">
+ <LemonInput type="password" />
+ </LemonField>
- <LemonField name="secret_key" label="Secret Access Key" className="flex-1">
- <LemonInput type="password" />
- </LemonField>
- </div>
+ <LemonField name="secret_key" label="Secret Access Key" className="flex-1">
+ <LemonInput type="password" />
+ </LemonField>
+ </div>
+ )}
<div className="flex justify-end">
<LemonButton type="primary" htmlType="submit">
diff --git a/products/managed_migrations/frontend/managedMigrationLogic.ts b/products/managed_migrations/frontend/managedMigrationLogic.ts
index 233b2a074301..7126579ef27e 100644
--- a/products/managed_migrations/frontend/managedMigrationLogic.ts
+++ b/products/managed_migrations/frontend/managedMigrationLogic.ts
@@ -98,8 +98,16 @@ export const managedMigrationLogic = kea<managedMigrationLogicType>([
generate_group_identify_events,
}: ManagedMigrationForm) => {
const errors: Record<string, string | null> = {
- access_key: !access_key ? 'Access key is required' : null,
- secret_key: !secret_key ? 'Secret key is required' : null,
+ secret_key: !secret_key
+ ? source_type === 'mixpanel'
+ ? 'Project secret is required'
+ : 'Secret key is required'
+ : null,
+ }
+
+ // Mixpanel authenticates with the project secret alone — no access key.
+ if (source_type !== 'mixpanel') {
+ errors.access_key = !access_key ? 'Access key is required' : null
}
if (source_type === 's3' || source_type === 's3_gzip') {