# Google Analytics 4

Google Analytics 4 (server-side Measurement Protocol)

| Field | Value |
|---|---|
| Addon id | `integration-google-analytics` |
| Kind | `integration` |
| Provides | `google_analytics` |
| Engine | `wasm` |
| ABI | `0.2.0` |
| Version | 0.1.0 |
| Author | MythicalSystems |
| Source | `extensions/addons/google-analytics` |
| Permissions (shown at install) | `network.outbound` |

## Capabilities

| Capability | Value |
|---|---|
| [`events`](capabilities.md) | `order.created`, `invoice.paid`, `user.registered` |
| [`http`](capabilities.md) | `www.google-analytics.com` |
| [`secrets`](capabilities.md) | `api_secret` |

## Events and hooks

| What | Value |
|---|---|
| Listens to (`events`) | `order.created`, `invoice.paid`, `user.registered` |
| Hooks | none |
| Emits | none |
| Mixins | none |
| Scheduled jobs | none |

## Settings and secrets

| Setting | Type | Required |
|---|---|---|
| `measurement_id` | `text` | yes |
| `api_secret` | `secret` | yes |

Secrets (stored encrypted, never returned by the API): `api_secret`.

Outbound HTTP allowed to: `www.google-analytics.com`. `$server` is the hostname of the server configured for the product, `$setting:<key>` the host of that setting.

## addon.json

_extensions/addons/google-analytics/addon.json_

```json
{
  "abi": "0.2.0",
  "author": "MythicalSystems",
  "capabilities": {
    "events": [
      "order.created",
      "invoice.paid",
      "user.registered"
    ],
    "http": [
      "www.google-analytics.com"
    ],
    "secrets": [
      "api_secret"
    ]
  },
  "description": "addons.desc.integration.google_analytics",
  "engine": "wasm",
  "id": "integration-google-analytics",
  "kind": "integration",
  "name": "Google Analytics 4",
  "permissions": [
    "network.outbound"
  ],
  "provides": "google_analytics",
  "settings": [
    {
      "key": "measurement_id",
      "kind": "text",
      "label": "Measurement ID (G-XXXXXXX)",
      "required": true
    },
    {
      "key": "api_secret",
      "kind": "secret",
      "label": "Measurement Protocol API secret",
      "required": true
    }
  ],
  "version": "0.1.0",
  "wasm": "addon.wasm"
}
```

