Google Cloud Pub/Sub Destination

Destination Info
  • iOS
  • Android
  • Server
Connection Modes
Device-mode Cloud-mode
Web Web
Mobile Mobile
Server Server

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.


In order for Segment to publish events to a Pub/Sub topic on your behalf, you must grant Segment’s Google Cloud Service Account publish access to your chosen topic. Follow these steps to enable this:

  1. In your Google Cloud Console, navigate to your Pub/Sub topic list.
  2. 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.
  3. In the Add Members input field, copy/paste Segment’s Service Account email:
  4. Click the Select a Role drop-down menu and choose Pub/Sub Publisher.
  5. Click Add.

You should now see the Segment Service Account email as a Pub/Sub Publisher like this:

track event mapping screenshot

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:

track event mapping screenshot

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.

page event mapping screenshot

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.


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.


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: 08 Mar 2022

Get started with Segment

Segment is the easiest way to integrate your websites & mobile apps data to over 300 analytics and growth tools.
Create free account