Google Cloud Pub/Sub Destination
When you toggle on Google Cloud Pub/Sub in Segment, we’ll start sending your specified Segment events to Pub/Sub topics of your choice. Our Google Cloud Pub/Sub destination supports all of the Segment methods, and will send data from any one of our libraries.
In order for us to publish events to a Pub/Sub topic on your behalf, you must grant our Google Cloud Service Account publish access to your chosen topic. Please follow these steps to enable this:
- In your Google Cloud Console, navigate to your Pub/Sub topic list. You should be able to access this list here.
- Once there, either select an individial topic or multiple using the checkboxes to the left of each topic name. Once you have made a selection, you should see some Permissions options on the right of the page.
- In the Add Members input field, copy/paster Segment’s Service Account email:
- Click the Select a Role dropdown and choose Pub/Sub Publisher.
- Click Add.
You should now see our Service Account email as a Pub/Sub Publisher like this:
To begin using the Google Cloud Pub/Sub destination you must first decide on which Segment events you would like to route to which of your Pub/Sub topics. This mapping then needs to be defined in your destination settings.
track events can map based on their event name. For example, if you have an event called
User Registered, and you wanted these events to be published to a topic called
projects/my-project/topics/user-registered, you would create a row in your destination settings that looks like this:
Please ensure you use the full topic path! They are formatted like this
Any Segment event type (ie.
screen, etc.) can also be mapped. This allows you to publish all occurrences of a given Segment event type to a given Pub/Sub topic. To do this, you simply to create a row with the event type (track, identify, page, etc.) and it’s corrensponding topic:
Events can be defined insensitive to case so
Page will be equivalent to
If you would like to route all events to a topic, use an * as the event name.
The structure of a Pub/Sub message follows this structure: PubsubMessage
Our integration will publish the entire Segment event payload as a Base64 encoded string and set it as the value of the
data parameter in the Pub/Sub message payload. We will set the
publishTime to be the
timestamp of the Segment event.
We do not currently integrate with the optional
attributes parameter. If you use this functionality, please contact us.
For user-property destinations, an identify call will be sent to the destination for each user being added and removed. The property name will be the snake_cased version of the audience name you provide with a true/false value. For example, when a user first completes an order in the last 30 days, we will send an identify call with the property
order_completed_last_30days: true, and when this user no longer satisfies we will set that value to
When the audience is first created an identify call is sent for every user in the audience. Subsequent syncs will only send updates for those users which were added or removed since the last sync.
Supported Sources and Connection Modes
The first step is to make sure Google Cloud PubSub supports the source type and connection mode you’ve chosen to implement. You can learn more about what dictates the connection modes we support here.
To learn more about about Connection Modes and what dictates which we support, see here.
Segment offers an optional Device-based Connection Mode for Mobile data with Google Cloud PubSub. If you’d like to use those features that require client-based functionality, follow the steps above to ensure you have packaged the Google Cloud PubSub SDK with Segment’s.
Segment lets you change these destination settings from your Segment dashboard without having to touch any code.
Map your Segment events / event types to your Google Cloud Pub/Sub topics.
This page was last modified: 25 Nov 2019
Questions? Problems? Need more info? Contact us, and we can help!