This guide assumes that you've completed the prerequisites for building partner integrations listed in Amplitude Integration Portal
This guide walks through the basics of creating a cohort syncing integration with Amplitude.
This doc uses a list-based integration in its examples. If you create a property-based cohort integration, some steps may be slightly different than you see here.
Add connection information before you configure the specifics of your integration.
The first step is to configure the integration tile that appears on the Amplitude Destinations page after Amplitude has validated your integration. You also need to decide between a List-based cohort integration or a Property-based cohort integration. See this doc for more information.
The configuration page has two sections.
The next several sections walk through configuration and testing options.
The first step is determining how you plan to authenticate the API call between Amplitude and your company.
Click Custom Headers, choose from the following:
These fields collect and replace the $variable
declared in the payloads in the API calls, and build the modal customers use to enable your integration. Fields you add here are required fields when your users set up the integration.
Amplitude recommends using an underscore "_" instead of a dash in the Header Values. for example, $api_key
instead of $api-key
.
Map fields to specify how Amplitude fields connect to the fields in your system. The value of the mapping replaces item_template
in the payloads.
user_id_field_amplitude
.You can slugify cohort names to standardize them. This is helpful if your system doesn't support special characters or foreign characters. This option converts your cohort name to a URL slug by replacing the Unicode special characters and spaces with ASCII and hyphens. This feature is only available when the variable $amplitude_cohort_name
appears in the payload of the endpoints. The slugify rule is as follows:
This option turns a cohort named Saturday's cohort & héllo
to Saturday-s-cohort-he-llo
You need to call three different APIs for a list-based integration. The first one is the list creation endpoint. When a cohort syncs for the first time, Amplitude calls this API, and creates a list on your platform. Amplitude expects your app to send a response with the unique identifier for listID
. From that response, Amplitude stores the listID
uses the ID as part of the payload for list updates.
https://api.yourapp.com/list
. Choose which method to use in the call.The payload editor is a developer-friendly JSON editor tool. Type $
to find created variables easily.
Add error status code and error messages for every endpoint so that end users can debug and get faster help.
Expand Error Classifications, and click Add New Error to add more status codes. Amplitude recommends including as many status codes and sub error codes as you need to. These codes and messages make debugging much faster for your end users.
Here are some common examples of status codes that most partners include:
Amplitude suggests giving a clear Failure Reason (Description) and Error Message in case cohort sync fails. Clear messages drastically improve your end user's experience and can help deflect support issues and frustration.
For any error response code that's "undefined" at the point of configuration (without failure reason or status code), Amplitude will by default show an "unclassified" error type with the following error message:
"This cohort sync has encountered an unidentified kind of error for this integration. Please contact support or your CSM to create a ticket and ask for help in solving this issue."
The add users API is called every time a cohort syncs from Amplitude to your app. This could be hourly or daily. This call calculates the difference in the current cohort size compared to the last successful sync.
URL Endpoint: There is a $list_Id
placeholder in the URL but it's not required. You can design your API to place this in the payload if you want, for example: https://your.domain/lists/$listId/add
.
API payload that to send to the destination: You can customize and define whether this payload is a batch. The important key here is the $items
variable. The contents of An array of items that replaces the $items variable in the payload replace this variable.
This $items
variable is usually the identifier for every user in a cohort. For example, there are 20 new users to add to your existing cohort. The Batch object contains a collection (a list of 20 users) so these 20 objects are sent to your endpoint. Your payload might look something like this:
1{2 "userIds": $items,3 "context": {4 "integration":{5 "name": "Amplitude Cohort Sync",6 "version": "1.0.0"7 }8 }9}
Maximum number of items in each API call (batch size): The default is 10,000, but you can specify this. Amplitude's recommendation is to have a 10,000 user per cohort batch.
An array of items that replaces the $items
variable in the payload: Specify the format of object that replaces the $item
variable in the payload. For example, "$user_id_field_amplitude"
.
Avoid rate limiting if possible. If you do have rate limits, for example, 90 requests per second, make the them explicit in your user documentation. Amplitude sends out 4 requests in parallel with each request having up to 10,000 users.
Instead of creating every single status code, failure reasons, error message, and sub error code again, Amplitude recommends using the same set of error codes from your list creation endpoint. Just select Copy errors from other endpoints and select an endpoint you've written errors for.
The remove users API is called every time a cohort syncs from Amplitude to your app. This could be hourly or daily. This call calculates the difference in the current cohort size compared to the last successful sync.
URL Endpoint: There is a $listId
placeholder in the URL but it's not required. You can design your API to place this in the payload if you want, for example: https://your.domain/lists/$listId/remove
.
API payload to send to the destination: You can customize and define whether this payload is a batch. The important key here is the $items
variable which is replaced by the contents of An array of items that replaces the $items variable in the payload
This $items
variable is usually the identifier for every user in a cohort. For example, there are 20 new users to remove from your existing cohort. The Batch object contains a collection (a list of 20 users) so these 20 objects are sent to your endpoint. Your payload might look something like this:
1{2 "userIds": $items,3 "context": {4 "integration":{5 "name": "Amplitude Cohort Sync",6 "version": "1.0.0"7 }8 }9}
Maximum number of items in each API call (batch size): The default is 10,000, but you can specify this. Amplitude's recommendation is to have a 10,000 user per cohort batch.
An array of items that replaces the $items
variable in the payload: Specify the format of object that replaces the $item
variable in the payload. For example, "$user_id_field_amplitude"
.
Instead of creating every single status code, failure reasons, error message, and sub error code again, Amplitude recommends using the same set of error codes from your list creation endpoint. Just select Copy errors from other endpoints and select an endpoint you've written errors for.
Before submitting your configuration for review, test the mock payload that you expect to receive from Amplitude. On the right side of the configuration page, follow these steps to preview and test your configuration.
Configure the test integration instance:
Check the variables table to make sure all variables are accounted for and resolve any errors.
Check your headers and payloads and when ready, click Test Endpoint to send a test API call to the predefined endpoint. You can also see the response/error for easy debugging.
After you click Test Endpoint, you should get a success response. Retrieve the $list_id
here and then Amplitude uses the $list_id
for the "Add Users Endpoint".
The {listId: $list_id}
is the expected response for list creation API call. To change the structure, change the Path to List ID in the response value in the list creation configuration.
Use the $list_id
you retrieved to test the add to add users and remove users endpoints.
After you have finalized your testing, click Submit to submit your integration to the Amplitude team. The review process should take about one week. When Amplitude approves you integration, you're notified via email and can see your integration tile in the Destination section of Amplitude.
Thanks for your feedback!
June 17th, 2024
Need help? Contact Support
Visit Amplitude.com
Have a look at the Amplitude Blog
Learn more at Amplitude Academy
© 2024 Amplitude, Inc. All rights reserved. Amplitude is a registered trademark of Amplitude, Inc.