Amplitude lets you group users who take similar actions into behavioral cohorts, such as those who downloaded a song in a music app or added an item to a cart. You can also define behavioral cohorts as customers that don’t take a specific action, like those who downloaded an app, but never finished signing up for a subscription.
Amplitude can sync these cohorts to other partner platforms through a series of REST API calls. Amplitude is able to create and update lists of cohort memberships (list-based) or set a user property or trait (property-based) in the Partner's platform.
The REST API uses basic authentication. The partner must send across the api_key
as username and an empty password
1curl -u api_key https://[ INSERT URL ]2Setting traits/properties on user:3JSON_HEADERS = {4 'Content-Type': 'application/json',5 }6Auth: ($api_key, '')
A list-based cohort integration works best if a cohort is represented as a list of user identifiers in the target system. You must call a list creation API on the first sync. Make subsequent calls to the add API and remove API to keep the list membership up to date.
1POST https://your.domain/lists 2{ 3 'name': [Amplitude] {$cohort_name}: {$cohort_id}, 4 'context': { 5 'integration': { 6 'name': 'Amplitude Cohort Sync', 7 'version': '1.0.0' 8 } 9 }10}
1POST https://your.domain/lists/$listId/add 2{ 3 'userIds':[$userId, $userId, ...] 4 'context': { 5 'integration': { 6 'name': 'Amplitude Cohort Sync', 7 'version': '1.0.0' 8 } 9 }10}
1POST https://your.domain/lists/$listId/remove 2{ 3 'userIds':[$userId, $userId, ...] 4 'context': { 5 'integration': { 6 'name': 'Amplitude Cohort Sync', 7 'version': '1.0.0' 8 } 9 }10}
A property-based cohort integration works best with systems that represent cohort membership as a custom user property, such as a boolean flag or a tag. When cohort membership changes, Amplitude invokes the updateAPI
to update the user property. Although you don't need list creation API here, some manual setup may be required to create the custom user property.
1POST https://your.domain/lists/$listId/remove 2{ 3 'type': 'identify', 4 'traits': { 5 '[Amplitude] {$cohort_name}: {$cohort_id}': True / False 6 }, 7 'userId': ‘$user_id’, 8 'context': { 9 'integration': {10 'name': 'Amplitude Cohort Sync',11 'version': '1.0.0'12 }13 }14}
1POST https://your.domain/lists/$listId/remove 2{ 3 'batch': [{ 4 'type': 'identify', 5 'traits': { 6 '[Amplitude] {$cohort_name}: {$cohort_id}': True / False 7 }, 8 'userId': ‘$user_id', 9 'context': {10 'integration': {11 'name': 'Amplitude Cohort Sync',12 'version': '1.0.0'13 }14 }15 }, {16 'type': 'identify',17 'traits': {18 '[Amplitude] {$cohort_name : {$cohort_id}': True / False19 },20 'userId': ‘$user_id’,21 'context': {22 'integration': {23 'name': 'Amplitude Cohort Sync',24 'version': '1.0.0'25 }26 }27 }]28}
Responses:
api_key
)The property Amplitude passes over for cohort members is set to true
when a user becomes part of the cohort and it's set to false
when a user leaves the cohort.
To test, Amplitude recommends creating a mock payload that you would expect to receive from Amplitude. For cohort integrations, the typical payload structure is as follows:
1curl --location --request POST 'https://app.staging-01.TEST_COMPANY_NAME.com/api/v1/integration/amplitude/cohort \ 2--header 'api_key: TEST_API_KEY' \ 3--header 'app_id: TEST_APP_ID' \ 4--header 'Content-Type: application/json' \ 5--data-raw ' 6{ 7 "traits": { 8 "cohort name:123": true 9 },10 "type": "identify",11 "userId": "test.user@email.com"12}13'
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.