Google Cloud Function Destination
Segment makes it easy to send your data to Google Cloud Function (and lots of other destinations). Once you track your data using our open-source libraries we’ll translate and route your data to Google Cloud Function in the format they understand. Learn more about how to use Google Cloud Function with Segment.
Google Cloud Function is a lightweight compute solution for developers to create single-purpose, stand-alone functions that respond to Cloud events without the need to manage a server or runtime environment.
NOTE: Google Cloud Function is currently in beta, and this doc was last updated on May 6, 2019. This means that there may still be some bugs for us to iron out and we’re excited to hear your thoughts. If you are interested in joining or have any feedback to help us improve the Google Cloud Function Destination and its documentation, let us know!
Getting Started
Before you start, make sure Google Cloud Function 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 | ✅ | ✅ | ✅ |
Build a Google Cloud Function to Process Segment Events
In order to process events from Segment, you will need to provide a Google Cloud Function that can handle your event flow:
- Go to https://cloud.google.com/functions.
- Click on
VIEW CONSOLE.

- Select a project.
-
Click on
CREATE FUNCTION.
- In the
Namefield, give a name to your function. - In the
Memory allocatedfield, define how much memory your function can use. - In the
Triggerfield, selectHTTP. Then keep the givenURLin order to configure your segment destination. - In the
Source codefield, select how you will provide your function code. - In the
Runtimefield, select what language is used in your code. - In the
Function to executefield, type the name of your function as it is defined in your code. - Click on
Createto create the Google Cloud Function.
Configure Google Cloud Function Destination
Once the Google Cloud Function is created, a destination that will call the function must be configured:
- In our
Destinationssection, click onAdd Destination. You will be redirected to ourCatalog. - Search and client on
Google Cloud Functiondestination. - Click on
Configure Google Cloud Function. - Fill the settings.
Settings:
| HTTP Trigger | The URL given under the Trigger section when you created the Google Cloud Function. |
|---|---|
| API Key (optional) | A string to identify that a request is coming from Segment. The API key is injected in the Authorization header as a basic authorization header without password. See https://en.wikipedia.org/wiki/Basic_access_authentication.Deciding whether to check the API key depends on the function implementer. |
Personas
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.
Settings
Segment lets you change these destination settings from the Segment app without having to touch any code.
API Key
The api key used to identify request performed by Segment.
HTTP Trigger
The URL to call the Google Cloud Function.
This page was last modified: 17 Jul 2020
Need support?
Questions? Problems? Need more info? Contact us, and we can help!