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

# Get one visitor’s attribution

> The visitor’s attribution record, by the first-party visitor ID (fetchski_vid) seen on their events.

```ts AdonisJS wrap theme={"dark"}
import app from '@adonisjs/core/services/app'
import { SiteClient } from '@fetchski/attract-cms-sdk'

const site = await app.container.make(SiteClient)
const getVisitorAttribution = await site.visitorAttribution().getVisitorAttribution({ visitorId: '0b8e6a4c-8d2f-4b6e-9a1c-3f5d7e9b1a2c' })
```

```json 200 wrap theme={"dark"}
{
  "attribution": {
    "visitorId": "0b8e6a4c-8d2f-4b6e-9a1c-3f5d7e9b1a2c",
    "firstTouch": {
      "at": "2026-09-20T09:12:00.000Z",
      "path": "/",
      "landingUrl": "https://example.com/?gclid=Cj0KCQjw&utm_source=google",
      "referrerOrigin": "https://www.google.com",
      "adPlatforms": [
        "google"
      ],
      "campaign": {
        "utm_source": "google",
        "utm_campaign": "spring-sale"
      },
      "clickIds": {
        "gclid": "Cj0KCQjw"
      }
    },
    "browserIds": {
      "_gcl_au": "1.1.1234567890.1790000000"
    },
    "marketing": true,
    "firstSeenAt": "2026-09-20T09:12:00.000Z",
    "lastSeenAt": "2026-09-21T15:04:05.000Z",
    "expiresAt": "2027-03-20T15:04:05.000Z"
  }
}
```

## In your app

A controller answers a route on your app: it calls `getVisitorAttribution()` and returns the answer.

**1. Add the controller**

```ts app/controllers/get_visitor_attribution_controller.ts theme={"dark"}
import { inject } from '@adonisjs/core'
import type { HttpContext } from '@adonisjs/core/http'
import { SiteClient } from '@fetchski/attract-cms-sdk'

@inject()
export default class GetVisitorAttributionController {
  constructor(protected site: SiteClient) {}

  async handle({ params }: HttpContext) {
    return this.site.visitorAttribution().getVisitorAttribution({ visitorId: params.visitorId })
  }
}
```

**2. Add the route**

```ts start/routes.ts theme={"dark"}
import router from '@adonisjs/core/services/router'

const GetVisitorAttributionController = () => import('#controllers/get_visitor_attribution_controller')

router.get('/visitor-attribution/:visitorId', [GetVisitorAttributionController])
```

**3. Call it**

```bash Terminal theme={"dark"}
curl http://localhost:3333/visitor-attribution/0b8e6a4c-8d2f-4b6e-9a1c-3f5d7e9b1a2c
```

With `node ace serve` running, it prints its answer as JSON.

> [accordion] Required parameters
>
> One object, e.g. `getVisitorAttribution({ visitorId })`; leave out the optional fields.
>
> **visitorId** `string` *required*
>
> **Required.** The visitor ID. At most 128 characters.

> [accordion] Returns
>
> A `GetVisitorAttributionResponse`. The record. Read its properties (`getVisitorAttribution.attribution`): each says whether the site always sends it.
>
> **attribution** `VisitorAttribution`
>
> **Always sent.** A `VisitorAttribution`. One visitor’s attribution record. Kept for the site’s retention setting after the visitor’s last page view.
>
> **VisitorAttribution**
>
> **visitorId** `string`
>
> **Always sent.**
>
> **firstTouch** `AttributionTouch`
>
> **Always sent.** An `AttributionTouch`. One touch of a visitor’s journey on this site. Identifier values (`clickIds`, `linker`) appear only when the visitor allowed Marketing.
>
> **AttributionTouch**
>
> The visitor’s first visit on record; null when unknown.
>
> **at** `Date`
>
> **Sometimes sent:** `undefined` when the site leaves it out. When the page view happened. Format: an ISO 8601 date and time.
>
> **path** `string`
>
> **Sometimes sent:** `undefined` when the site leaves it out. The page’s path.
>
> **landingUrl** `string`
>
> **Sometimes sent:** `undefined` when the site leaves it out. The full landing URL. Without Marketing consent its identifier parameters are removed. Format: an absolute URL.
>
> **referrerOrigin** `string | null`
>
> **Sometimes sent:** `undefined` when the site leaves it out, and it can be `null`. Where the visitor came from; null for a direct visit.
>
> **adPlatforms** `readonly AdPlatforms[]`
>
> **Sometimes sent:** `undefined` when the site leaves it out. Platforms whose ad click ID the URL carried — kept for every visitor, consent or not. Each one of `google`, `meta`, `tiktok`, `other`.
>
> **campaign** `Readonly\<Record\<string, string\>\>`
>
> **Sometimes sent:** `undefined` when the site leaves it out. UTM and campaign parameters (`utm_*`, `gad_source`, `gad_campaignid`, `srsltid`).
>
> **clickIds** `Readonly\<Record\<string, string\>\>`
>
> **Sometimes sent:** `undefined` when the site leaves it out. Ad click IDs (`gclid`, `gbraid`, `wbraid`, `fbclid`, `ttclid`). Marketing only.
>
> **linker** `Readonly\<Record\<string, string\>\>`
>
> **Sometimes sent:** `undefined` when the site leaves it out. Google’s cross-domain linker value (`_gl`). Marketing only.
>
> **marketing** `boolean`
>
> **Always sent.** Whether the visitor allowed Marketing on their latest page view.
>
> **firstSeenAt** `Date`
>
> **Always sent.** Format: an ISO 8601 date and time.
>
> **lastSeenAt** `Date`
>
> **Always sent.** Format: an ISO 8601 date and time.
>
> **expiresAt** `Date`
>
> **Always sent.** Format: an ISO 8601 date and time.
>
> **lastTouch** `AttributionTouch`
>
> **Sometimes sent:** `undefined` when the site leaves it out. An `AttributionTouch`. One touch of a visitor’s journey on this site. Identifier values (`clickIds`, `linker`) appear only when the visitor allowed Marketing. Its fields are listed under the first `AttributionTouch` above.
>
> **browserIds** `Readonly\<Record\<string, string\>\>`
>
> **Sometimes sent:** `undefined` when the site leaves it out. Ad-platform browser IDs (`_gcl_au` — the cross-site key — `_gcl_aw`, `_gcl_gb`, `_gcl_gs`, `_gcl_dc`, `_ga`, `_fbp`, `_fbc`, `_ttp`). Marketing only.

> [accordion] Errors
>
> Nothing to catch: the SDK retries what is safe, and throws the rest as the classes below. Your exception handler turns them into your app’s own answers, once for every call (see [Map SDK errors to responses](https://docs.fetchski-attract.com/adonisjs/calling-the-api.md#map-sdk-errors-to-responses)); catch only what you want to react to here.
>
> **AuthenticationFailed** `401`
>
> The API key is missing, malformed, unknown, disabled, expired or archived (`invalid`), or a request that must be signed — by the route, or by the key’s own signing mode — has a missing, stale or wrong signature (an upload signs its SHA-256, declared in `X-Fetchski-Content-SHA256`, in the body’s place) (`unauthorized`).
>
> **Retried first:** No. **Read:** `siteMessage`, `errorName`, `data`.
>
> **Forbidden** `403`
>
> The API key lacks the scope this route needs (the message names it), or the key is used from an address outside its allowlist.
>
> **Retried first:** No. **Read:** `siteMessage`, `errorName`, `data`.
>
> **NotFound** `404`
>
> Nothing with this identifier — or the caller may not use the Data API at all (anonymous visitors and non-admin sessions get 404 so the API is not advertised). A write while conversion tracking is switched off also answers 404.
>
> **Retried first:** No. **Read:** `siteMessage`, `errorName`, `data`.
>
> **RateLimited** `429`
>
> The key used up its reads- or writes-per-minute limit (set per key; defaults 600 / 120). Still, after the client’s own waits and retries.
>
> **Retried first:** Yes: the client waits `Retry-After` (1 s when absent; over 60 s it gives up at once) and retries, up to `retries` times (2 by default). **Read:** `retryAfter` (seconds, or null), `siteMessage`.
>
> **SiteError** `5xx`
>
> The site failed (or something in front of it did). Its logs say why.
>
> **Retried first:** A 502, 503 or 504: yes, after 0.5 s then 1 s. A 500: no. **Read:** `siteMessage`, `errorName`, `data`.
>
> **SiteUnreachable** `no answer`
>
> No answer: DNS, a refused connection, TLS, or the timeout (15 s per attempt by default).
>
> **Retried first:** Yes, after 0.5 s then 1 s. **Read:** `reason`, `neverConnected`.
>
> **RequestNotSent** `not sent`
>
> The client refused to send it (e.g. a path segment of `..`); the site never saw it.
>
> **Retried first:** No. **Read:** `reason` (what to change).
>
> **SiteRequestFailed** `any other`
>
> Any other status, or a success whose JSON doesn’t match this SDK version’s types (update the SDK).
>
> **Retried first:** No. **Read:** `reason`, `status`.
>
> **UnknownSite** `setup`
>
> `sites.forSite('acme')` named a slug `config/attract.ts` doesn’t list (with the keys in the database: no row in `attract_api_keys`).
>
> **Retried first:** No: nothing was sent. **Read:** `message`, `slug`.
>
> **SiteConfigurationError** `setup`
>
> The site’s entry is wrong: a malformed `baseUrl` or key, a key filed under another slug, or no default site. `node ace attract:check` names the fix.
>
> **Retried first:** No: nothing was sent. **Read:** `message` (what to fix).

## Behavior

* **Access:** an API key with `attribution:read` — or its group master `ads:all`, or `admin:all` — or a signed-in user holding the `attribution:view` permission. Anonymous callers get 404.
* **Rate limit:** the key’s own reads-per-minute limit, set when the key is created (default 600); over it, 429 with `Retry-After`. The client waits and retries for you; you see `RateLimited` only if that runs out.
* **Retries:** a read is safe to repeat: the client retries it on no answer, a 502/503/504 and a 429.
* **Timeout:** 15 s per attempt by default; raise `timeout` (milliseconds) in `config/attract.ts` for longer.

## More examples

```ts Or null wrap theme={"dark"}
import app from '@adonisjs/core/services/app'
import { SiteClient } from '@fetchski/attract-cms-sdk'

const site = await app.container.make(SiteClient)
const getVisitorAttribution = await site.visitorAttribution().findVisitorAttribution({ visitorId: '0b8e6a4c-8d2f-4b6e-9a1c-3f5d7e9b1a2c' }) // GetVisitorAttributionResponse | null: null when the site answers 404
```

## Test it

It calls the controller above with the SDK faked: `fakeAttract()` puts the fake in the container for this one test, and it answers every call with a valid example, so nothing leaves your machine and no key is read. Save it as `tests/unit/visitor_attribution_get_visitor_attribution.spec.ts`, then run your tests:

```ts tests/unit/visitor_attribution_get_visitor_attribution.spec.ts theme={"dark"}
import { test } from '@japa/runner'
import app from '@adonisjs/core/services/app'
import testUtils from '@adonisjs/core/services/test_utils'
import { fakeAttract } from '@fetchski/attract-cms-adonis/testing'
import GetVisitorAttributionController from '#controllers/get_visitor_attribution_controller'

test('visitorAttribution.getVisitorAttribution', async () => {
  const site = fakeAttract()

  const ctx = await testUtils.createHttpContext()
  ctx.params = { visitorId: '0b8e6a4c-8d2f-4b6e-9a1c-3f5d7e9b1a2c' }
  const controller = await app.container.make(GetVisitorAttributionController)
  await controller.handle(ctx)

  site.assertCalled('visitorAttribution.getVisitorAttribution', (args) => args.visitorId === '0b8e6a4c-8d2f-4b6e-9a1c-3f5d7e9b1a2c')
})
```

```bash Terminal theme={"dark"}
node ace test
```

**Answer with your own values:** fake `visitorAttribution.getVisitorAttribution` with `factories.GetVisitorAttributionResponse({...})`, the fields you give over a valid example (nested ones too).

```ts tests/unit/visitor_attribution_get_visitor_attribution_answers.spec.ts theme={"dark"}
import { test } from '@japa/runner'
import { factories, fakeAttract } from '@fetchski/attract-cms-adonis/testing'

test('visitorAttribution.getVisitorAttribution answers your values', async ({ assert }) => {
  const site = fakeAttract({
    'visitorAttribution.getVisitorAttribution': factories.GetVisitorAttributionResponse({ attribution: { visitorId: 'Your value' } }),
  })

  const getVisitorAttribution = await site.visitorAttribution().getVisitorAttribution({ visitorId: '0b8e6a4c-8d2f-4b6e-9a1c-3f5d7e9b1a2c' })
  assert.containSubset(getVisitorAttribution, { attribution: { visitorId: 'Your value' } })
})
```

## Related

> [card] [Find visitors by an identifier](https://docs.fetchski-attract.com/adonisjs/reference/visitor-attribution/find-visitor-attributions.md)
>
> `site.visitorAttribution().findVisitorAttributions()`

> [card] [GET /visitor-attribution/\{visitorId}](https://docs.fetchski-attract.com/api-reference/visitor-attribution/get-one-visitor’s-attribution.md)
>
> The endpoint this calls, in the API reference: the HTTP request and answer, and every rule the site checks.


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