# Set up payment attribution Payment attribution lets you identify which content creator referred a user who made a purchase. All purchases made by that user are attributed to that content creator, ensuring they receive the correct campaign payouts. > [!NOTE] > If purchases are made through a [creator storefront](/user-acquisition/features/creator-storefront/) or a page created with [Xsolla site builder](/web-storefront/quick-start/get-started/), no additional payment attribution setup is required — it works automatically. If you are using a custom storefront, follow the instructions below. ## How it works To enable attribution, use the `tracking_id` parameter. The `tracking_id` is a unique identifier that is used to: * track the performance of campaigns * identify which creator referred the user * collect analytics in Partner Network * correctly calculate rewards and payouts When a user follows a content creator’s personal link, Xsolla generates a unique 32-character `tracking_id` and appends it to the URL of the destination page. The destination can be any landing page associated with selling products. Pass the generated `tracking_id` in the request to generate a payment token. After the transaction is completed, the `tracking_id` is stored with the payment data and is used for attribution, analytics, and financial calculations. Example of a link with a `tracking_id` parameter: `https://webshop-external-demo.xsolla.site/?tracking_id=abcdefghijklmnopqrstuvwxyz123456` > [!NOTE] > > **Audience: all other audiences** > > Without a `tracking_id`, the payment can’t be attributed to a traffic source. Such payments aren’t included in the [performance report](https://publisher.xsolla.com/0/projects/0/network/statistics) and aren’t considered when calculating payouts to the creator. > > **End of audience: all other audiences** > > **Audience: Web games** > > Without a `tracking_id`, the payment can’t be attributed to a traffic source. Such payments aren’t included in the [performance report](https://xsolla.com/for/web-games/account/0/projects/0/network/statistics) and aren’t considered when calculating payouts to the creator. > > **End of audience: Web games** > > **Audience: Free-to-play PC games** > > Without a `tracking_id`, the payment can’t be attributed to a traffic source. Such payments aren’t included in the [performance report](https://xsolla.com/for/free-to-play-pc/account/0/projects/0/network/statistics) and aren’t considered when calculating payouts to the creator. > > **End of audience: Free-to-play PC games** > > **Audience: Premium PC games** > > Without a `tracking_id`, the payment can’t be attributed to a traffic source. Such payments aren’t included in the [performance report](https://xsolla.com/for/premium-pc-games/account/0/projects/0/network/statistics) and aren’t considered when calculating payouts to the creator. > > **End of audience: Premium PC games** > > **Audience: Mobile games** > > Without a `tracking_id`, the payment can’t be attributed to a traffic source. Such payments aren’t included in the [performance report](https://xsolla.com/for/mobile-games/account/0/projects/0/network/statistics) and aren’t considered when calculating payouts to the creator. > > **End of audience: Mobile games** > To pass `tracking_id` when generating a payment token: 1. [Get the tracking_id from the query parameters in the URL](/user-acquisition/integration-guide/setup-payment-attribution/#pn_get_payment_attribution). 2. Save it to the browser's `localStorage`. 3. [Include tracking_id in the request to generate the payment token](/user-acquisition/integration-guide/setup-payment-attribution/#pn_pass_payment_attribution). ## Get tracking_id Retrieving the `tracking_id` on the client side depends on your integration type. You can either implement your own logic to extract the `tracking_id` or use the [Partner Network script](/user-acquisition/integration-guide/setup-payment-attribution/?tabs=100-PartnerNetwork_200-SiteBuilder) provided by Xsolla. Payment attribution works the same regardless of the type of sales pages, including storefronts, individual items or game key pages, and multi-game catalogs. > [!NOTE] > Make sure the script runs before any other JavaScript that modifies the URL. Otherwise, the `tracking_id` may be lost. This script automatically extracts `tracking_id` from the URL's query parameters and saves it to `localStorage`. To retrieve the stored value, the `getTrackingId()` method is provided, which is called when generating a payment token. Detailed implementation examples are provided in the tabs below. **Tab: Partner Network script** This script automatically extracts the `tracking_id` from the URL’s query parameters, saves it to `localStorage`, and provides the `getTrackingId()` method to use when generating a payment token. Add the following script to your landing page’s HTML: ```html ``` > [!NOTE] > The script must be loaded on all pages where a payment token may be generated. **Tab: JavaScript snippet** The snippet below extracts the `tracking_id` from the URL and saves it to `localStorage`. `tracking_id` processing JavaScript snippet: ```javascript (function () { const XPN_TRACKING_ID = 'xsolla_partner_network_tracking_id'; const TRACKING_ID = 'tracking_id'; function removeTrackingIdFromUrl() { if (window.history && window.history.replaceState) { const url = new URL(window.location.href); url.searchParams.delete(TRACKING_ID); window.history.replaceState(null, '', url.toString()); } } function extractTrackingIdFromURL() { try { const savedTrackingId = localStorage.getItem(XPN_TRACKING_ID); const searchParams = new URLSearchParams(window.location.search); const trackingId = searchParams.get(TRACKING_ID) || savedTrackingId || ''; if (trackingId !== '') { localStorage.setItem(XPN_TRACKING_ID, trackingId); } removeTrackingIdFromUrl(); } catch (e) { console.error('[Xsolla Partner Network] Failed to extract tracking_id:', e); } } function getTrackingId() { return localStorage.getItem(XPN_TRACKING_ID) || null; } extractTrackingIdFromURL(); window.XsollaPartnerNetwork = window.XsollaPartnerNetwork || {}; window.XsollaPartnerNetwork.getTrackingId = getTrackingId; })(); ``` ------------------------------------------------ Regardless of how you integrate it — using the JavaScript snippet or the Partner Network script — call `XsollaPartnerNetwork.getTrackingId()` to retrieve the stored `tracking_id`: ```javascript const trackingId = XsollaPartnerNetwork.getTrackingId(); if (trackingId) { console.log('Saved tracking_id from URL:', trackingId); // add tracking_id into your request parameters } ``` ## Pass tracking_id when generating payment token Depending on how you set up your integration, use one of the options below to pass the `tracking_id` to the token generation method. > [!NOTE] > To ensure accurate attribution, make sure `tracking_id` is included in the token request. **Tab: Xsolla site builder** If your store is built with [Xsolla site builder](/web-storefront/quick-start/get-started/), no additional actions are required — `tracking_id` is handled automatically. It is extracted from the URL and added to the token request. > [!NOTE] > The `tracking_id` is automatically passed for landing pages published after May 23, 2025. To enable this functionality on older pages, simply republish the site. **Tab: Purchase widget** To pass `tracking_id` to the purchase widget: 1. Get the `tracking_id` on the client side (from the URL or `localStorage`). 2. Add it to `access_data.user.tracking_id.value` parameter during widget initialization: ```javascript { access_data: { user: { tracking_id: { value: "abcdefghijklmnopqrstuvwxyz123456" } } } } ``` **Tab: Pay Station Embed** > [!NOTE] > `tracking_id` can’t be passed as a widget initialization parameter. Instead, it must be included in the token’s parameter `user.tracking_id.value`. To pass `tracking_id` to [Pay Station Embed](/payment-ui-and-flow/payment-ui/how-to-open-payment-ui/#pay_station_guide_pay_station_embed): 1. Get the `tracking_id` on the client side (from the URL or `localStorage`). 2. Pass this parameter while [generating payment token](/api/pay-station/token/create-token/): ```json { "user": { "tracking_id": { "value": "abcdefghijklmnopqrstuvwxyz123456" } } } ``` 3. Use the `access_token` to initialize the widget: ```javascript XPayStationWidget.init({ access_token: 'your_token_with_tracking_id' }); ``` > [!NOTE] > Using `access_data` instead of `access_token` is deprecated. If your integration doesn’t support `access_token`, pass `tracking_id` in the `access_data.user.tracking_id.value` parameter – as shown in the [purchase widget](/user-acquisition/integration-guide/setup-payment-attribution/?tabs=100-PartnerNetwork_200-PurchaseWidget). **Tab: Headless checkout** To pass `tracking_id` with [Headless checkout](/sdk-fuctional-and-ui/headless-checkout/): 1. Get the `tracking_id` on the client side (from the URL or `localStorage`). 2. Add it to `user.tracking_id.value` parameter while [generating payment token](/api/pay-station/token/create-token/). 3. [Initialize the SDK](/sdk-fuctional-and-ui/headless-checkout/integration-guide/install-sdk) using the `headlessCheckout.init()` method. 4. Pass the token using: ```javascript await headlessCheckout.setToken('your_token_with_tracking_id'); ``` **Tab: API Xsolla** ### Payment token on client side Use this option if you generate the payment token via one of the following API calls: * [Create order with all items from current cart](/api/catalog/payment-client-side/create-order/) * [Create order with all items from particular cart](/api/catalog/payment-client-side/create-order-by-cart-id/) * [Create order with specified item](/api/catalog/payment-client-side/create-order-with-item/) To pass `tracking_id` while generating payment token: 1. Get the `tracking_id` on the client side (from the URL or `localStorage`). 2. Add it to the `user.tracking_id.value` parameter. **Example:** ```json { "user": { "tracking_id": { "value": "abcdefghijklmnopqrstuvwxyz123456" } } } ``` > [!NOTE] > This option is client-side only. Country and currency are determined by the user’s IP address. ### Payment token on the server side Use this option if you generate the payment token via the [Create payment token for purchase](/api/catalog/payment-server-side/admin-create-payment-token/) API call. To pass `tracking_id` while generating payment token: 1. Get the `tracking_id` on the client side (from the URL or `localStorage`). 2. Add it to the `user.tracking_id.value` parameter. **Example:** ```json { "user": { "tracking_id": { "value": "abcdefghijklmnopqrstuvwxyz123456" } } } ``` **Tab: Xsolla SDK for Unity (legacy/enterprise)** To pass `tracking_id` using [Xsolla SDK for Unity (legacy/enterprise)](/sdk-client-side/unity-enterprise/): 1. Make sure you’re using a [recent SDK version](https://github.com/xsolla/store-unity-sdk/releases) that supports `tracking_id`. 2. Get the `tracking_id` on the client side (e.g., via [deeplink](https://docs.unity3d.com/Manual/deep-linking.html)). 3. Pass it to the `Xsolla.Core.PurchaseParams` object. **Example:** ```csharp var purchaseParams = new PurchaseParams { tracking_id = "abcdefghijklmnopqrstuvwxyz123456" }; ```