Profile views registration

Profile views registration is required when you use API 2GIS. You can do it by including a JS tracker.

JS Tracker

To work with the tracker you will need a JavaScript object DG.apitracker. It becomes available after the following code has been loaded:

    <script src="https://catalog.api.2gis.com/assets/apitracker.js"></script>

Please don’t forget that this file should be included in each page that uses 2GIS API.

Profile viewing

The registration of the profile views is carried out by calling the DG.apitracker.regBC( [reg_bc_url] ) method, where [reg_bc_url] is a set of additional data for an event registration, collected in a company branch profile in the reg_bc_url field. The ways to call the DG.apitracker.regBC() tracker:

  • placing the calling code before the tag;
  • placing the calling code in the event handler of the onLoad tag;
  • placing the calling code in any arbitrary code, ensuring the calling of event registration after loading the profile of the company branch.

An example of calling an event registration when loading the page:

    <body onload="DG.apitracker.regBC('http://stat.api.2gis.ru/?v=2.0&hash=a6ffd3544cc0dfe277c3');">

Additional events

In addition to the profile views registration it is recommended to register additional events. To register the events you need to visually hide a part of the data and display it on user request. For example, to display only a part of a phone number and replace the hidden part with the “Show phone” button. When a user clicks this button an event is registered. The registration is carried out by calling the DG.apitracker.regBCEvent( [reg_bc_url], [event_type] ) method, where [reg_bc_url] is the same data that was used when registering profile views and [event_type] is an event that was made by the user. It can be one from the following list:

    the
  • show_address — company addresses; the event is registered when the company addresses block is displayed;
  • show_contact_email — the event is registered when a contact with the email type is displayed;
  • show_contact_phone — a phone number; event is registered when a contact with the phone type is displayed;
  • show_contact_skype — the event is registered when a contact with the skype type is displayed;
  • the
  • show_contact_social_profile — a social network contact; the event is registered when a contact with vkontakte, twitter, instagram, facebook, odnoklassniki, googleplus, linkedin, youtube, or pinterest types is displayed.

An example of calling an event registration when clicking the “Show phone number” button:

<head>
    <script type="text/javascript">
        function showHiddenData() {} // - your function that displays hidden data
    </script>
</head>
<body onload="DG.apitracker.regBC(...);">
<div>
    Phone number: +7 123 45
    <input type="button" onclick="
        showHiddenData();
        DG.apitracker.regBCEvent('http://stat.api.2gis.ru/?v=2.0&hash=a6ffd3544cc0dfe277c3','show_contact_phone');"
        value="Show phone number"/>
</div>
</body>
</xmp>