> ## Documentation Index
> Fetch the complete documentation index at: https://docs.stigg.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Ingestion from GCP Pub/Sub

## Overview

If you're already reporting events to Google Cloud Platform (GCP) [Pub/Sub](https://cloud.google.com/pubsub) you can leverage Stigg's native connector to forward these events to Stigg and track feature usage.

Under the hood, the connector leverages a GCP Function designed to actively listen to a Pub/Sub topic, map events to the [Stigg event schema format](./index#event-schema) and send them to Stigg in batches at one-second intervals.

## Prerequisites

* A [project](https://developers.google.com/workspace/guides/create-project) in a GCP account
* A [pub/sub topic](https://cloud.google.com/pubsub/docs/create-topic) to consume messages from
* [Terraform](https://developer.hashicorp.com/terraform/tutorials/aws-get-started/install-cli) installed

## Getting started

* Enable access for the [required APIs](https://console.cloud.google.com/flows/enableapi?apiid=cloudbuild.googleapis.com,artifactregistry.googleapis.com,cloudfunctions.googleapis.com,storage.googleapis.com,compute.googleapis.com,eventarc.googleapis.com,run.googleapis.com) on the GCP project
* Clone [Stigg's GCP connector repository](https://github.com/stiggio/gcp-events-connector)
* Edit the [EventParser.ts](https://github.com/stiggio/gcp-events-connector/blob/master/function-source/src/EventParser.ts) file to map between your event format and the Stigg format.

## Deployment

* Create a `terraform/terraform.tfvars` file with the following content and fill in the values:
  <CodeGroup>
    ```typescript terraform.tfvars theme={null}
    gcp_project=""
    pubsub_topic_id=""
    stigg_api_key=""
    ```
  </CodeGroup>
* Change the directory `cd terraform/`
* Run `terraform init` to initialize the project
* Run `terraform apply -var-file=".tfvars"` to deploy the Cloud Function

## Connecting to a metered feature in Stigg

To allow Stigg to meter feature usage based on reported events, an event-based metered feature must exist in Stigg.

If you haven't defined a meter for these events in Stigg yet, [click here](./index) to learn how to do so.

## Example project

<Card href="https://github.com/stiggio/gcp-events-connector" horizontal>
  <div style={{ display: 'flex', alignItems: 'center', gap: '1rem' }}>
    <img src="https://mintcdn.com/stigg/aJeGPh9dwMpK_Kcr/images/gcp.svg?fit=max&auto=format&n=aJeGPh9dwMpK_Kcr&q=85&s=d68d19e26546f8f29725f3fc6d974781" alt="GCP" width="42" height="42" data-path="images/gcp.svg" />

    <div>
      <h3 style={{ margin: 0, fontSize: '1rem', fontWeight: 600 }}>GCP Events Connector</h3>

      <p style={{ margin: 0 }}>
        Example integration of GCP Pub/Sub with Stigg for usage metering.
      </p>
    </div>
  </div>
</Card>
