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

# Attribution rules

> Teach website analytics your own channel rules for partner domains, offline campaign tags or an agency's UTM conventions, and re-apply them to past visits.

Every website visit gets a **channel** (direct, search, social, email, paid, AI or referral), a channel group and a source. Built-in rules already recognize the major search engines, social networks, mailbox providers and AI assistants. Add your own rule when you know something they can't, such as a partner's domain, an offline campaign tag or a medium your agency uses.

Rules live at **Analytics → Attribution Rules**. Every role can read them, because they explain the charts. Only owners and administrators can change them.

## How rules are applied

1. The built-in classifier runs first and gives every visit its starting values.
2. **Every** enabled rule whose conditions match then runs, highest **Priority** first.
3. If two rules write the same field, the higher-priority rule wins.
4. Any field your rules don't touch keeps the built-in value.

This isn't "first match wins". A low-priority catch-all rule with no conditions matches every visit. With **default to** actions, it fills only the fields nothing else has set.

### Actions

| Action         | What it does                                                                                    |
| -------------- | ----------------------------------------------------------------------------------------------- |
| **set to**     | Writes the value, unless a higher-priority rule already set that field.                         |
| **clear**      | Empties the field, with the same priority rules as **set to**.                                  |
| **default to** | Writes the value only if the field is still empty. It never blocks a lower-priority **set to**. |

The fields a rule can write are **Channel**, **Channel group**, **UTM source**, **UTM medium**, **UTM campaign**, **UTM content**, **UTM term** and **Referrer domain**.

### Conditions

A condition compares one fact about the visit with a value. Facts include the UTM tags, **Ad click ID** and its type, **Referrer URL**, **Referrer domain** and **Referrer path**, **Is direct**, **Landing page**, **Landing domain** and **Landing path**, **Device**, **Browser**, **Operating system** and **Browser language**.

Operators include **is**, **is not**, **contains**, **does not contain**, **starts with**, **ends with**, **is the domain (or a subdomain)**, **matches regex**, **is set** and **is not set**. Under **How conditions combine**, choose whether a visit must match **all of the conditions** or **any of the conditions**.

Visits from your own site's domain count as internal navigation, and a referrer rule can't claim them.

## Create a rule

<Steps>
  <Step title="Start a rule">
    Click **New rule**. Give it a **Name**, and optionally **Tags** to keep rules organized.
  </Step>

  <Step title="Add conditions">
    Under **When**, click **Add condition** and pick a field, an operator and a value. For example: **Referrer domain** **is the domain (or a subdomain)** `partners.example.com`.
  </Step>

  <Step title="Add actions">
    Under **Actions**, click **Add action**. For example: **Channel** **set to** `referral`, **UTM source** **set to** `partner-portal`.
  </Step>

  <Step title="Set the priority">
    A higher **Priority** runs first and wins conflicts.
  </Step>

  <Step title="Test it">
    Use **Test this rule**: describe a visit (empty boxes count as absent) and click **Test**. The result shows whether the rule matches and what it would write. The test uses the same logic as live tracking.
  </Step>

  <Step title="Save">
    Click **Add rule**. Use the up and down arrows to reorder rules, and the toggle to turn a rule on or off.
  </Step>
</Steps>

## Starter rules

If your workspace has no generated rules yet, **Add starter rules** writes the built-in classification (search engines, social networks, mailbox providers, AI assistants, paid click ids and the standard UTM mediums) as ordinary, editable rules. Rules you already wrote are kept and moved above the starter rules, so they still win.

<Warning>
  After you add starter rules, the rules **are** the classification. The built-in platform lists stop running underneath them. Deleting the "Google" search rule, for example, really does stop visits from google.com being counted as search. You can add starter rules only once per workspace.
</Warning>

## Re-run over past visits

A rule only affects visits recorded **after** you save it. To apply your enabled rules to visits you've already collected:

1. Click **Re-run over past visits**.
2. Choose **How much history to re-run**: last 30 days, last 90 days, last 12 months or all time.
3. Click **Re-run attribution**.

Progress shows as visits checked and re-classified. It's safe to run more than once, because it only changes visits whose channel, group or source actually changes. After you delete a rule, run a re-run to re-classify the visits that rule had labeled.

## Troubleshooting

<AccordionGroup>
  <Accordion title="My rule doesn't seem to apply">
    Check that it's enabled. Use **Test this rule** with the values of a real visit. Check whether a higher-priority rule writes the same field. Remember that rules only apply to new visits until you re-run.
  </Accordion>

  <Accordion title="A regex pattern is refused when saving">
    **matches regex** is case-insensitive and matches anywhere in the value, so anchor it with `^` and `$` if you need an exact match. Patterns longer than 200 characters, or with nested repetition such as `(a+)+` that could slow tracking down, are refused.
  </Accordion>
</AccordionGroup>
