Stape
Search
Try for free

Pub/Sub Publish tag for Google Tag Manager server container

Updated
Sep 10, 2024
Published
Sep 9, 2024

Pub/Sub Publish tag allows users to send messages to a Google Cloud Pub/Sub topic directly from server containers. It connects GTM with Google Cloud services, enabling you to send event data from your GTM containers to your cloud infrastructure.

What is Pub/Sub?

Pub/Sub, short for Publish/Subscribe, is a messaging service from Google Cloud that helps different systems communicate with each other. 

Here’s a simple example: imagine you have two people, one who shares information (the "publisher") and one who receives it (the "subscriber"). Pub/Sub allows the publisher to send messages (like data or updates) to a topic, which is like a mailbox. Then, the subscriber can take the messages from the mailbox whenever they're ready. 

It’s useful when you want to send data from one place (like a website or app) to another place (like a cloud server), especially for tasks like processing data or triggering actions. Pub/Sub makes this data flow automatic and easy to manage! Here’s a detailed documentation from Google.

How to use Pub/Sub Publish tag?

A common use case of the Pub/Sub Publish tag is data processing pipelines. For instance, if you're tracking certain events (like purchases, sign-ups, etc.), you may want to push this data into Google Cloud for further processing, analysis, or integration with other systems. Using Pub/Sub, you can route these events into Google Cloud services like BigQuery for analytics or into a Google Cloud Function for custom processing.

Example: you want to track user purchases on your e-commerce website and automatically push that data to your cloud infrastructure, where it gets processed to trigger downstream workflows like order fulfillment or sending customer notifications.

How to set up Pub/Sub Publish tag

1. Create a Service account in Google Cloud with appropriate Pub/Sub roles. This account will allow your GTM container to publish messages to a specific Pub/Sub topic in your Google Cloud Project.

Create a Service account in Google Cloud with appropriate Pub/Sub roles

2. After creating the account, download the JSON key file. This file is essential because you'll upload it to the Stape power-up later.

3. Before implementation, make sure you have set up server Google Tag Manager container on Stape.

Log in to your Stape account. Open your sGTM container and click the Power-ups tab. Find Google Service Account and click Use.

Log in to your Stape account. Open your sGTM container and click the Power-ups tab. Find Google Service Account and click Use.

Activate the power-up and upload service account credentials file. Click Save changes button.

Log in to your Stape account. Open your sGTM container and click the Power-ups tab. Find Google Service Account and click Use.

4. In the Google Cloud Console, go to Pub/Sub under the Cloud Console menu.

Click on Create Topic.

Give the topic a name (you will use this name when setting up the tag in GTM).

This topic will be the destination where GTM sends its data.

Google Cloud Console, go to Pub/Sub under the Cloud Console menu

5. Download Pub/Sub Publish tag from GitHub or add it from the Template Gallery.

Import the tag to server Google Tag Manager by clicking Templates → New Tag Template. Click three dots in the top right corner → Click import → Add template that you’ve recently downloaded → Click Save.

pub/sub tag

6. Configure the tag by filling out the following fields:

pub/sub tag

Project - write your GCP project ID

Topic - Pub/Sub topic name, which you created on step 4.

Add Event Data - add all Event Data to the message. If Event Data and Custom Data have the same field, the Custom Data value will be used for that field. In other words, you can override Event Data values with Custom Data.

Add Timestamp - this option will add the millisecond timestamp to the message.

Skip null or undefined values - this option allows skipping items from customDataList with undefined or null values.

7. Set a trigger. Decide when you want the Pub/Sub Publish tag to fire. This could be on any specific event you need.

To sum up

Pub/Sub Publish tag for server GTM offers a powerful way to integrate Google Cloud with your event tracking setup. By sending event data from your GTM containers directly to Google Cloud Pub/Sub, you open up a world of possibilities for further data processing, analysis, and automation. 

Whether it's routing purchase data to BigQuery for analysis or triggering downstream workflows like order fulfillment through Google Cloud Functions, this tag provides a flexible, scalable solution for managing data within your cloud infrastructure. 

Tagged with:gtm server

Host your GTM server at Staperight now!