Google Cloud Pub/Sub Destination
When you enable Google Cloud Pub/Sub in the Segment app, Segment starts sending the events you specify to Pub/Sub topics of your choice. The Segment Google Cloud Pub/Sub destination supports all of the Segment methods, and sends data from any of the Segment libraries.
Authentication
In order for Segment to publish events to a Pub/Sub topic on your behalf, you must grant Segment’s Google Cloud Service Account {:target=”_blank”} publish access to your chosen topic. Follow these steps to enable this:
- In your Google Cloud Console, navigate to your Pub/Sub topic list.
- Select one or more topics using the checkboxes to the left of each topic name. Permissions options appear at the right of the page once you make a selection.
- In the Add Members input field, copy/paste Segment’s Service Account email:
pubsub@segment-integrations.iam.gserviceaccount.com
. - Click the Select a Role drop-down menu and choose Pub/Sub Publisher.
- Click Add.
You should now see the Segment Service Account email as a Pub/Sub Publisher like this:
Event Mapping
To use the Google Cloud Pub/Sub destination you must first decide which Segment events to route, and which of your Pub/Sub topics you want to route them to. Define this mapping in your destination settings.
Segment 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:
Make sure you use the full topic path! Paths are formatted as projects/${PROJECT_NAME}/topics/${TOPIC_NAME}
You can map any Segment event type (page
, track
, identify
, screen
, etc.). This allows you to publish all occurrences of a Segment event type to a specific Pub/Sub topic. To do this, create a row with the event type (track, identify, page, etc.) and its corrensponding topic as in the example below.
Events are case insensitive so Page
is equivalent to page
.
To route all events to a topic, use an *
as the event name.
Data Model
The structure of a Pub/Sub message uses the PubsubMessage structure.
The Segment destination publishes the entire Segment event payload as a Base64 encoded string, and sets it as the value of the data
parameter in the Pub/Sub message payload. Segment sets the publishTime
to be the timestamp
of the Segment event.
Segment does not currently use the optional attributes
parameter. If you use this functionality, contact us.
Engage
You can send computed traits and audiences generated using Engage to this destination as a user property. To learn more about Engage, schedule a demo.
For user-property destinations, an identify call is sent to the destination for each user being added and removed. The property name is the snake_cased version of the audience name, with a true/false value to indicate membership. For example, when a user first completes an order in the last 30 days, Engage sends an Identify call with the property order_completed_last_30days: true
. When the user no longer satisfies this condition (for example, it’s been more than 30 days since their last order), Engage sets that value to false
.
When you first create an audience, Engage sends an Identify call for every user in that audience. Later audience syncs only send updates for users whose membership has changed since the last sync.
Real-time to batch destination sync frequency
Real-time audience syncs to Google Cloud Pub/Sub may take six or more hours for the initial sync to complete. Upon completion, a sync frequency of two to three hours is expected.
Settings
Segment lets you change these destination settings from the Segment app without having to touch any code.
Setting | Description |
---|---|
Mapped Topics | mixed , defaults to . Map your Segment events / event types to your Google Cloud Pub/Sub topics. |
This page was last modified: 27 Oct 2023
Need support?
Questions? Problems? Need more info? Contact Segment Support for assistance!