# Google PubSub

Use the Google PubSub destination to send Freshpaint data to a Google Pub/Sub Topic, facilitating queued reliable delivery to any number of Topic subscribers.

## Destination Info

* Supports [Page](https://documentation.freshpaint.io/developer/freshpaint-sdk-reference#page), [Track](https://documentation.freshpaint.io/developer/freshpaint-sdk-reference#track), and [Identify](https://documentation.freshpaint.io/developer/freshpaint-sdk-reference#identify), and [Group](https://documentation.freshpaint.io/developer/freshpaint-sdk-reference#group) calls
* Supports [HIPAA mode](https://documentation.freshpaint.io/hipaa-mode)
* Connection Modes:

<table><thead><tr><th align="right"> </th><th data-type="checkbox">Client-side</th><th data-type="checkbox">Server-side</th></tr></thead><tbody><tr><td align="right">Web</td><td>false</td><td>true</td></tr><tr><td align="right">Mobile</td><td>false</td><td>true</td></tr><tr><td align="right">Server</td><td>false</td><td>true</td></tr></tbody></table>

## Getting Started

To set up the Google PubSub destination, follow the steps below:

### Grant Freshpaint's Google Cloud Service Account publisher access to your Topic

1. In your Google Cloud Console, navigate to the [Pub/Sub topic list](https://console.cloud.google.com/cloudpubsub/topicList)
2. Select one or more Topics using the checkboxes.
3. Click "Add Principal" and specify Freshpaint's Service Account email`pubsub@freshpaint-1.iam.gserviceaccount.com`, then choose Role: "Pub/Sub" -> "Pub/Sub Publisher", then click "Save".
4. You should see the Freshpaint Service Account email listed under Role/Principal

<figure><img src="/files/wI46SPCfntnzzzrQoivs" alt=""><figcaption></figcaption></figure>

### Configure Freshpaint Event Definition to Topic Mappings

1. Go to the [Google PubSub configuration page](https://app.freshpaint.io/destinations/apps/google-pubsub) in Freshpaint and click "Configure" for `Mappings`.
2. Click "Add Mapping"
3. Enter the Event Definition name to be mapped
4. Enter the Google Pub/Sub Topic Name&#x20;
5. Click "Save"

<figure><img src="/files/tEFlGYA2rvN2db0w9zx7" alt=""><figcaption></figcaption></figure>

## Events

When you send an event to the Google Pubsub destination from Freshpaint, Freshpaint will send Event data for each mapped Event Definition to the corresponding Topic. The body of the message will look like this:

```json
{
    "event": "a",
    "type": "track",
    "timestamp": "2022-12-28T21:16:50Z",
    "messageId": "iI5pcrFfZHTuAfEu1DZ6Mg==",
    "anonymousId": "1855a980cb1529-066ed15036156b-18525635-13c680-1855a980cb2178a",
    "context": {
        "page": {
            "url": "https://example.com/",
            "title": "Home Page",
            "path": "/"
        },
        "library": {
            "name": "freshpaint.js"
        }
    },
    "properties": {
        "customProp": 42
    }
}I
```

## Page

When a pageview event occurs, Freshpaint will send pageview event data to the corresponding Topic. The body of the message will look like this:

```json
{
    "type": "page",
    "timestamp": "2022-12-28T21:51:30Z",
    "messageId": "icgQY4taV/WsZPiE9/0ZaA==",
    "anonymousId": "1855a980cb1529-066ed15036156b-18525635-13c680-1855a980cb2178a",
    "context": {
        "page": null,
        "library": {
            "name": "freshpaint.js"
        }
    },
    "properties": {
        "url": "https://example.com/",
        "title": "Example Domain",
        "path": "/"
    }
}
```

## Identify

When you call [`freshpaint.identify('hello@example.com', {"phone": "+15558675309"}`](/reference/developer/freshpaint-sdk-reference.md#identify)`,` Freshpaint will send Identify data for each mapped Event Definition to the corresponding Topic. The body of the message will look like this:

```json
{
    "type": "identify",
    "timestamp": "2022-12-28T22:00:25Z",
    "messageId": "Zi1TKug6D8lLqNUD1v0i1w==",
    "anonymousId": "1855a980cb1529-066ed15036156b-18525635-13c680-1855a980cb2178a",
    "userId": "hello@example.com",
    "context": {
        "page": {
            "url": "https://example.com/",
            "title": "Home Page",
            "path": "/"
        },
        "library": {
            "name": "freshpaint.js"
        }
    },
    "properties": {},
    "traits": {
        "phone": "+15558675309"
    }
}
```

## Group

When you call [`freshpaint.group("Acme, Inc", {"companyId": "1234"})`](/reference/developer/freshpaint-sdk-reference.md#group),Freshpaint will send Group data for each mapped Event Definition to the corresponding Topic. The body of the message will look like this:

```json
{
    "type": "group",
    "timestamp": "2022-12-28T21:56:23Z",
    "messageId": "7Kx9d7JNjo3Tbi9IcFITYw==",
    "anonymousId": "1855a980cb1529-066ed15036156b-18525635-13c680-1855a980cb2178a",
    "context": {
        "page": {
            "url": "https://example.com/",
            "title": "Home Page",
            "path": "/"
        },
        "library": {
            "name": "freshpaint.js"
        }
    },
    "groupId": "Acme, Inc",
    "properties": {},
    "traits": {
        "companyId": "1234"
    }
}
```

## Payload Format

Here is what each piece of message body means:

| Key               | Type            | Description                                                                                                  |
| ----------------- | --------------- | ------------------------------------------------------------------------------------------------------------ |
| `event`           | string          | The name of the event                                                                                        |
| `type`            | string          | The type of the event, for example `"track"`, `"identify"`, `"page"`, or `"group"`                           |
| `timestamp`       | string          | <p>The time the event occurred.<br>Example: <code>"2022-08-08T17:15:45Z"</code></p>                          |
| `messageId`       | string          | Unique id identifying this event                                                                             |
| `anonymousId`     | string          | The ID of the device the identify call was performed on                                                      |
| `userId`          | optional string | An identifier that uniquely identifies the user that performed the event (usually email address)             |
| `groupId`         | optional string | For group events, a string that uniquely identifies the group this user belongs to (such as a company name). |
| `context.page`    | object          | Data about the page that the event was performed on                                                          |
| `context.library` | object          | Data about the Freshpaint SDK that was used to capture this event                                            |
| `properties`      | object          | Any additional event properties for Track and Page events                                                    |
| `traits`          | object          | Any additional properties of the user (for identify events) or group (for group events)                      |

##


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://documentation.freshpaint.io/integrations/destinations/apps/google-pubsub.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
