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

# How ad attribution works

> What Pocketflows does from the first ad click through to the attributed conversion

When a end-consumer visits a booking flow through an ad, a number of things
happen from first landing on the page to final checkout. Pocketflows is involved
in many of these steps, which we'll outline here.

For the purposes of this walkthrough, we'll adopt the persona of an average
consumer signing up for a haircut. The business is called "Haircuts for Days"
— they host their website at `haircutsfordays.com` and use the SaaS
platform `haircut.ai` to manage appointment scheduling.

To set this up for your own platform, see
[Track ad conversions](https://docs.pocketflows.com/how-to/track-ad-conversions.md).

## Consumer lifecycle

| Consumer Journey | What Pocketflows Does |
| - | - |
| 1. Consumer searches "haircuts near me" on Google. `haircutsfordays.com` shows up in the "Sponsored Results" section. | |
| 2. Consumer clicks on that result - they are taken to `haircutsfordays.com?gclid=XXXX&gad_campaign_id=XXXX` | Pocketflows is loaded as a [script](https://docs.pocketflows.com/how-to/track-ad-conversions.md#step-2-install-the-tracking-script) on `haircutsfordays.com`. From this, Pocketflows stores the `gclid` and `gad_campaign_id` params as well as generates a unique identifier for the consumer |
| 3. After navigating around on the site, consumer clicks the "Schedule Appointment" button on the site and is taken to `app.haircut.ai/haircutsfordays/schedule?gclid=XXXX&gad_campaign_id=XXXX&pai=XXXX` | The same [Pocketflows script](https://docs.pocketflows.com/how-to/track-ad-conversions.md#step-2-install-the-tracking-script) loaded on `haircutsfordays.com` automatically decorates links to `app.haircut.ai` with the necessary parameters to continue conversion tracking once the consumer switches websites |
| 4. During checkout on `app.haircut.ai`, the consumer is prompted to create an account or sign in on the platform. | The same [Pocketflows script](https://docs.pocketflows.com/how-to/track-ad-conversions.md#step-2-install-the-tracking-script) is loaded on `app.haircut.ai` and after the consumer is signed in, the web page calls `.track('identify', { customer_id: 'cust_XXXX' })` with a Pocketflows customer ID (or external ID) |
| 5. Consumer finishes checkout and schedules their appointment. | On the server-side of `app.haircut.ai`, a `POST /businesses/:id/track` request is made to Pocketflows which notifies us of the purchase and the customer. From there, we are able to stitch together the consumer's journey and the subsequent ad attribution |

## Attributing the purchase

When a purchase event is received, Pocketflows automatically:

1. Looks up the customer and finds their last touch point based on tracked UTM
   parameters (e.g. `ad_campaign_id`, `campaign_id`, `trigger_id`,
   `email_blast_id`).
2. Attributes the conversion to the marketing source that drove it using
   last-touch attribution.
3. Sends the conversion event to the ad platform (e.g. Google Ads) on your
   behalf, so the platform can optimize bidding and reporting in real time.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.