Create counter

Attention.

Access tokens will not be accepted in URL parameters starting February 13, 2019. To continue working with the Yandex.Metrica API, set up authorization by passing the token in the HTTP header.

The outdated authorization method will be temporarily disabled on January 23, January 30, and February 6 for maintenance. Authorization using URL parameters will be unavailable on these dates.

Creates counter with specified parameters.

  1. Request syntax
  2. Request message body
  3. Response format

Request syntax

https://api-metrica.yandex.net/management/v1/counters
 ? [field=<string>]
Query parameters
fieldOne or several additional parameters of a returned object. The names of the additional parameters are specified in any order, separated by commas, without spaces. For example: field=goals,mirrors,grants,filters,operations.

Request message body


{
    "counter" : {
        "name" :  < string > ,
        "site2" : {
            "site" :  < string > 
        },
        "mirrors2" : [ {
            "site" :  < string > 
        }, ... ],
        "goals" : [  < goal > , ... ],
        "filters" : [ {
            "attr" :  < filter_attribute > ,
            "type" :  < filter_type > ,
            "value" :  < string > ,
            "action" :  < filter_action > ,
            "status" :  < filter_status > ,
            "with_subdomains" :  < boolean > 
        }, ... ],
        "operations" : [ {
            "action" :  < operation_type > ,
            "attr" :  < operation_attribute > ,
            "value" :  < string > ,
            "status" :  < operation_status > 
        }, ... ],
        "grants" : [ {
            "user_login" :  < string > ,
            "perm" :  < grant_type > ,
            "comment" :  < string > 
        }, ... ],
        "labels" : [ {
            "id" :  < int > ,
            "name" :  < string > 
        }, ... ],
        "webvisor" : {
            "urls" :  < string > ,
            "arch_enabled" :  < boolean > ,
            "arch_type" :  < webvisor_arch_type > ,
            "load_player_type" :  < webvisor_load_player_type > ,
            "wv_version" :  < integer >  
        },
        "code_options" : {
            "async" :  < boolean > ,
            "informer" : {
                "enabled" :  < boolean > ,
                "type" :  < informer_type > ,
                "size" :  < integer > ,
                "indicator" :  < informer_metric > ,
                "color_start" :  < string > ,
                "color_end" :  < string > ,
                "color_text" :  < integer > ,
                "color_arrow" :  < integer > 
            },
            "visor" :  < boolean > ,
            "ut" :  < boolean > ,
            "track_hash" :  < boolean > ,
            "xml_site" :  < boolean > ,
            "clickmap" :  < boolean > ,
            "in_one_line" :  < boolean > ,
            "ecommerce" :  < boolean > 
        },
        "create_time" :  < date > ,
        "time_zone_name" :  < string > ,
        "time_zone_offset" :  < int > ,
        "monitoring" : {
            "enable_monitoring" :  < int > ,
            "emails" : [  < string > , ... ],
            "enable_sms" :  < int > ,
            "sms_time" :  < string > ,
            "phones" : [  < string > , ... ]
        },
        "filter_robots" :  < integer > ,
        "visit_threshold" :  < integer > ,
        "offline_options" : {
            "offline_conversion_extended_threshold" :  < boolean > ,
            "offline_calls_extended_threshold" :  < boolean > ,
            "offline_visits_extended_threshold" :  < boolean > 
        }
    }
}
ParametersDescription
counterCounter.
counter
nameName of counter.
site2Full site domain.
mirrors2List of site mirrors (domains).
goalsList of structures with information on counter goals.
filtersList of structures with information on counter filters.
operationsList of structures with information about counter actions.
grantsList of structures with information on access rights to counter.
labelsList of structures with information about tags.
webvisorStructure with information about Session Replay settings.
code_optionsCounter code settings.
create_timeDate and time when counter was created.
time_zone_nameTime zone for calculation of statistics.
time_zone_offsetCurrent time zone offset from Greenwich, minutes
monitoring

Site availability monitoring settings.

filter_robotsRobot filtering.

Possible values:

  • 0 — factor in sessions of all robots;
  • 1 — only filter robots by strict rules (by default);
  • 2 — filter robots by strict rules and by behavior
visit_thresholdSession timeout in seconds.

Default value: "1800"

offline_optionsOffline event settings.
site2
siteFull site domain.
mirrors2
siteFull site domain.
filters
attrType of data, to which a filter is applied.

Possible values:

  • referer — referrer;
  • uniq_id — special filter attribute “don't factor in my sessions”.
  • client_ip — IP-address;
  • title — page title;
  • url — page URL;
typeFilter type or action for filter.

Possible values:

  • equal — equals;
  • contain — contains;
  • me — my visits, used only with the type of data attr = uniq_id;
  • start — begins with;
  • interval — in the interval, is used only with data type “IP-address” (attr = client_ip);
  • only_mirrors — only site and mirrors, used only for data type “page URL” (attr = url) and filter type “only record traffic” (action = include), as well as when mirrors are specified for the counter.
valueFilter value.
actionFilter type.

Possible values:

  • include — keep traffic only.
  • exclude — exclude traffic;
statusFilter status.

Possible values:

  • active — filter is used;
  • disabled — filter disabled (without deletion).
with_subdomainsFilter by subdomains.
operations
actionAction type.

Possible values:

  • cut_parameter — remove specific parameter from URL;
  • replace_domain — replace domain.
  • to_lower — convert to lower case;
  • merge_https_and_http — replace https:// with http://;
  • cut_fragment — remove anchor from URL;
  • cut_all_parameters — cut all parameters from URL;
attrField for filtration.

Possible values:

  • referer — referrer;
  • url — page URL.
valueValue for replacement.
statusAction status.

Possible values:

  • active — action is used;
  • disabled — action disabled (without deletion).
grants
user_login

Login of user, which has been granted permission to manage counter.

Parameter contains empty string, if public access is provided to the statistics of the counter (perm = public_stat)

permAccess level.

Possible values:

  • view — page views only;
  • edit — full access.
  • public_stat — public access to statistics;
comment

Any comment. 255 characters maximum.

labels
idTag ID.
nameTag name.
webvisor
urlsList of pages for saving.
arch_enabledSaving pages of site.

Possible values:

  • 0 ― disabled (by default);
  • 1 ― enabled.
arch_typeRecord of page content.

Possible values:

  • load — download from site;
  • html — from browser.
  • none — disabled;
load_player_typeLoading pages in the player.

Possible values:

  • proxy — as an anonymous user;
  • on_your_behalf — as you.
wv_versionSession Replay version.
code_options
asyncAsynchronous code of counter.

Possible values:

  • 0 ― disabled;
  • 1 ― enabled (by default).
informerInformer settings.
visorRecording and analysis of site user behavior.

Possible values:

  • 0 ― disabled (by default);
  • 1 ― enabled.
utStop automatic page indexing.

Possible values:

  • 0 ― disabled (by default);
  • 1 ― enabled.
track_hashHash tracking in browser address bar. Option applies to AJAX sites.

Possible values:

  • 0 ― disabled (by default);
  • 1 ― enabled.
xml_siteFor XML-sites. The noscript element should not be used in XML documents.

Possible values:

  • 0 ― disabled (by default);
  • 1 ― enabled.
clickmapGathering statistics for the click map report.

Possible values:

  • 0 ― disabled;
  • 1 ― enabled (by default).
in_one_lineRemove counter code in one string.

Possible values:

  • 0 ― disabled (by default);
  • 1 ― enabled.
ecommerce

Possible values:

  • 0 ― disabled (by default);
  • 1 ― enabled.
informer
enabledPermission for display of informer.

Possible values:

  • 0 ― informer is not displayed (by default);
  • 1 ― informer is displayed.
typeInformer type.

Possible values:

  • ext — advanced (by default).
  • simple — simple;
sizeSize of informer.

Possible values:

  • 1 - size 80х15;
  • 2 - size 80х31;
  • 3 - size 88х31 (by default). Does not affect the value of the indicator field in view of informer of this type.
indicatorParameter which will be displayed on the informer.

Possible values:

  • visits — Sessions;
  • pageviews — pageviews (by default);
  • uniques — users.
color_startBeginning (top) color of informer in the format RRGGBBAA. RR, GG, BB are saturated red, green and blue colors. The level of saturation for every color is assigned a value ranging from 00 to FF. AA is transparency from 00 (transparent) to FF (opaque).

Default value: "FFFFFFFF."

color_endEnding (lower) color of informer in the format RRGGBBAA. The parameter is intended for creating background gradient. Color saturation and transparency are analogously given the parameter color_start.

Default value: "EFEFEFFF"

color_textText color on informer.

Possible values:

  • 0 ― black (by default);
  • 1 ― white.
color_arrowArrow color on informer.

Possible values:

  • 0 ― black;
  • 1 ― violet (by default).
monitoring
enable_monitoring

Notifications for monitoring site availability. Possible values:

  • 0 — user is not subscribed to notifications (by default);
  • 1 — monitoring notifications enabled.
emails

List of email addresses for getting site monitoring notifications. Can contain one or several addresses, separated by commas

enable_sms

SMS-notifications for monitoring site availability. Possible values:

  • 0 — user is not subscribed to SMS-notifications (by default);
  • 1 — subscribed to SMS monitoring notifications.
sms_time

Permitted time ranges for sending SMS-notifications. The ranges are specified by days of the week from Monday to Sunday. If the range is not specified for a particular day, SMS-notifications will not be sent on that day.

Days of the week are separated by semicolons, as shown in the following example:

8-9;8-9;;20-22;;;

This value permits the sending of SMS from 8:00 to 9:59 on Monday and Tuesday and from 20:00 to 22:59 on Thursday.

Each specified hour corresponds to an interval of time from the beginning until the end of that hour. So, the number 9 indicates the interval beween 9 hours 00 minutes and 9 hours 59 minutes inclusive.

Ranges can consist of "to-from" intervals and individual hours, for example 7-12,16,18,22-23. The components of such ranges are separated by commas.

phones

List of telephone numbers for getting site monitoring notifications. Can contain one or several numbers, separated by commas

offline_options
offline_conversion_extended_thresholdExtended period for tracking offline conversions.

Possible values:

  • 0 ― disabled (by default);
  • 1 ― enabled.
offline_calls_extended_thresholdExtended call tracking period.

Possible values:

  • 0 ― disabled (by default);
  • 1 ― enabled.
offline_visits_extended_thresholdExtended tracking period for offline visits.

Possible values:

  • 0 ― disabled (by default);
  • 1 ― enabled.

Request example

POST https://api-metrica.yandex.net/management/v1/counters?

Response format


{
    "counter" : {
        "id" :  < int > ,
        "status" :  < counter_status > ,
        "owner_login" :  < string > ,
        "code_status" :  < code_status > ,
        "code_status_info" : {
            "length" :  < integer > ,
            "found" :  < integer > ,
            "match" :  < integer > ,
            "http_code" :  < integer > ,
            "http_msg" :  < string > ,
            "duration" :  < double > ,
            "infected" :  < string > 
        },
        "name" :  < string > ,
        "site2" : {
            "site" :  < string > 
        },
        "type" :  < counter_type > ,
        "favorite" :  < boolean > ,
        "permission" :  < counter_permission > ,
        "mirrors2" : [ {
            "site" :  < string > 
        }, ... ],
        "goals" : [  < goal > , ... ],
        "filters" : [ {
            "id" :  < int > ,
            "attr" :  < filter_attribute > ,
            "type" :  < filter_type > ,
            "value" :  < string > ,
            "action" :  < filter_action > ,
            "status" :  < filter_status > ,
            "start_ip" :  < string > ,
            "end_ip" :  < string > ,
            "with_subdomains" :  < boolean > 
        }, ... ],
        "operations" : [ {
            "id" :  < int > ,
            "action" :  < operation_type > ,
            "attr" :  < operation_attribute > ,
            "value" :  < string > ,
            "status" :  < operation_status > 
        }, ... ],
        "grants" : [ {
            "user_login" :  < string > ,
            "perm" :  < grant_type > ,
            "created_at" :  < date > ,
            "comment" :  < string > 
        }, ... ],
        "labels" : [ {
            "id" :  < int > ,
            "name" :  < string > 
        }, ... ],
        "webvisor" : {
            "urls" :  < string > ,
            "arch_enabled" :  < boolean > ,
            "arch_type" :  < webvisor_arch_type > ,
            "load_player_type" :  < webvisor_load_player_type > ,
            "wv_version" :  < integer >
        },
        "code_options" : {
            "async" :  < boolean > ,
            "informer" : {
                "enabled" :  < boolean > ,
                "type" :  < informer_type > ,
                "size" :  < integer > ,
                "indicator" :  < informer_metric > ,
                "color_start" :  < string > ,
                "color_end" :  < string > ,
                "color_text" :  < integer > ,
                "color_arrow" :  < integer > 
            },
            "visor" :  < boolean > ,
            "ut" :  < boolean > ,
            "track_hash" :  < boolean > ,
            "xml_site" :  < boolean > ,
            "clickmap" :  < boolean > ,
            "in_one_line" :  < boolean > ,
            "ecommerce" :  < boolean > 
        },
        "create_time" :  < date > ,
        "time_zone_name" :  < string > ,
        "time_zone_offset" :  < int > ,
        "update_time" :  < string > ,
        "code" :  < string > ,
        "monitoring" : {
            "enable_monitoring" :  < int > ,
            "emails" : [  < string > , ... ],
            "sms_allowed" :  < int > ,
            "enable_sms" :  < int > ,
            "sms_time" :  < string > ,
            "phones" : [  < string > , ... ]
        },
        "filter_robots" :  < integer > ,
        "visit_threshold" :  < integer > ,
        "offline_options" : {
            "offline_conversion_extended_threshold" :  < boolean > ,
            "offline_calls_extended_threshold" :  < boolean > ,
            "offline_visits_extended_threshold" :  < boolean > 
        }
    }
}
ParametersDescription
counterCounter.
counter
idCounter ID.
statusCounter status.

Possible values:

  • Active — Counter active
  • Deleted — Counter deleted
owner_loginUsername of counter owner.
code_statusInstallation status of counter code.

Possible values:

  • CS_ERR_INFECTED — unable to verify (the site on which the counter is installed, or one of its mirrors, is in the list of infected sites).
  • CS_NOT_FOUND — Not installed.
  • CS_ERR_OTHER_HTML_CODE — another counter installed.
  • CS_ERR_CONNECT — unable to verify (connection error).
  • CS_ERR_TIMEOUT — unable to verify (timeout).
  • CS_OK — Correctly installed.
code_status_infoInformation on counter status.
nameName of counter.
site2Full site domain.
typeCounter type.

Possible values:

  • partner — counter imported from YAN.
  • simple — counter created by user in Yandex.Metrica;
favoriteIs counter added to favorites.

Possible values:

  • 0 ― not added (by default);
  • 1 ― added.
permissionAccess level to counter.

Possible values:

  • view — guest counter with access level “page views only”;
  • edit — guest counter with access level “full access”.
  • own — counter, owned by a user;
mirrors2List of site mirrors (domains).
goalsList of structures with information on counter goals.
filtersList of structures with information on counter filters.
operationsList of structures with information about counter actions.
grantsList of structures with information on access rights to counter.
labelsList of structures with information about tags.
webvisorStructure with information about Session Replay settings.
code_optionsCounter code settings.
create_timeDate and time when counter was created.
time_zone_nameTime zone for calculation of statistics.
time_zone_offsetCurrent time zone offset from Greenwich, minutes
update_timeTime counter was last changed.
code

HTML-code of counter

monitoring

Site availability monitoring settings.

filter_robotsRobot filtering.

Possible values:

  • 0 — factor in sessions of all robots;
  • 1 — only filter robots by strict rules (by default);
  • 2 — filter robots by strict rules and by behavior
visit_thresholdSession timeout in seconds.
offline_optionsOffline event settings.
code_status_info
lengthContent length in bytes.
foundNumber of valid Yandex.Metrica codes found.
matchNumber of valid codes for verified counter found.
http_codeHTTP response status code (“200” on success).
http_msgString displaying the HTTP status response code (“OK” on success).
durationSite response time in seconds.
infectedInfected site (site on which a counter is installed, or is one of its mirrors).
site2
siteFull site domain.
mirrors2
siteFull site domain.
filters
id

Filter ID. Specify this parameter when changing a counter filter

attrType of data, to which a filter is applied.

Possible values:

  • referer — referrer;
  • uniq_id — special filter attribute “don't factor in my sessions”.
  • client_ip — IP-address;
  • title — page title;
  • url — page URL;
typeFilter type or action for filter.

Possible values:

  • equal — equals;
  • contain — contains;
  • me — my visits, used only with the type of data attr = uniq_id;
  • start — begins with;
  • interval — in the interval, is used only with data type “IP-address” (attr = client_ip);
  • only_mirrors — only site and mirrors, used only for data type “page URL” (attr = url) and filter type “only record traffic” (action = include), as well as when mirrors are specified for the counter.
valueFilter value.
actionFilter type.

Possible values:

  • include — keep traffic only.
  • exclude — exclude traffic;
statusFilter status.

Possible values:

  • active — filter is used;
  • disabled — filter disabled (without deletion).
start_ipFirst IP-address range.
end_ipLast IP-address of range.
with_subdomainsFilter by subdomains.
operations
id

Action ID (needs to be specified while changing a counter action).

actionAction type.

Possible values:

  • cut_parameter — remove specific parameter from URL;
  • replace_domain — replace domain.
  • to_lower — convert to lower case;
  • merge_https_and_http — replace https:// with http://;
  • cut_fragment — remove anchor from URL;
  • cut_all_parameters — cut all parameters from URL;
attrField for filtration.

Possible values:

  • referer — referrer;
  • url — page URL.
valueValue for replacement.
statusAction status.

Possible values:

  • active — action is used;
  • disabled — action disabled (without deletion).
grants
user_login

Login of user, which has been granted permission to manage counter.

Parameter contains empty string, if public access is provided to the statistics of the counter (perm = public_stat)

permAccess level.

Possible values:

  • view — page views only;
  • edit — full access.
  • public_stat — public access to statistics;
created_at

Date of granting access in the format YYYY-MM-DD'T'hh:mm:ssZ.

comment

Any comment. 255 characters maximum.

labels
idTag ID.
nameTag name.
webvisor
urlsList of pages for saving.
arch_enabledSaving pages of site.

Possible values:

  • 0 ― disabled (by default);
  • 1 ― enabled.
arch_typeRecord of page content.

Possible values:

  • load — download from site;
  • html — from browser.
  • none — disabled;
load_player_typeLoading pages in the player.

Possible values:

  • proxy — as an anonymous user;
  • on_your_behalf — as you.
wv_versionSession Replay version.
code_options
asyncAsynchronous code of counter.

Possible values:

  • 0 ― disabled;
  • 1 ― enabled (by default).
informerInformer settings.
visorRecording and analysis of site user behavior.

Possible values:

  • 0 ― disabled (by default);
  • 1 ― enabled.
utStop automatic page indexing.

Possible values:

  • 0 ― disabled (by default);
  • 1 ― enabled.
track_hashHash tracking in browser address bar. Option applies to AJAX sites.

Possible values:

  • 0 ― disabled (by default);
  • 1 ― enabled.
xml_siteFor XML-sites. The noscript element should not be used in XML documents.

Possible values:

  • 0 ― disabled (by default);
  • 1 ― enabled.
clickmapGathering statistics for the click map report.

Possible values:

  • 0 ― disabled;
  • 1 ― enabled (by default).
in_one_lineRemove counter code in one string.

Possible values:

  • 0 ― disabled (by default);
  • 1 ― enabled.
ecommerce

Possible values:

  • 0 ― disabled (by default);
  • 1 ― enabled.
informer
enabledPermission for display of informer.

Possible values:

  • 0 ― informer is not displayed (by default);
  • 1 ― informer is displayed.
typeInformer type.

Possible values:

  • ext — advanced (by default).
  • simple — simple;
sizeSize of informer.

Possible values:

  • 1 - size 80х15;
  • 2 - size 80х31;
  • 3 - size 88х31 (by default). Does not affect the value of the indicator field in view of informer of this type.
indicatorParameter which will be displayed on the informer.

Possible values:

  • visits — Sessions;
  • pageviews — pageviews (by default);
  • uniques — users.
color_startBeginning (top) color of informer in the format RRGGBBAA. RR, GG, BB are saturated red, green and blue colors. The level of saturation for every color is assigned a value ranging from 00 to FF. AA is transparency from 00 (transparent) to FF (opaque).
color_endEnding (lower) color of informer in the format RRGGBBAA. The parameter is intended for creating background gradient. Color saturation and transparency are analogously given the parameter color_start.
color_textText color on informer.

Possible values:

  • 0 ― black (by default);
  • 1 ― white.
color_arrowArrow color on informer.

Possible values:

  • 0 ― black;
  • 1 ― violet (by default).
monitoring
enable_monitoring

Notifications for monitoring site availability. Possible values:

  • 0 — user is not subscribed to notifications (by default);
  • 1 — monitoring notifications enabled.
emails

List of email addresses for getting site monitoring notifications. Can contain one or several addresses, separated by commas

sms_allowed

SMS-notifications. To receive notifications you need to subscibe and confirm your subscription. Phone number is stored in the user's personal data for all Yandex services.

Possible values:

  • 0 — user did not enter mobile phone number;
  • 1 — user entered mobile phone number and confirmed subscription.
enable_sms

SMS-notifications for monitoring site availability. Possible values:

  • 0 — user is not subscribed to SMS-notifications (by default);
  • 1 — subscribed to SMS monitoring notifications.
sms_time

Permitted time ranges for sending SMS-notifications. The ranges are specified by days of the week from Monday to Sunday. If the range is not specified for a particular day, SMS-notifications will not be sent on that day.

Days of the week are separated by semicolons, as shown in the following example:

8-9;8-9;;20-22;;;

This value permits the sending of SMS from 8:00 to 9:59 on Monday and Tuesday and from 20:00 to 22:59 on Thursday.

Each specified hour corresponds to an interval of time from the beginning until the end of that hour. So, the number 9 indicates the interval beween 9 hours 00 minutes and 9 hours 59 minutes inclusive.

Ranges can consist of "to-from" intervals and individual hours, for example 7-12,16,18,22-23. The components of such ranges are separated by commas.

phones

List of telephone numbers for getting site monitoring notifications. Can contain one or several numbers, separated by commas

offline_options
offline_conversion_extended_thresholdExtended period for tracking offline conversions.

Possible values:

  • 0 ― disabled (by default);
  • 1 ― enabled.
offline_calls_extended_thresholdExtended call tracking period.

Possible values:

  • 0 ― disabled (by default);
  • 1 ― enabled.
offline_visits_extended_thresholdExtended tracking period for offline visits.

Possible values:

  • 0 ― disabled (by default);
  • 1 ― enabled.