Event Tracking

Event Tracking

Event Tracking

icon
Event tracking you’ll actually enjoy

Event tracking products are difficult to test in the field and are filled with feature bloat. Our new event tracking tool lets you easily capture your products key-value metrics on a per customer basis. We’ll stitch together your event data with your customer subscription data for you, to give you a comprehensive view of your customers.

Use Cases

  • Conversion funnel analytics
  • Customer health
  • Feature adoption reports
  • Churn prediction

Naming Conventions

To keep event naming consistent across your application, we recommend using an object-action convention, capitalized and with a regular space.

  • “Product Clicked”
  • “Application Opened”
  • “Account Created”
  • “User Registered”

Publishing Events

Events are created through a simple HTTP request.

Server Side

For sending server side events, include your Churnkey API key as a header, as shown below.

const headers = {
  "x-ck-api-key": "YOUR_CHURNKEY_API_KEY",
  "x-ck-app": "YOUR_CHURNKEY_APP_ID",
}

const eventBody = {
  "uid": "unique_id", // unique id of the customer e.g. your database id
  "customerId": "cus_abcxyz", // billing provider id
  "event": "Post Created",
  "createdAt": '2022-05-01', // use for backfilling data, default is now
  "eventData": {
    "postType": "image"
  },
  // optionally update customer records with new data
  "customerData": {
    "numFollowers": 21600,
  },
  // Only for use in B2B scenarios where each customer can have multiple users
  "user": {
    "uid": "user_unique_id", // e.g. your database id for the user
    "data": {
      "name": "John Henry",
      "email": "johnhenry@example.com",
    }
  }
}

axios.post("https://api.churnkey.co/v1/events/track", eventBody, headers)

Server Side Bulk Create

You can create up to 100 events in one api request using our bulk event endpoint. Please note that, unlike with single event creation, you cannot include customer and user data updates with the bulk event endpoint.

const headers = {
  'x-ck-api-key': 'YOUR_CHURNKEY_API_KEY',
  'x-ck-app': 'YOUR_CHURNKEY_APP_ID',
};

const events = [
  {
    uid: 'id_a', // unique id of the customer e.g. your database id
    customerId: 'cus_a', // billing provider id
    event: 'Post Created',
    eventData: {
      postType: 'image',
    },
    // optional, use for B2B with multiple users per account
    user: {
      uid: 'user_x',
    },
    createdAt: '2022-05-01' // use for backfilling data, default is now
  },
  {
    uid: 'id_b',
    customerId: 'cus_b',
    event: 'Post Created',
    eventData: {
      postType: 'video',
    },
    createdAt: '2022-05-02'
  },
];

axios.post('https://api.churnkey.co/v1/events/bulk', events, headers);

Client Side

💡
Make sure to not use your secret Churnkey API key client side

Client side events can be authenticated by signing the customerId or customerEmail if the customerId is not available. Events can also be created without authentication, and will be marked as “unverified” accordingly.

For details on creating the hmacSignature , see Step 2 on our cancel flow Installation Guide.

// Optional. See Step 2 of our Installation Guide
const hmacSignature = await getSignedCustomerId(customerId) // Sign customerEmail if customerId is not available

window.churnkey.event({
  customerId: "cus_a23kmlfg",
	customerEmail: "jane@example.com",
  appId: "YOUR_CHURNKEY_APP_ID",
  authHash: hmacSignature, // Optional
  event: "Post Created",
  eventData: {
    postType: "image",
  }
})

Customer Data Records

In addition to events, you can update customer data. This can be done by including a customerData property in the create (single) event endpoint, or by sending an explicit request to events/customer-update.

You must include at least one of uid or customerId. For B2B products, you can also pass in a user property as shown below to update user data records.

const headers = {
  'x-ck-api-key': 'YOUR_CHURNKEY_API_KEY',
  'x-ck-app': 'YOUR_CHURNKEY_APP_ID',
};

const dataUpdate = {
  uid: 'unique_id', // unique id of the customer e.g. your database id
  customerId: 'cus_abcxyz', // optional, billing provider id
  customerData: {
    numFollowers: 21600,
  },
  // Only for use in B2B scenarios where each customer can have multiple users
  user: {
    uid: 'user_unique_id', // e.g. your database id for the user
    data: {
      name: 'John Henry',
      email: 'johnhenry@example.com',
    },
  },
};

axios.post('https://api.churnkey.co/v1/events/customer-update', dataUpdate, headers);

💠
h

© Churnkey