> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dodopayments.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Customer.io

> Gửi sự kiện Dodo Payments đến Customer.io để kích hoạt tự động hóa email và hành trình khách hàng.

## Giới thiệu

Kích hoạt các chiến dịch email cá nhân hóa và hành trình khách hàng dựa trên các sự kiện thanh toán. Tự động gửi email chào mừng cho khách hàng mới, cập nhật đăng ký và thông báo lỗi thanh toán qua Customer.io.

<Info>
  Tích hợp này yêu cầu ID Trang và Khóa API của Customer.io.
</Info>

## Bắt đầu

<Steps>
  <Step title="Open the Webhook Section">
    Trong bảng điều khiển Dodo Payments của bạn, chuyển đến <b>Webhooks → + Add Endpoint</b> và mở rộng menu tích hợp.

    <Frame>
      <img src="https://mintcdn.com/dodopayments/slbAEdrLLwKHfaRf/images/integrations/customer-io.png?fit=max&auto=format&n=slbAEdrLLwKHfaRf&q=85&s=fb4d96b67438c2eb178b2482475903db" alt="Add Endpoint and integrations dropdown" width="1644" height="952" data-path="images/integrations/customer-io.png" />
    </Frame>
  </Step>

  <Step title="Select Customer.io">
    Chọn thẻ tích hợp <b>Customer.io</b>.
  </Step>

  <Step title="Enter Credentials">
    Cung cấp ID Trang và Khóa API của Customer.io trong phần cấu hình.
  </Step>

  <Step title="Configure Transformation">
    Chỉnh sửa mã chuyển đổi để định dạng sự kiện cho API Track của Customer.io.
  </Step>

  <Step title="Test & Create">
    Thử nghiệm với các payload mẫu và nhấp <b>Create</b> để kích hoạt đồng bộ.
  </Step>

  <Step title="Done!">
    🎉 Các sự kiện thanh toán bây giờ sẽ kích hoạt các chiến dịch email tự động của Customer.io.
  </Step>
</Steps>

## Ví dụ Mã Biến đổi

### Theo dõi Sự kiện Thanh toán

```javascript track_payments.js icon="js" expandable theme={null}
function handler(webhook) {
  if (webhook.eventType === "payment.succeeded") {
    const p = webhook.payload.data;
    webhook.url = "https://track.customer.io/api/v2/entity";
    webhook.payload = {
      type: "person",
      identifiers: {
        id: p.customer.customer_id
      },
      action: "payment_completed",
      name: "Payment Completed",
      attributes: {
        email: p.customer.email,
        name: p.customer.name,
        payment_amount: (p.total_amount / 100).toFixed(2),
        payment_method: p.payment_method || "unknown",
        payment_id: p.payment_id,
        currency: p.currency || "USD"
      }
    };
  }
  return webhook;
}
```

### Theo dõi Vòng đời Đăng ký

```javascript track_subscriptions.js icon="js" expandable theme={null}
function handler(webhook) {
  const s = webhook.payload.data;
  switch (webhook.eventType) {
    case "subscription.active":
      webhook.url = "https://track.customer.io/api/v2/entity";
      webhook.payload = {
        type: "person",
        identifiers: {
          id: s.customer.customer_id
        },
        action: "subscription_started",
        name: "Subscription Started",
        attributes: {
          email: s.customer.email,
          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
        }
      };
      break;
    case "subscription.cancelled":
      webhook.url = "https://track.customer.io/api/v2/entity";
      webhook.payload = {
        type: "person",
        identifiers: {
          id: s.customer.customer_id
        },
        action: "subscription_cancelled",
        name: "Subscription Cancelled",
        attributes: {
          email: s.customer.email,
          subscription_id: s.subscription_id,
          cancelled_at: s.cancelled_at,
          cancel_at_next_billing: s.cancel_at_next_billing_date
        }
      };
      break;
  }
  return webhook;
}
```

### Theo dõi Thuộc tính Khách hàng

```javascript track_attributes.js icon="js" expandable theme={null}
function handler(webhook) {
  if (webhook.eventType === "payment.succeeded") {
    const p = webhook.payload.data;
    webhook.url = "https://track.customer.io/api/v2/entity";
    webhook.payload = {
      type: "person",
      identifiers: {
        id: p.customer.customer_id
      },
      action: "identify",
      name: "Customer Identified",
      attributes: {
        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;
}
```

## Mẹo

* Sử dụng tên sự kiện nhất quán phù hợp với các chiến dịch Customer.io của bạn
* Bao gồm các thuộc tính liên quan để cá nhân hóa
* Đặt các định danh khách hàng chính xác để theo dõi chính xác
* Sử dụng tên sự kiện có ý nghĩa cho các kích hoạt chiến dịch

## Khắc phục sự cố

<AccordionGroup>
  <Accordion title="Events not triggering campaigns">
    * Xác nhận ID Trang và Khóa API chính xác
    * Kiểm tra tên sự kiện trùng với chiến dịch của Customer.io
    * Đảm bảo định danh khách hàng được thiết lập đúng cách
    * Xem lại giới hạn tốc độ API của Customer.io
  </Accordion>

  <Accordion title="Transformation errors">
    * Xác nhận cấu trúc JSON phù hợp với định dạng API của Customer.io
    * Kiểm tra tất cả trường bắt buộc đã có
    * Đảm bảo tên sự kiện và thuộc tính được định dạng đúng
  </Accordion>
</AccordionGroup>
