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

# Dynamic Traffic Routing

> Send different visitors to different destinations from one link.

Dynamic Traffic Routing lets a single link resolve to different destinations depending on who clicked it — country, device, language — with a default for everyone else.

One link on a poster can send iOS users to the App Store, Android users to Play, and everyone else to your website.

```bash cURL theme={null}
curl -X POST "https://api.dashlink.ai/api/v1/shortlinks/create_shortlink" \
  -H "X-API-Key: $DASHLINK_API_KEY" \
  -F "destination_url=https://example.com/download" \
  -F "dynamic_routing_enabled=true" \
  -F 'routing_rules=[
    {"condition":"os","operator":"equals","value":"iOS",
     "destination_url":"https://apps.apple.com/app/id123456"},
    {"condition":"os","operator":"equals","value":"Android",
     "destination_url":"https://play.google.com/store/apps/details?id=com.example"}
  ]'
```

```javascript Node.js theme={null}
const body = new FormData();
body.append("destination_url", "https://example.com/download");
body.append("dynamic_routing_enabled", "true");
body.append("routing_rules", "[\n    {\"condition\":\"os\",\"operator\":\"equals\",\"value\":\"iOS\",\n     \"destination_url\":\"https://apps.apple.com/app/id123456\"},\n    {\"condition\":\"os\",\"operator\":\"equals\",\"value\":\"Android\",\n     \"destination_url\":\"https://play.google.com/store/apps/details?id=com.example\"}\n  ]");

const response = await fetch("https://api.dashlink.ai/api/v1/shortlinks/create_shortlink", {
  method: "POST",
  headers: { "X-API-Key": process.env.DASHLINK_API_KEY },
  body,
});
const payload = await response.json();
```

```python Python theme={null}
import os
import requests

response = requests.post(
    'https://api.dashlink.ai/api/v1/shortlinks/create_shortlink',
    headers={'X-API-Key': os.environ["DASHLINK_API_KEY"]},
    data={
        'destination_url': 'https://example.com/download',
        'dynamic_routing_enabled': 'true',
        'routing_rules': '[\n    {"condition":"os","operator":"equals","value":"iOS",\n     "destination_url":"https://apps.apple.com/app/id123456"},\n    {"condition":"os","operator":"equals","value":"Android",\n     "destination_url":"https://play.google.com/store/apps/details?id=com.example"}\n  ]',
    },
)
payload = response.json()
```

```go Go theme={null}
package main

import (
	"fmt"
	"io"
	"net/http"
	"os"
	"net/url"
	"strings"
)

func main() {
	endpoint0 := "https://api.dashlink.ai/api/v1/shortlinks/create_shortlink"
	form0 := url.Values{
		"destination_url": {"https://example.com/download"},
		"dynamic_routing_enabled": {"true"},
		"routing_rules": {"[\n    {\"condition\":\"os\",\"operator\":\"equals\",\"value\":\"iOS\",\n     \"destination_url\":\"https://apps.apple.com/app/id123456\"},\n    {\"condition\":\"os\",\"operator\":\"equals\",\"value\":\"Android\",\n     \"destination_url\":\"https://play.google.com/store/apps/details?id=com.example\"}\n  ]"},
	}
	req0, err0 := http.NewRequest("POST", endpoint0, strings.NewReader(form0.Encode()))
	if err0 != nil {
		panic(err0)
	}
	req0.Header.Set("Content-Type", "application/x-www-form-urlencoded")
	req0.Header.Set("X-API-Key", os.Getenv("DASHLINK_API_KEY"))
	resp0, err0b := http.DefaultClient.Do(req0)
	if err0b != nil {
		panic(err0b)
	}
	defer resp0.Body.Close()
	body0, _ := io.ReadAll(resp0.Body)
	fmt.Println(string(body0))
}

```

```ruby Ruby theme={null}
require "net/http"
require "json"
require "uri"

uri0 = URI("https://api.dashlink.ai/api/v1/shortlinks/create_shortlink")
request0 = Net::HTTP::Post.new(uri0)
request0["X-API-Key"] = ENV.fetch("DASHLINK_API_KEY")
request0.set_form_data("destination_url" => "https://example.com/download", "dynamic_routing_enabled" => "true", "routing_rules" => "[\n    {\"condition\":\"os\",\"operator\":\"equals\",\"value\":\"iOS\",\n     \"destination_url\":\"https://apps.apple.com/app/id123456\"},\n    {\"condition\":\"os\",\"operator\":\"equals\",\"value\":\"Android\",\n     \"destination_url\":\"https://play.google.com/store/apps/details?id=com.example\"}\n  ]")
response0 = Net::HTTP.start(uri0.hostname, uri0.port, use_ssl: true) do |http|
  http.request(request0)
end
payload0 = JSON.parse(response0.body)
```

```php PHP theme={null}
<?php
$ch0 = curl_init('https://api.dashlink.ai/api/v1/shortlinks/create_shortlink');
curl_setopt($ch0, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch0, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch0, CURLOPT_HTTPHEADER, [
    "X-API-Key: " . getenv("DASHLINK_API_KEY"),
]);
curl_setopt($ch0, CURLOPT_POSTFIELDS, http_build_query(['destination_url' => 'https://example.com/download', 'dynamic_routing_enabled' => 'true', 'routing_rules' => '[
    {"condition":"os","operator":"equals","value":"iOS",
     "destination_url":"https://apps.apple.com/app/id123456"},
    {"condition":"os","operator":"equals","value":"Android",
     "destination_url":"https://play.google.com/store/apps/details?id=com.example"}
  ]']));
$payload0 = json_decode(curl_exec($ch0), true);
curl_close($ch0);
```

`destination_url` on the link itself is the fallback when no rule matches. It is required, and it is what most of your visitors will get — set it deliberately rather than treating it as a leftover.

## Rule shape

```json theme={null}
{
  "condition": "country",
  "operator": "equals",
  "value": "IN",
  "destination_url": "https://example.com/in"
}
```

| Field | Notes |
| - | - |
| `condition` | What to match on: `country`, `os`, `device`, `browser`, `language` |
| `operator` | `equals`, `not_equals`, `in`, `not_in` |
| `value` | What to match against. An array for `in` and `not_in` |
| `destination_url` | Where a match goes |

## Order decides the outcome

Rules are evaluated top to bottom and the **first match wins**. A broad rule above a narrow one means the narrow one never runs:

```json theme={null}
[
  {"condition":"country","operator":"in","value":["IN","LK","BD"],
   "destination_url":"https://example.com/south-asia"},

  {"condition":"country","operator":"equals","value":"IN",
   "destination_url":"https://example.com/in"}
]
```

The India-specific rule here is dead — the regional rule above it already matched. Put specific rules first.

## Grouping several countries

```json theme={null}
{
  "condition": "country",
  "operator": "in",
  "value": ["DE", "AT", "CH"],
  "destination_url": "https://example.com/de"
}
```

Countries are ISO 3166-1 alpha-2 codes.

## Checking it works

`get_shortlink_routing_analytics` shows which rules actually fired:

```bash cURL theme={null}
curl -X GET "https://api.dashlink.ai/api/v1/analytics/get_shortlink_routing_analytics?name=SHORT-0001&date_from=2026-01-01&date_to=2026-01-31" \
  -H "X-API-Key: $DASHLINK_API_KEY"
```

```javascript Node.js theme={null}
const response = await fetch("https://api.dashlink.ai/api/v1/analytics/get_shortlink_routing_analytics?name=SHORT-0001&date_from=2026-01-01&date_to=2026-01-31", {
  headers: { "X-API-Key": process.env.DASHLINK_API_KEY },
});
const payload = await response.json();
```

```python Python theme={null}
import os
import requests

response = requests.get(
    'https://api.dashlink.ai/api/v1/analytics/get_shortlink_routing_analytics?name=SHORT-0001&date_from=2026-01-01&date_to=2026-01-31',
    headers={'X-API-Key': os.environ["DASHLINK_API_KEY"]},
)
payload = response.json()
```

```go Go theme={null}
package main

import (
	"fmt"
	"io"
	"net/http"
	"os"
)

func main() {
	endpoint0 := "https://api.dashlink.ai/api/v1/analytics/get_shortlink_routing_analytics?name=SHORT-0001&date_from=2026-01-01&date_to=2026-01-31"
	req0, err0 := http.NewRequest("GET", endpoint0, nil)
	if err0 != nil {
		panic(err0)
	}
	req0.Header.Set("X-API-Key", os.Getenv("DASHLINK_API_KEY"))
	resp0, err0b := http.DefaultClient.Do(req0)
	if err0b != nil {
		panic(err0b)
	}
	defer resp0.Body.Close()
	body0, _ := io.ReadAll(resp0.Body)
	fmt.Println(string(body0))
}

```

```ruby Ruby theme={null}
require "net/http"
require "json"
require "uri"

uri0 = URI("https://api.dashlink.ai/api/v1/analytics/get_shortlink_routing_analytics?name=SHORT-0001&date_from=2026-01-01&date_to=2026-01-31")
request0 = Net::HTTP::Get.new(uri0)
request0["X-API-Key"] = ENV.fetch("DASHLINK_API_KEY")
response0 = Net::HTTP.start(uri0.hostname, uri0.port, use_ssl: true) do |http|
  http.request(request0)
end
payload0 = JSON.parse(response0.body)
```

```php PHP theme={null}
<?php
$ch0 = curl_init('https://api.dashlink.ai/api/v1/analytics/get_shortlink_routing_analytics?name=SHORT-0001&date_from=2026-01-01&date_to=2026-01-31');
curl_setopt($ch0, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch0, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch0, CURLOPT_HTTPHEADER, [
    "X-API-Key: " . getenv("DASHLINK_API_KEY"),
]);
$payload0 = json_decode(curl_exec($ch0), true);
curl_close($ch0);
```

A rule with zero matches is usually one of three things: it is shadowed by a broader rule above it, the value is wrong (`UK` instead of `GB`), or nobody in that segment has clicked yet.

> [!TIP]
>
> Check this a day after launching a routed link. A shadowed rule is invisible until you look, and every visitor it should have caught went to the fallback instead.

## Keep the set small

Every rule is evaluated on every click. Two or three broad rules plus a good fallback is almost always better than twenty narrow ones — easier to reason about, easier to debug, and the long tail of rules usually catches nobody.


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