Google Cloud Pub/Sub Destination

On this page

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 Segment Personas to this destination as a user property. To learn more about Personas, contact us for 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 indicade membership. For example, when a user first completes an order in the last 30 days, Personas 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), Personas sets that value to false.

When you first create an audience, Personas 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.

Supported Sources and Connection Modes

Before you start, make sure Google Cloud PubSub supports the source type and connection mode you’ve chosen to implement. You can learn more about connection modes here.

Web Mobile Server
📱 Device-mode
☁️ Cloud-mode

Segment offers an optional Device-based Connection Mode for Mobile data going to Google Cloud PubSub, so that you can use Google Cloud PubSub features that collect data directly from the mobile device. To do this, you must package the Segment-Google Cloud PubSub mobile SDK with the Segment mobile library.


Segment lets you change these destination settings from the Segment app without having to touch any code.

Mapped Topics

Map your Segment events / event types to your Google Cloud Pub/Sub topics.

This page was last modified: 17 Jul 2020

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