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

# Advertising success tracking with referer and subreferer

> Tag deep links with a referer and subreferer, optionally keep the values in cookies, and automatically map external referers to your own values.

Every deep link into your shop can be tagged with a referer and a subreferer. This lets you see later where a visitor came from. The referer names the source; the subreferer breaks it down further, for example into individual banners with a search engine provider.

Both values are included in the order data and appear in the WEBSALE AG sales statistics, broken down by referer and, below that, by subreferer. From there, they can be passed on to an ERP system or an analytics tool.

There are three ways a referer can get into a session. They build on each other and are covered in this order.

| Way | When it applies |
| - | - |
| Call parameter on the deep link | always, overwrites a value that has already been set |
| Cookie from an earlier visit | if no parameter was passed |
| Automatic derivation from rules | if there is still no referer set after that |

## Passing the referer on the deep link

Append the values to the URL as call parameters. A referer comes into existence simply by assigning it. You do not have to create it anywhere beforehand.

```text theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
https://www.ihr-shop.de/?ref=Suchmaschine&subref=Banner-Fruehjahr
https://www.ihr-shop.de/<sprechender Name>?ref=Suchmaschine&subref=Banner-Fruehjahr
```

| Parameter | Meaning |
| - | - |
| `ref` | Referer |
| `subref` or `subreferer` | Subreferer; both spellings are accepted |
| `refhex` | Referer, hexadecimal encoded |
| `subrefhex` | Subreferer, hexadecimal encoded |

> [!NOTE]
>
> The hexadecimal variants only apply if the respective plain text parameter is missing. They are useful when a value contains characters that are difficult to transport in a URL.

> [!NOTE]
>
> A referer or subreferer can be overwritten at any time by calling again with `ref` or `subref`, even in the middle of an ongoing session. The value passed last wins.

> [!NOTE]
>
> The shop removes line breaks and quotation marks from both values before writing them to a cookie. The values come directly from the URL, and without this cleanup, they could be used to inject foreign cookie attributes.

> [!NOTE]
>
> If the call comes from an app and no referer has been set yet, the shop automatically enters the referer `WS-APP`. So this value appears in your statistics even if you have never assigned it.

Guide: Calling up a shop or subshop · Internal deep links

Materials: URL parameters

## Keeping the referer in a cookie

By default, a referer only applies to the current session. Optionally, the shop stores it in a cookie and reads it again on a subsequent visit. This means that even a purchase days later is still attributed to the original source.

Activate the function in the shop configuration `shop.config` in the `Basic` section.

```ini theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
<Basic>
   ...
   SetRefererCookie  = yes
   RefererCookieDays = 30
   ...
</Basic>
```

| Parameter | Meaning |
| - | - |
| `SetRefererCookie` | with `yes`, referer and subreferer are stored in cookies |
| `RefererCookieDays` | validity period in days. If not specified, or with a value of 0 or less, 30 days apply |

The shop creates two cookies:

| Cookie | Content |
| - | - |
| `ws_<Shop>_<Sprache>_ref` | the referer |
| `ws_<Shop>_<Sprache>_subref` | the subreferer |

> [!NOTE]
>
> Both cookies are only written if the respective value is filled, and they get the same validity period. A visitor with a referer but without a subreferer therefore only receives the first cookie.

> [!WARNING]
>
> The language code is part of the cookie name. If a visitor switches language, the shop does not find the cookie of the other language and starts there without a referer.

> [!NOTE]
>
> The referer `WSTopRank` is always stored in the cookie, even if `SetRefererCookie` is not set to `yes`.

### Consent

The referer cookie is stored in the shop as a service requiring consent. If you use consent management in production, the WEBSALE service `RefererCookie` must be assigned to a consent entry that has been agreed to.

> [!WARNING]
>
> Without consent, the shop neither writes the two cookies nor reads them, and it does so without any message. Your attribution across multiple visits then silently falls back to session assignment. If advertising results suddenly look worse than expected, first check whether this service is in a group that has been agreed to.

> [!NOTE]
>
> Please coordinate the use of these cookies with your data protection officer. A cookie that assigns an advertising source to a visitor over weeks serves to measure success, not to operate the shop.

Reference: Basic section

Materials: Cookies used

Guide: Consent management

## Deriving the referer automatically

Not every visitor comes via a link you built yourself. Someone coming from a search engine does not bring a `ref` parameter, only their browser's HTTP referer. With derivation rules, you turn this into your own meaningful referer so that this traffic does not remain anonymous in your statistics.

![Referrer](https://mintcdn.com/websaleag-44ee7ea6/UyjGmXApgB40YKCW/images/referrer.jpg?fit=max\&auto=format\&n=UyjGmXApgB40YKCW\&q=85\&s=da29d3c3df03b2ae1294b26399ff7622)

> [!NOTE]
>
> Derivation only runs after call parameters and cookies have been evaluated, and only if there is still no referer set after that. A referer you have assigned is therefore never overwritten by a rule.

### Configuring the rules

The rules are located in the `shop.config` in the `RefererDerivation` section. A rule checks a condition and, if it matches, sets a referer. Optionally, it refers to a rule set that also determines the subreferer.

```ini theme={"theme":{"light":"github-light","dark":"github-dark"},"languages":{"custom":["/languages/websale.json"]}}
<RefererDerivation>
   <+RefererRule>
      Source               = HTTPReferer
      Type                 = Contains
      Value                = bing
      SetReferer           = Microsoft Bing
      UseSubRefererRuleSet = def
   </+RefererRule>

   <+SubRefererRuleSet>
      ID                = def
      DefaultSubReferer = BRAND-DEFAULT
      <+SubRefererRule>
         Source        = Path
         Type          = ExactMatch
         Value         = /mein-shop
         SetSubReferer = BRAND Mein-Shop
      </+SubRefererRule>
   </+SubRefererRuleSet>
</RefererDerivation>
```

This example does the following:

| Step | Parameter | Effect |
| - | - | - |
| 1 | `Source = HTTPReferer` | The HTTP referer passed by the browser is checked |
| 2 | `Type = Contains`, `Value = bing` | Does it contain the string `bing`? |
| 3 | `SetReferer = Microsoft Bing` | If so, the referer is set to this value |
| 4 | `UseSubRefererRuleSet = def` | Then the subreferer rule set with the ID `def` runs |
| 5 | `Source = Path`, `Type = ExactMatch`, `Value = /mein-shop` | It checks whether the called path is exactly `/mein-shop` |
| 6 | `SetSubReferer = BRAND Mein-Shop` | If so, the subreferer is set to this value |
| 7 | `DefaultSubReferer = BRAND-DEFAULT` | If no subreferer rule applies, this value is used |

### The possible values

For `Source` and `Type`, there are exactly two values each, in both `+RefererRule` and `+SubRefererRule`.

| Parameter | Value | Meaning |
| - | - | - |
| `Source` | `HTTPReferer` | the HTTP referer passed by the browser |
| `Source` | `Path` | the called path |
| `Type` | `Contains` | the value occurs in the source |
| `Type` | `ExactMatch` | the source matches the value exactly |

> [!NOTE]
>
> A subreferer rule may also use `HTTPReferer` as its source. You are not limited to the path just because the example shows it.

> [!WARNING]
>
> Write `Contains` and `ExactMatch` exactly like this. A typo in the value does not lead to an error message, but to the rule not applying.

> [!NOTE]
>
> `DefaultSubReferer` is the reason a rule set is useful even if none of its rules apply. Without this value, the subreferer would remain empty, and all derived traffic would appear in the statistics under a single referer without further breakdown.

Reference: RefererDerivation section

## Related topics

* Guide: Calling up a shop or subshop
* Guide: Internal deep links
* Materials: Cookies used


## Related topics

- [CHECK- (URL and cookie data)](https://dokumentation.websale.de/en/v8s/referenz/tags/check.md)
- [SEO URLs and link optimization](https://dokumentation.websale.de/en/v8s/seo/seo-urls-und-link-optimierung.md)
- [Cookies used](https://dokumentation.websale.de/en/v8s/referenz/verwendete-cookies.md)
- [External services and interfaces](https://dokumentation.websale.de/en/v8s/referenz/konfigurationen/shopkonfiguration-shop-config/externe-dienste-und-schnittstellen.md)
- [Integrating tracking](https://dokumentation.websale.de/en/v8s/funktionen-zur-shop-optimierung/tracking-einbinden.md)


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