PostHog कनेक्टर
data-driven marketing campaigns और personalized customer engagement के लिए product analytics data, user behavior events, और cohort memberships sync करने हेतु Tajo के माध्यम से PostHog को Brevo से कनेक्ट करें।
अवलोकन
| Property | Value |
|---|---|
| Platform | PostHog |
| Category | Product Analytics (Custom) |
| Setup Complexity | Medium |
| Official Integration | No |
| Data Synced | Events, Persons, Feature Flags, Cohorts |
| Auth Method | Personal API Key / Project Token |
विशेषताएं
- Event sync - behavioral targeting के लिए PostHog analytics events को Brevo में forward करें
- Person profile sync - PostHog person properties को Brevo contact attributes से sync करें
- Cohort-आधारित segmentation - PostHog cohorts को Brevo contact lists से map करें
- Feature flag sync - enabled feature flags द्वारा contacts segment करें
- Funnel data - targeted re-engagement के लिए conversion funnel data का उपयोग करें
- Session replay metadata - session engagement metrics के साथ contacts को समृद्ध करें
पूर्वावश्यकताएं
शुरू करने से पहले, सुनिश्चित करें कि आपके पास हैं:
- एक PostHog account (Cloud या self-hosted)
- PostHog Settings से एक Personal API Key
- Project Settings से आपकी Project API Key (token)
- API access वाला एक Brevo account
- connector permissions वाला एक Tajo account
प्रमाणीकरण
Personal API Key (Private Endpoints)
# https://app.posthog.com/settings/user-api-keys पर generate करेंexport POSTHOG_PERSONAL_API_KEY=phx_your_personal_api_keyexport POSTHOG_PROJECT_TOKEN=phc_your_project_tokenexport POSTHOG_HOST=https://us.posthog.com # or https://eu.posthog.comexport TAJO_API_KEY=your_tajo_api_keyexport BREVO_API_KEY=your_brevo_api_key// Private API endpoints Bearer authentication का उपयोग करते हैंconst headers = { 'Authorization': `Bearer ${process.env.POSTHOG_PERSONAL_API_KEY}`, 'Content-Type': 'application/json'};
// Public endpoints project token का उपयोग करते हैंconst publicHeaders = { 'Content-Type': 'application/json'};// Public endpoints के लिए Token request body में pass होता हैAPI Key Security
Personal API keys पूर्ण account access प्रदान करती हैं। उन्हें कभी भी client-side code में expose न करें। event capture और feature flag evaluation जैसे public endpoints के लिए Project API Key (token) का उपयोग करें।
कॉन्फ़िगरेशन
बेसिक सेटअप
connectors: posthog: enabled: true host: "${POSTHOG_HOST}" personal_api_key: "${POSTHOG_PERSONAL_API_KEY}" project_token: "${POSTHOG_PROJECT_TOKEN}" project_id: "12345"
sync: persons: true events: true cohorts: true feature_flags: true schedule: "0 */3 * * *" # हर 3 घंटे में
event_filters: - "$pageview" - "purchase_completed" - "signup_completed" - "feature_used"
lists: all_users: 25 active_users: 26 power_users: 27Field Mapping
field_mapping: email: email $name: FIRSTNAME $browser: BROWSER $os: OS $initial_referrer: REFERRAL_SOURCE total_events: EVENT_COUNT last_seen: LAST_ACTIVE_DATE signup_date: SIGNUP_DATE plan: SUBSCRIPTION_PLAN company: COMPANY cohort_names: POSTHOG_COHORTSAPI Endpoints
| Endpoint | Method | विवरण |
|---|---|---|
{host}/api/projects/{id}/persons/ | GET | persons list करें |
{host}/api/projects/{id}/events/ | GET | events list करें |
{host}/api/projects/{id}/cohorts/ | GET | cohorts list करें |
{host}/api/projects/{id}/feature_flags/ | GET | feature flags list करें |
{host}/api/projects/{id}/feature_flags/evaluation/ | POST | flags का मूल्यांकन करें |
{host}/api/projects/{id}/insights/ | GET | saved insights list करें |
{host}/api/projects/{id}/query/ | POST | HogQL queries चलाएं |
{host}/i/v0/e | POST | events capture करें (public) |
{host}/decide/?v=3 | POST | Feature flag decisions (public) |
कोड उदाहरण
कनेक्टर शुरू करें
import { TajoClient } from '@tajo/sdk';
const tajo = new TajoClient({ apiKey: process.env.TAJO_API_KEY, brevoApiKey: process.env.BREVO_API_KEY});
await tajo.connectors.connect('posthog', { host: process.env.POSTHOG_HOST, personalApiKey: process.env.POSTHOG_PERSONAL_API_KEY, projectToken: process.env.POSTHOG_PROJECT_TOKEN, projectId: '12345'});Persons को Brevo से Sync करें
// PostHog persons के माध्यम से paginate करेंlet nextUrl = `${posthogHost}/api/projects/${projectId}/persons/?` + new URLSearchParams({ limit: '100' });
while (nextUrl) { const response = await fetch(nextUrl, { headers: { 'Authorization': `Bearer ${process.env.POSTHOG_PERSONAL_API_KEY}` } });
const data = await response.json();
for (const person of data.results) { const email = person.properties.$email || person.properties.email; if (!email) continue;
await tajo.contacts.sync({ email, attributes: { FIRSTNAME: person.properties.$name || person.properties.name, LAST_ACTIVE_DATE: person.properties.$last_seen, SIGNUP_DATE: person.created_at, EVENT_COUNT: person.properties.$event_count, BROWSER: person.properties.$browser, OS: person.properties.$os, REFERRAL_SOURCE: person.properties.$initial_referrer }, listIds: [25] }); }
nextUrl = data.next;}Cohorts को Brevo Lists के रूप में Sync करें
// PostHog cohorts प्राप्त करें और members को Brevo lists से sync करेंconst cohortsResponse = await fetch( `${posthogHost}/api/projects/${projectId}/cohorts/`, { headers: { 'Authorization': `Bearer ${process.env.POSTHOG_PERSONAL_API_KEY}` } });
const { results: cohorts } = await cohortsResponse.json();
for (const cohort of cohorts) { // इस cohort में persons प्राप्त करें const personsResponse = await fetch( `${posthogHost}/api/projects/${projectId}/cohorts/${cohort.id}/persons/`, { headers: { 'Authorization': `Bearer ${process.env.POSTHOG_PERSONAL_API_KEY}` } } );
const { results: persons } = await personsResponse.json();
for (const person of persons) { const email = person.properties.$email || person.properties.email; if (email) { await tajo.contacts.update(email, { attributes: { POSTHOG_COHORTS: cohort.name } }); } }}Analytics के लिए HogQL Queries चलाएं
// analytics data क्वेरी करने के लिए HogQL का उपयोग करेंconst queryResponse = await fetch( `${posthogHost}/api/projects/${projectId}/query/`, { method: 'POST', headers: { 'Authorization': `Bearer ${process.env.POSTHOG_PERSONAL_API_KEY}`, 'Content-Type': 'application/json' }, body: JSON.stringify({ query: { kind: 'HogQLQuery', query: ` SELECT properties.$email AS email, count() AS event_count, max(timestamp) AS last_event FROM events WHERE event = 'purchase_completed' AND timestamp > now() - interval 30 day GROUP BY email HAVING event_count > 3 ORDER BY event_count DESC LIMIT 1000 ` } }) });
const queryResult = await queryResponse.json();
for (const row of queryResult.results) { await tajo.contacts.update(row[0], { attributes: { PURCHASE_COUNT_30D: row[1], LAST_PURCHASE: row[2] } });}Rate Limits
| Endpoint Category | Limit | नोट्स |
|---|---|---|
| Analytics endpoints | 240/min, 1,200/hr | GET persons, events, insights |
| Query endpoint | 2,400/hr | HogQL और custom queries |
| Feature flag evaluation | 600/min | Local evaluation endpoint |
| CRUD endpoints | 480/min, 4,800/hr | Create, update, delete operations |
| Public endpoints (capture) | असीमित | Event capture, flag decisions |
Batch Exports
बड़े पैमाने के event data exports के लिए, API के बजाय PostHog के batch exports feature का उपयोग करें। Batch exports S3, BigQuery, Snowflake, और अन्य destinations को support करते हैं।
समस्या निवारण
| समस्या | कारण | समाधान |
|---|---|---|
| 401 Unauthorized | अमान्य API key | settings में Personal API Key सत्यापित करें |
| 400 Invalid project | गलत project ID | PostHog URL में project ID जांचें |
| खाली persons list | कोई identified users नहीं | सुनिश्चित करें कि posthog.identify() call हो रहा है |
| गायब properties | Properties सेट नहीं | client SDK में $set calls सत्यापित करें |
| Rate limit 429 | बहुत अधिक requests | backoff लागू करें, rate limit headers जांचें |
Debug Mode
connectors: posthog: debug: true log_level: verbose log_queries: true log_sync: trueसर्वोत्तम प्रथाएं
- Users को identify करें - person sync enable करने के लिए हमेशा email के साथ
posthog.identify()call करें - Segmentation के लिए cohorts का उपयोग करें - Brevo lists के लिए PostHog के behavioral cohorts का लाभ उठाएं
- API requests batch करें - बड़े datasets के लिए pagination और batch processing का उपयोग करें
- जटिल queries के लिए HogQL का उपयोग करें - SQL जैसी queries के साथ custom analytics extract करें
- Batch exports सेट करें - बड़ी data volumes के लिए API polling के बजाय batch exports को प्राथमिकता दें
- प्रासंगिक events filter करें - noise कम करने के लिए केवल marketing-relevant events sync करें
सुरक्षा
- Personal API Key - Scoped Bearer token authentication
- Project token - केवल client-side operations के लिए public token
- HTTPS only - सभी endpoints के लिए TLS encryption आवश्यक
- IP allowlisting - self-hosted instances के लिए उपलब्ध
- Key scoping - specific permission scopes के साथ API keys बनाएं
- GitHub secret scanning - PostHog leaked key detection के लिए GitHub के साथ partner करता है