---
metadata:
  - name: generator
    content: Diplodoc Platform v5.48.2
alternate:
  - https://yandex.com.tr/dev/metrika/en/management/addgoal-example.md
  - https://yandex.com.tr/dev/metrika/ru/management/addgoal-example.md
---
> **Documentation Index:** Fetch the complete configuration index at https://yandex.com.tr/dev/metrika/en/llms.txt

# Examples of creating goals

## JS event {#action}

```python translate=no
import requests
import json

your_token = '<your_token>'
counter_id = <Tag ID>

f={"goal": 
    {
        "name" :  "API JS goal",
        "type" :  "action" ,
        "conditions" : [ {
            "type" :  "exact" ,
            "url" :  "order" 
        }]
    }
}

headers={f'Authorization': 'OAuth' + your_token}
r = requests.post(url=f'https://api-metrika.yandex.net/management/v1/counter/{counter_id}/goals',
                  headers=headers,
                  json=f)

print(json.dumps(r.json(), indent=4))

```

## Multi-step goal {#step}

```python translate=no
import requests
import json

your_token = '<your_token>'
counter_id = <Tag ID>

f={"goal": 
    {
        "name" :  "API Multi-step goal",
        "type" :  "step" ,
        "is_retargeting" :  0,
        "steps" : [ {
            "name" : "First step of the multi-step goal",
            "type" : "url",
                "conditions" : [ {
                    "type" : "contain_action", #Step ID contains
                    "url" : "stepgoalID"
                }
                ]
        },
        {
            "name" : "Second step of the multistep goal",
            "type" : "url",
                "conditions" : [ {
                    "type" : "regexp_action", #Step ID matches a regular expression
                    "url" : "stepgoalID2"
                }
                ]
        },
        {
            "name" : "Third step of the multi-step goal",
            "type" : "url",
                "conditions" : [ {
                    "type" : "action", #Step ID matches
                    "url" : "stepgoalID3"
                }
                ]
        }
        ]
    }
}

headers={f'Authorization': 'OAuth' + your_token}
r = requests.post(url=f'https://api-metrika.yandex.net/management/v1/counter/{counter_id}/goals',
                  headers=headers,
                  json=f)

print(json.dumps(r.json(), indent=4))
```

## Page view {#url}

```python translate=no
import requests
import json

your_token = '<your_token>'
counter_id = <Tag ID>

f={"goal": 
    {
        "name" :  "API Page view",
        "type" :  "url" ,
        "conditions" : [ {
            "type" :  "contain" , #url contains
            "url" :  "mysite.ru/cart" 
        }]
    }
}

headers={f'Authorization': 'OAuth' + your_token}
r = requests.post(url=f'https://api-metrika.yandex.net/management/v1/counter/{counter_id}/goals',
                  headers=headers,
                  json=f)

print(json.dumps(r.json(), indent=4))   
```

## Page depth {#number}

```python translate=no
import requests
import json

your_token = '<your_token>'
counter_id = <Tag ID>

f={"goal": 
    {
        "name" :  "API Page depth",
        "type" :  "number" ,
        "depth" : 3 #Page depth
    }
}

headers={f'Authorization': 'OAuth' + your_token}
r = requests.post(url=f'https://api-metrika.yandex.net/management/v1/counter/{counter_id}/goals',
                  headers=headers,
                  json=f)

print(json.dumps(r.json(), indent=4))
```

## Click on phone number {#phone}

```python translate=no
import requests
import json

your_token = '<your_token>'
counter_id = <Tag ID>

f={"goal": 
    {
        "name" :  "API Click on phone number",
        "type" :  "phone" ,
        "hide_phone_number": 1, #Hide the phone number (1 - yes, 0 - no)
        "conditions" : [ {
            "type" :  "exact" , 
            "url" :  "+79990123456" 
        }]
    }
}

headers={f'Authorization': 'OAuth' + your_token}
r = requests.post(url=f'https://api-metrika.yandex.net/management/v1/counter/{counter_id}/goals',
                  headers=headers,
                  json=f)

print(json.dumps(r.json(), indent=4))  
```

## Click on email {#email}

```python translate=no
import requests
import json

your_token = '<your_token>'
counter_id = <Tag ID>

f={"goal": 
    {
        "name" :  "API Click on email",
        "type" :  "email" ,
        "conditions" : [ {
            "type" :  "exact" , 
            "url" :  "mail@mail.ru" 
        }]
    }
}

headers={f'Authorization': 'OAuth' + your_token}
r = requests.post(url=f'https://api-metrika.yandex.net/management/v1/counter/{counter_id}/goals',
                  headers=headers,
                  json=f)

print(json.dumps(r.json(), indent=4))      
```

## Open messenger {#messenger}

```python translate=no
import requests
import json

your_token = '<your_token>'
counter_id = <Tag ID>

f={"goal": 
    {
        "name" :  "API Open messenger",
        "type" :  "messenger" ,
        "conditions" : [ {
            "type" :  "messenger", 
            "url" :  "whatsapp" #Opening WhatsApp
        }]
    }
}

headers={f'Authorization': 'OAuth' + your_token}
r = requests.post(url=f'https://api-metrika.yandex.net/management/v1/counter/{counter_id}/goals',
                  headers=headers,
                  json=f)

print(json.dumps(r.json(), indent=4))
```

## File downloads {#file}

```python translate=no
import requests
import json

your_token = '<your_token>'
counter_id = <Tag ID>

f={"goal": 
    {
        "name" :  "API File downloads",
        "type" :  "file" ,
        "conditions" : [ {
            "type" :  "file", 
            "url" :  "file.pdf" #Filename with or without an extension
        }]
    }
}

headers={f'Authorization': 'OAuth' + your_token}
r = requests.post(url=f'https://api-metrika.yandex.net/management/v1/counter/{counter_id}/goals',
                  headers=headers,
                  json=f)

print(json.dumps(r.json(), indent=4))    
```

## Site search {#search}

```python translate=no
import requests
import json

your_token = '<your_token>'
counter_id = <Tag ID>

f={"goal": 
    {
        "name" :  "API Site search",
        "type" :  "search" ,
        "conditions" : [ {
            "type" :  "search", 
            "url" :  "result" #Name of the GET parameter that accepts a search query on the site
        }]
    }
}

headers={f'Authorization': 'OAuth' + your_token}
r = requests.post(url=f'https://api-metrika.yandex.net/management/v1/counter/{counter_id}/goals',
                  headers=headers,
                  json=f)

print(json.dumps(r.json(), indent=4))   
```

## Click-through to social network {#social}

```python translate=no
import requests
import json

your_token = '<your_token>'
counter_id = <Tag ID>

f={"goal": 
    {
        "name" :  "API Click-through to social network",
        "type" :  "social" ,
        "conditions" : [ {
            "type" :  "social", 
            "url" :  "vkontakte" #Name of the social network
        }]
    }
}

headers={f'Authorization': 'OAuth' + your_token}
r = requests.post(url=f'https://api-metrika.yandex.net/management/v1/counter/{counter_id}/goals',
                  headers=headers,
                  json=f)

print(json.dumps(r.json(), indent=4))     
```

## Transition back from payment system {#payment_system}

```python translate=no
import requests
import json

your_token = '<your_token>'
counter_id = <Tag ID>

f={"goal": 
    {
        "name" :  "API Transition back from payment system",
        "type" :  "payment_system" 
    }
}

headers={f'Authorization': 'OAuth' + your_token}
r = requests.post(url=f'https://api-metrika.yandex.net/management/v1/counter/{counter_id}/goals',
                  headers=headers,
                  json=f)

print(json.dumps(r.json(), indent=4))
```

## Session duration {#visit_durration}

```python translate=no
import requests
import json

your_token = '<your_token>'
counter_id = <Tag ID>

f={"goal": 
    {
        "name" :  "API Session duration",
        "type" :  "visit_duration",
        "duration": 90 #Time in seconds
    }
}

headers={f'Authorization': 'OAuth' + your_token}
r = requests.post(url=f'https://api-metrika.yandex.net/management/v1/counter/{counter_id}/goals',
                  headers=headers,
                  json=f)

print(json.dumps(r.json(), indent=4))
```
