Amplitude Data's Google Pub/Sub Cohort integration lets you stream your cohort membership updates straight to a Pub/Sub topic.
Considerations
- This integration is only available for customers who have paid plans with Amplitude.
- You must enable this integration for each Amplitude project you want to use it in.
- You should have an understanding of Amplitude Audiences and Behavioral Cohorts before setting up this integration.
- Cohort updates can be sent via all the supported cadences (Daily, Hourly, Real Time).
- All the existing Real Time Cohort Sync limits apply here.
Payload
The payload sent to Pub/Sub is a JSON object. Example:
1{
2 "cohort_name": "Test Cohort",
3 "cohort_id": "gs72ns",
4 "in_cohort": true,
5 "computed_time": "1685748245",
6 "message_id": "some-message-id:54",
7 "users": [{
8 "user_id": "user1@amplitude.com",
9 "user_properties": {
10 "city": "San Francisco",
11 "fav_animal": "Bat"
12 }
13 },
14 {
15 "user_id": "user2@amplitude.com",
16 "user_properties": {
17 "city": "Seattle",
18 "fav_animal": "Cat"
19 }
20 }]
21}
-
cohort_name: String. the name of the audience
-
cohort_id: String. the unique ID of the audience, which can also be found in URL when viewing it on Amplitude
-
in_cohort: Boolean. Indicating this batch of users is “entering” or “exiting” an audience. Each message will only have one of either state but not both.
-
compute_time: String. The Epoch timestamp when we re-compute the audience in Amplitude. Due to the nature of Kinesis streaming, it’s impossible to enforce order upon receiving the message. The team can leverage this to resume the order.
- We kept it as a string rather than a number because depending on the programming language/platform the team is using, a JSON number can be interpreted as a float and lose precision.
-
message_id: String. The unique id of each message.
-
users: List. The users batch. Each user will be represented as a JSON object
-
user_id: String. the id of the user
-
(optional) user_properties: Map. A list of user properties to include, with key as the property name and value as the property value.
Note: The feature of having user_properties in the payload is in development. Please follow this page for updates.
Setup
Prerequisites
Before you get started, create a topic in Pub/Sub, and a Google IAM service account.
Amplitude needs two things from Pub/Sub to set up the integration:
-
Pub/Sub topic name: The name of the topic, not the full name in the google cloud. See the Google Pub/Sub documentation for help with this step.
-
Google service account key: You should create a dedicated service account for Amplitude Pub/Sub integration. See the Google documentation for help with this step.
Google Pub/Sub Setup
After you create your topic and service role, you must add the service account as a principle for the topic you created. For more detailed instructions for this step, see the Google documentation.
- Open the topic.
- In the Permissions tab, click Add Principal.
- Add the service account's name.
- Select Pub/Sub Publisher as the role.
Now, create a key for the service account. You need this to complete Amplitude setup. See the Google documentation for help with this step.
Amplitude setup
- In Amplitude Data, click Catalog and select the Destinations tab.
- In the Cohort section, click on Google Pub/Sub.
- Click Add another destination.
- Enter the Display Name for this destination. This is just a name to identify the destination when syncing the cohort.
- Enter the pub/sub topic id.
- Upload the service account key in the .json format based on the above setup.
- Save the destination.
This will create the destination for cohorts to be synced to.
Syncing Cohort Updates
- In Amplitude, open the cohort you want to export.
- Click Sync, and choose Google Pub/Sub.
- Select the destination created above.
- Select the sync frequency you need.