## Attribution Window

Alpha Insights uses an attribution window to decide how long to remember where a visitor came from and which page they first landed on. This guide explains what the setting controls, what data is stored (referral URL and landing page), and how it affects your reports and order attribution.

### Where the setting lives

The attribution window is configured in Alpha Insights → Settings → General Settings, under the section Alpha Analytics & Event Tracking.

Setting name: Attribution Window Timeout (days)

Options: 1, 2, 3, 4, 5, 6, 7, 14, or 30 days. The default is 3 days if the setting is not saved.

This value is used everywhere attribution is applied: cookies, session storage, and reporting. The frontend and backend stay in sync so the same number of days is used for storing and expiring attribution data.

### What the attribution window actually sets

The attribution window controls how long two pieces of data are kept for the visitor:

1. Referral URL (referral source) – the URL of the page or site the visitor came from (e.g. a Google search results page, a Facebook post, or another website).
2. Landing page – the first page on your site that the visitor loaded (the full URL of that page).

Both are stored when the visitor first hits your site (or when first detected). They are first-touch: once set, they are not updated on later page views. They simply expire after the attribution window (in days) from when they were first set.

Referral URL is stored in the cookie `wpd_ai_referral_source` and in server-side session (PHP/WooCommerce session) as a backup. It is used to work out the traffic source (e.g. Organic Search, Google Ads, Direct, Social).

Landing page is set by JavaScript on the first page load (`document.location.href`) and stored in the cookie `wpd_ai_landing_page`. It is not overwritten by later activity; it always represents the first page they landed on within the attribution period.

When the window expires, both values are cleared. After that, a later visit or purchase will no longer be tied to that original referrer or landing page unless the visitor comes again with a new referrer/landing (which will then get a new window).

### What this means for reporting

#### Sessions and traffic source

Each stored session includes `landing_page` and `referral_url` (or equivalent). The traffic source (acquisition channel) is derived from the referral URL and any UTM or tracking parameters on the landing page. Reports that group by traffic source, acquisition channel, or landing page use this session data. If the attribution window is short, sessions that extend beyond the window no longer have a valid referral/landing and may be treated as direct or uncategorized once the data has expired.

#### Order attribution

When an order is placed, Alpha Insights copies the current referral source and landing page from the session/cookies onto the order (order meta `_wpd_ai_referral_source` and `_wpd_ai_landing_page`). So the order is attributed to whatever source and landing page were still within the attribution window at checkout.

- If the customer clicked an ad, landed on your site, and bought within the attribution window (e.g. 7 days), the order is attributed to that ad (e.g. Google Ads or Facebook).
- If they clicked an ad, left, and came back 10 days later (with a 7-day window), the referral/landing may have expired; the order can then be attributed to Direct or the new visit’s source, depending on how they returned.

So a longer window (e.g. 14 or 30 days) keeps “first touch” longer and attributes more orders to the original campaign or referrer. A shorter window (e.g. 1–3 days) attributes only orders that happen soon after the first visit; later returns may show as direct or a different source.

#### Reports that use this data

- Website Traffic / Analytics reports – Sessions and events are tied to traffic source and landing page from session data (which respects the attribution window).
- Order-level attribution – On the order edit screen, the “Session” and “Customer” sections show Traffic Source, Referral Source, and Landing Page from the order meta that was saved at checkout.
- Report Builder and data sources – Any widget or filter that uses “traffic source”, “referral source”, or “landing page” ultimately uses this same session and order data.

### Choosing a value

- Short (1–3 days): Good if you care mainly about immediate response (e.g. same-day or next-day conversions). Fewer orders will be attributed to an old click; returning visitors after the window may show as Direct.
- Medium (7 days): Common default for e‑commerce; balances “first touch” and not over-attributing to very old visits.
- Long (14–30 days): Use when your sales cycle is longer (e.g. consideration period, B2B) so that orders placed within 2–4 weeks still get attributed to the original campaign or referrer.

Changing the setting only affects new attribution (new cookies and new session data). Existing orders and already-stored sessions keep the referral and landing page they had when they were saved.

### Technical note

The attribution window is independent of session length. Sessions can expire or be extended based on activity and session timeout rules. Referral URL and landing page are stored and expired only by the attribution window (from the time they were first set), so they can outlast or underlast a given session depending on your settings. They are de-coupled from the session ID: if a session expires (e.g. 30 minutes of inactivity), the referral and landing page are not cleared and continue to expire only after the attribution window from when they were first set.

Internally, the setting is stored as days and converted to seconds for cookies and server-side expiry. The frontend (JavaScript) receives the same value in seconds so cookie expiry and reporting stay in sync.

#### For developers

You can override the attribution window programmatically with the filter `wpd_attribution_timeout_seconds`. The filter receives the computed value in seconds (from the saved days setting) and must return an integer (seconds). Example:

    add_filter( 'wpd_attribution_timeout_seconds', function( $seconds ) {
        return 14 * DAY_IN_SECONDS; // 14 days
    }, 10 );

For more on how traffic source is determined from referral URL and UTM parameters, see Traffic Source Analysis and Tracking UTM Campaigns.