Google Cloud Pub/Sub Destination

Getting Started

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. Follow these steps to enable this:

  1. In your Google Cloud Console, navigate to your Pub/Sub topic list. You should be able to access this list here.
  2. 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.
  3. In the Add Members input field, copy/paster Segment’s Service Account email:
  4. Click the Select a Role dropdown and choose Pub/Sub Publisher.
  5. Click Add.

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

track event mapping screenshot

Event Mapping

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.

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! They are formatted like this projects/${PROJECT_NAME}/topics/${TOPIC_NAME}

Any Segment event type (ie. page, track, identify, 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:

page event mapping screenshot

Events can be defined insensitive to case so Page will be equivalent to page.

If you would like to route all events to a topic, use an * as the event name.

Data Model

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, contact us.


You can send computed traits and audiences generated through 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 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 false.

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.

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

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 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 SDK.


Segment lets you change these destination settings from your Segment dashboard 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: 09 Jun 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