---
title: "Share campaign links"
description: "Share a pricing link with a discount code and UTM attribution: useCampaign reads both from the address, the pricing page carries them through sign-in into checkout, and the provider stores the attribution on the order."
canonical_url: "https://nuxt-backend.dev/docs/build/growth/offers/campaign-links"
---
# Share campaign links

> Share a pricing link with a discount code and UTM attribution: useCampaign reads both from the address, the pricing page carries them through sign-in into checkout, and the provider stores the attribution on the order.

Version: nuxt-backend 0.6.x · Tab: Build · Kind: how-to · Status: stable

Every page: [llms.txt](https://nuxt-backend.dev/llms.txt) · Skill for coding agents: [nuxt-backend](https://nuxt-backend.dev/.well-known/skills/nuxt-backend/SKILL.md)

Commands use npm; use your project's package manager.

- [Try it live in the playground](https://nuxt-backend.dev/playground/pricing)
- [API reference](https://nuxt-backend.dev/docs/reference/api/use-campaign)
- [Source](https://github.com/qruto/nuxt-backend/blob/main/src/runtime/vue/composables/use-campaign.ts)

A campaign link tells you which newsletter, post or partner brought a customer, and can hand them a discount on the way. It is a link to your pricing page with the campaign in its query:

```text
https://example.com/pricing?discount=LAUNCH20&utm_source=newsletter&utm_medium=email&utm_campaign=autumn
```

Everyone who follows it and buys checks out with the code applied, and the order or subscription records where they came from. Nothing is stored on the visitor's device: the campaign lives in the address, and a sign-in on the way keeps it.

- **Natively:** Polar applies a discount code at checkout, and copies a checkout's metadata to the order and the subscription it creates (checked on 2026-10-25).
- **The package adds:** `useCampaign()`, which reads the code and the UTM values from the address, a pricing page that carries them through sign-in into checkout, and a fallback to the regular price when the code no longer applies.

## Make the link

The link carries two kinds of value:

- **The discount code** goes in `?discount=`, or the provider's own name for it, `?discount_code=`. It must be a code the provider knows, letters and digits only. Declare it as a [promotion](https://nuxt-backend.dev/docs/build/growth/offers) in the catalog and the pricing page also shows its terms and end date, or create one from your server with `billing.discounts` ([Offer discounts](https://nuxt-backend.dev/docs/build/growth/offers/discounts)). The page never shows the code, and a value that could not be a code never reaches checkout.
- **The attribution** goes in `utm_source`, `utm_medium`, `utm_campaign`, `utm_term` and `utm_content`, the parameters analytics tools already use. Keep them campaign-level (`newsletter`, `autumn`): they are for counting, never for identifying a person.

Point the link at `/pricing`, or at any page of yours with `<PricingTable>` on it.

## What happens on the way

1. The visitor lands on the pricing page, and `<PricingTable>` reads the campaign with `useCampaign()`.
2. Signed out, they press "Sign in to subscribe". The sign-in page returns them to the address they left, query included.
3. They pick a plan or a pack. The checkout carries the code and the attribution: the server applies the code with the provider's own check, and writes the attribution as `utm_*` metadata, which the provider copies to the order and the subscription.

A code the provider does not accept (unknown, expired, used up, not for this product) never blocks the purchase. The server refuses that checkout with `invalid_input` on `discountCode`, and `<PricingTable>` opens it again at once without the code, keeping the attribution and saying nothing about the code. An old campaign link keeps selling at the full price. Repeated refusals are rate-limited: see [Campaign links on checkout](https://nuxt-backend.dev/docs/build/billing/subscriptions/checkout#campaign-links) for the server's checks.

## Use it in your own checkout buttons

`useCampaign()` returns the same campaign for any checkout of yours:

```vue [app/pages/launch.vue]
<script setup lang="ts">
const { checkoutOptions, attribution } = useCampaign()
const { checkout } = useBilling()
const { plans } = usePricing()
const pro = computed(() => plans.value?.find(plan => plan.key === 'pro')?.prices.month)
</script>

<template>
  <p v-if="attribution?.campaign === 'autumn'">
    Autumn launch: the discount applies at checkout.
  </p>
  <button v-if="pro" @click="checkout(pro.productId, checkoutOptions)">
    Get Pro
  </button>
</template>
```

`discountCode` and `attribution` are read-only, computed from the current route. `checkoutOptions` holds both, ready for `useBilling().checkout` or `useCredits().topUp`. A code the provider refuses rejects your checkout with `invalid_input` on `discountCode`. To sell anyway, as the table does, call `checkout` again without `discountCode`.

## Read the results

The attribution sits on each order and subscription as metadata (`utm_source`, `utm_campaign` and the rest). Read it in any of three places:

- the provider's dashboard, filtering orders by it;
- the [billing events](https://nuxt-backend.dev/docs/build/billing/events) your app receives (`event.data.metadata.utm_campaign`);
- a campaign's orders, listed by the discount they used.

## What is stored, and where

- **On the device**: nothing. No cookie and no local storage: the campaign travels in the URL and is gone when the visitor leaves it.
- **At the billing provider**: the `utm_*` values on the order and the subscription they paid for, cut to 100 characters each. Include them in what your privacy notice says you share with the provider.
- **In your app**: nothing beyond what your own event handlers keep.

## What happens when…

- **The code is unknown, expired, used up or not for this product:** the server refuses the checkout as [`invalid_input`](https://nuxt-backend.dev/docs/reference/backend/errors#invalid_input) on `discountCode`. `<PricingTable>` opens it again without the code and keeps the attribution.
- **A visitor tries code after code:** repeated refusals are rate-limited, then refused as [`rate_limited`](https://nuxt-backend.dev/docs/reference/backend/errors#rate_limited).
- **The query holds a value that could not be a code:** it is dropped before checkout, and the page sells at the regular price.
- **A UTM value is longer than 100 characters:** it is cut to 100 before it reaches the provider.

## Limits

- **Attribution per purchase.** The UTM values land on orders and subscriptions, not on accounts. First-touch attribution of sign-ups is the [growth funnel's](https://nuxt-backend.dev/docs/build/growth/measure).
- **One code per checkout.** A campaign's code and a promotion your server picks never stack.
- **No link shortener and no click counts.** Use your newsletter or ad tool's own counts for clicks.

## Test it

Follow a campaign link signed out, sign in on the way, and check the checkout carries the campaign:

```ts [tests/campaign.spec.ts]
import { expect, test } from '@playwright/test'

test('a campaign survives sign-in', async ({ page }) => {
  await page.goto('/pricing?discount=LAUNCH20&utm_source=newsletter&utm_campaign=autumn')
  await page.getByRole('button', { name: /sign in to subscribe/i }).first().click()
  // …sign in with a code from the dev inbox…
  await expect(page).toHaveURL(/utm_campaign=autumn/)
})
```

Pay with the test card `4242 4242 4242 4242`, then find `utm_campaign` in the order's metadata in Polar's sandbox dashboard ([Run end-to-end tests](https://nuxt-backend.dev/docs/develop/testing/e2e)).

## Related

- [Polar](https://nuxt-backend.dev/docs/services/polar): the account whose orders carry the attribution.
- [Customize the pricing page](https://nuxt-backend.dev/docs/build/billing/pricing-page): the table that reads the campaign.
- [Run a promotion](https://nuxt-backend.dev/docs/build/growth/offers): declare the code a link carries, with its terms.
- [Mint discounts from your server](https://nuxt-backend.dev/docs/build/growth/offers/discounts): create codes from your server code.
- [Open checkout and the portal](https://nuxt-backend.dev/docs/build/billing/subscriptions/checkout#campaign-links): the server's checks on a code.


## Sitemap

See the full [sitemap](https://nuxt-backend.dev/sitemap.md) for all pages.
