Skip to content
New Revenue by source: MRR from Stripe or Paddle beside your live traffic, each subscription credited to its first visit

Deploys

Mark each deploy under the traffic chart, from GitHub, GitLab or Bitbucket's own webhooks or one request from any CI, so a drop sits next to the commit that caused it.

A drop in sign-ups an hour after a release is easy to explain when the release is on the chart. A deploy hook notes each deploy under the traffic chart: the commit's first line, its short hash, its author, its branch or environment, and a link to it.

Add a hook

In the site's settings, Deploys, choose Add deploy hook and say:

  • Repository on: GitHub, GitLab, Bitbucket, or A CI step for any other CI;
  • what counts as a deploy: a workflow run, pipeline or build that passed, a deployment that succeeded (GitHub and GitLab; Bitbucket sends none), or a push to the branch, for a site that deploys on every push;
  • Branch: the repository's default branch unless you name one (Bitbucket sends no default, so main or master);
  • optionally, one Workflow, Pipeline, Build or Environment by name, when a repository runs several.

mettr shows the hook's address and secret once. Add them to the repository's webhook settings, as the hook's Setup explains for each provider. A site can have several hooks: one per repository, or one per environment.

Repository webhooks

  • GitHub: Settings, Webhooks, Add webhook. Payload URL is the hook's address, content type application/json, secret the hook's secret. Send the events the setup lists (workflow runs, deployment statuses or pushes).
  • GitLab: Settings, Webhooks. URL is the hook's address, secret token the hook's secret, with pipeline, deployment or push events.
  • Bitbucket: Repository settings, Webhooks, with the hook's secret, and commit status or push events.

Each delivery is checked before it is read: GitHub and Bitbucket sign it with the secret (HMAC-SHA256), GitLab sends the token. The same commit through the same hook within 10 minutes is one deploy. Each hook shows what its last delivery came to, so one that notes nothing says why (another branch, a failed run, a different workflow).

A CI step

For any CI, or to mark the moment the site really changed rather than when a workflow ended, add a hook of the kind A CI step, and have the deploy job send one request once it has deployed:

# .github/workflows/deploy.yml, after the deploy step
- name: Note the deploy in mettr
  env:
    METTR_DEPLOY_URL: ${{ secrets.METTR_DEPLOY_URL }}
    METTR_DEPLOY_SECRET: ${{ secrets.METTR_DEPLOY_SECRET }}
    MESSAGE: ${{ github.event.head_commit.message }}
    AUTHOR: ${{ github.event.head_commit.author.name }}
  run: |
    jq -n --arg sha "$GITHUB_SHA" --arg message "$MESSAGE" \
      --arg author "$AUTHOR" --arg branch "$GITHUB_REF_NAME" \
      --arg repository "$GITHUB_REPOSITORY" \
      --arg url "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/commit/$GITHUB_SHA" \
      '$ARGS.named' |
    curl --fail --silent --show-error -X POST "$METTR_DEPLOY_URL" \
      -H "Authorization: Bearer $METTR_DEPLOY_SECRET" \
      -H 'Content-Type: application/json' --data @- ||
    echo '::warning::mettr did not take the deploy'

METTR_DEPLOY_URL is the hook's address and METTR_DEPLOY_SECRET its secret, kept as repository secrets. The commit's words reach the shell through the environment, never pasted into the script, so a commit message can never run as code.

Field What it is
sha Required. The commit deployed
message The commit's message; its first line is the note
author Who made it
branch The branch deployed
environment production, staging
url A link to the commit or the run
repository The repository's name

Anything else is refused with 422, so the step fails where you see it. The hook's Setup has the ready step for GitHub Actions, GitLab CI and Bitbucket Pipelines.

Responses

Status Means
201 A deploy noted: {"outcome": "noted", "id": 412}
202 A delivery that is not a deploy, with the reason: {"outcome": "ignored", "reason": "…"}
200 The provider's test delivery: {"outcome": "ping"}
401 Not signed with the hook's secret
413 Larger than 2 MB
422 A CI request that does not fit

Removing a hook keeps the deploys it noted. For other changes (a campaign, a price change), use the Annotations API or note them on the chart.

Updated · This page as Markdown · Something unclear? [email protected]

Search the docs, features, comparisons, blog and changelog