- JS-событие
- Составная цель
- Посещение страниц
- Количество просмотров
- Клик по номеру телефона
- Клик по email
- Переход в мессенджер
- Скачивание файлов
- Поиск по сайту
- Переход в соц. сети
- Возвращение из платёжной системы
- Продолжительность визита
import requests
import json
your_token = '<ВАШ ТОКЕН>'
counter_id = <Номер счётчика>
f={"goal":
{
"name" : "API JS-цель",
"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))
import requests
import json
your_token = '<ВАШ ТОКЕН>'
counter_id = <Номер счётчика>
f={"goal":
{
"name" : "API Составная цель",
"type" : "step" ,
"is_retargeting" : 0,
"steps" : [ {
"name" : "Первый шаг составной цели",
"type" : "url",
"conditions" : [ {
"type" : "contain_action", #идентификатор шага содержит
"url" : "stepgoalID"
}
]
},
{
"name" : "Второй шаг составной цели",
"type" : "url",
"conditions" : [ {
"type" : "regexp_action", #идентификатор шага соответствует регулярному выражению
"url" : "stepgoalID2"
}
]
},
{
"name" : "Третий шаг составной цели",
"type" : "url",
"conditions" : [ {
"type" : "action", #идентификатор шага совпадает
"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))
import requests
import json
your_token = '<ВАШ ТОКЕН>'
counter_id = <НОМЕР СЧËТЧИКА>
f={"goal":
{
"name" : "API Посещение страниц",
"type" : "url" ,
"conditions" : [ {
"type" : "contain" , #url содержит
"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))
import requests
import json
your_token = '<ВАШ ТОКЕН>'
counter_id = <НОМЕР СЧËТЧИКА>
f={"goal":
{
"name" : "API Количество просмотров",
"type" : "number" ,
"depth" : 3 #количество просмотренных страниц
}
}
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))
import requests
import json
your_token = '<ВАШ ТОКЕН>'
counter_id = <НОМЕР СЧËТЧИКА>
f={"goal":
{
"name" : "API Клик по номеру телефона",
"type" : "phone" ,
"hide_phone_number": 1, #применить опцию скрытия номера (1 - да, 0 - нет)
"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))
import requests
import json
your_token = '<ВАШ ТОКЕН>'
counter_id = <НОМЕР СЧËТЧИКА>
f={"goal":
{
"name" : "API Клик по 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))
import requests
import json
your_token = '<ВАШ ТОКЕН>'
counter_id = <НОМЕР СЧËТЧИКА>
f={"goal":
{
"name" : "API Переход в мессенджер",
"type" : "messenger" ,
"conditions" : [ {
"type" : "messenger",
"url" : "whatsapp" #переход в 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))
import requests
import json
your_token = '<ВАШ ТОКЕН>'
counter_id = <НОМЕР СЧËТЧИКА>
f={"goal":
{
"name" : "API Скачивание файлов",
"type" : "file" ,
"conditions" : [ {
"type" : "file",
"url" : "file.pdf" #имя файла с расширением или без
}]
}
}
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))
import requests
import json
your_token = '<ВАШ ТОКЕН>'
counter_id = <НОМЕР СЧËТЧИКА>
f={"goal":
{
"name" : "API Поиск по сайту",
"type" : "search" ,
"conditions" : [ {
"type" : "search",
"url" : "result" #название get-параметра, в который записывается текст поиска по сайту
}]
}
}
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))
import requests
import json
your_token = '<ВАШ ТОКЕН>'
counter_id = <НОМЕР СЧËТЧИКА>
f={"goal":
{
"name" : "API Переход в соц.сети",
"type" : "social" ,
"conditions" : [ {
"type" : "social",
"url" : "vkontakte" #название социальной сети
}]
}
}
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))
import requests
import json
your_token = '<ВАШ ТОКЕН>'
counter_id = <НОМЕР СЧËТЧИКА>
f={"goal":
{
"name" : "API Возвращение из платёжной системы",
"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))
import requests
import json
your_token = '<ВАШ ТОКЕН>'
counter_id = <НОМЕР СЧËТЧИКА>
f={"goal":
{
"name" : "API Продолжительность визита",
"type" : "visit_duration",
"duration": 90 # время в секундах
}
}
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))