Introduzione
Monitora gli eventi di pagamento in Segment per alimentare la tua analisi, automazione del marketing e piattaforma di dati dei clienti. Invia automaticamente eventi di pagamento, abbonamento e ciclo di vita del cliente a oltre 300 strumenti downstream.
Questa integrazione richiede una Segment Write Key dal tuo workspace Segment.
Iniziare
Open the Webhook Section
Nel pannello di controllo di Dodo Payments, vai su Webhooks → + Add Endpoint ed espandi il menu a discesa delle integrazioni.
Select Segment
Scegli la scheda di integrazione Segment .
Enter Write Key
Fornisci la tua Segment Write Key nella configurazione.
Configure Transformation
Modifica il codice di trasformazione per formattare gli eventi per la Track API di Segment.
Test & Create
Testa con payload di esempio e clicca Create per attivare la sincronizzazione.
Done!
🎉 Gli eventi di pagamento saranno ora tracciati in Segment e inviati agli strumenti collegati.
Monitora Eventi di Pagamento
function handler ( webhook ) {
if ( webhook . eventType === "payment.succeeded" ) {
const p = webhook . payload . data ;
webhook . url = "https://api.segment.io/v1/track" ;
webhook . payload = {
userId: p . customer . customer_id ,
event: "Payment Completed" ,
properties: {
amount: ( p . total_amount / 100 ). toFixed ( 2 ),
currency: p . currency || "USD" ,
payment_method: p . payment_method || "unknown" ,
payment_id: p . payment_id ,
customer_email: p . customer . email ,
customer_name: p . customer . name
},
timestamp: webhook . payload . timestamp
};
}
return webhook ;
}
See all 20 lines
Monitora Ciclo di Vita dell’Abbonamento
function handler ( webhook ) {
const s = webhook . payload . data ;
switch ( webhook . eventType ) {
case "subscription.active" :
webhook . url = "https://api.segment.io/v1/track" ;
webhook . payload = {
userId: s . customer . customer_id ,
event: "Subscription Started" ,
properties: {
subscription_id: s . subscription_id ,
product_id: s . product_id ,
amount: ( s . recurring_pre_tax_amount / 100 ). toFixed ( 2 ),
frequency: s . payment_frequency_interval ,
next_billing: s . next_billing_date ,
customer_email: s . customer . email
},
timestamp: webhook . payload . timestamp
};
break ;
case "subscription.cancelled" :
webhook . url = "https://api.segment.io/v1/track" ;
webhook . payload = {
userId: s . customer . customer_id ,
event: "Subscription Cancelled" ,
properties: {
subscription_id: s . subscription_id ,
product_id: s . product_id ,
cancelled_at: s . cancelled_at ,
cancel_at_next_billing: s . cancel_at_next_billing_date ,
customer_email: s . customer . email
},
timestamp: webhook . payload . timestamp
};
break ;
}
return webhook ;
}
See all 37 lines
Identifica Proprietà del Cliente
function handler ( webhook ) {
if ( webhook . eventType === "payment.succeeded" ) {
const p = webhook . payload . data ;
webhook . url = "https://api.segment.io/v1/identify" ;
webhook . payload = {
userId: p . customer . customer_id ,
traits: {
email: p . customer . email ,
name: p . customer . name ,
total_spent: ( p . total_amount / 100 ). toFixed ( 2 ),
payment_method: p . payment_method || "unknown" ,
last_payment_date: webhook . payload . timestamp ,
customer_since: webhook . payload . timestamp
}
};
}
return webhook ;
}
See all 18 lines
Suggerimenti
Usa nomi di eventi coerenti nella tua integrazione
Includi proprietà rilevanti per analisi e segmentazione
Imposta timestamp appropriati per un tracciamento accurato degli eventi
Usa gli ID cliente come userId per una corretta identificazione dell’utente
Risoluzione dei Problemi
Events not appearing in Segment
Verifica che la Write Key sia corretta e attiva
Controlla che i nomi degli eventi seguano le convenzioni di denominazione di Segment
Assicurati che userId sia impostato correttamente per l’identificazione dell’utente
Verifica i limiti di invocazione dell’API di Segment