On Habré there are already several articles about the bot telegram. But how to monitor the use of the bot? Under the cat we collect data to assess the most used bot functions, campaign effectiveness and failure rates.
First a small note. I am neither an analyst nor a seo specialist. Perhaps some tasks can be solved more efficiently, but there is very little information about this. It so happened that our colleagues overseas flatly refused to work with the Yandex
botan product and demanded a familiar interface “like in google analytics”. It was decided to use
google analytics measurement protocol . With it, you can transfer almost all the same data to google analytics as you normally would (for example, a script on the site).
If your bot is written in laravel, we can advise the
irazasyed / laravel-gamp package for running the measurement protocol.
')
How to use the bot?
In our bot, we have marked the main user interaction with the bot on the dialogues and steps. For example, the settings dialog looks like this:
In fact, this is one step of the dialogue with buttons and 6 separate steps for setting specific parameters. This structure can be represented as addresses:
- / settings
- / settings / gender
- / settings / frequency
- / settings / language
- ...
We consider a set of current user buttons as its state or as the page on which it is located. Accordingly, we can send a page view to analytics.
use Irazasyed\LaravelGAMP\Facades\GAMP; ... $gamp = GAMP::setClientId( '123456' ); $gamp->setDocumentPath( '/settings' ); $gamp->sendPageview(); ...
Where do new users come from?
If the analogy of the pages of the site with the state of the user (his current keyboard) is quite obvious, then how to draw an analogy with the source of traffic? In fact, we can’t find out exactly how the user found our bot. But there is one trick. We already had a tool to transfer the utm_campaign analog to Google Analytics.
Telegram allows you to start a dialogue with a user not from scratch. When the user presses the “start” button in the telegram application, the bot receives the message “
/ start ”. This message can be extended with
an additional parameter . Each bot has a link that opens a chat with it in a telegram -
telegram.me <bot_name> . To this link you can add the parameter “start” (or “startgroup”), for example:
https://telegram.me/bot_name?start=habr-gamp
In this case, we can transmit to the analyst the source “habr” and even clarify it with the channel “gamp”.
if($campaign){ if(strpos($campaign,'-')){ list($campaign,$medium) = explode('-',$campaign); $gamp->setCampaignMedium($medium); } else{ $gamp->setCampaignMedium('none'); } $gamp->setCampaignSource($campaign); }
From this moment we can follow the success of advertising campaigns:
What to do if the user has blocked the bot?
The next time you send a message, you may encounter an unpleasant situation - the user has blocked the bot. How to reflect this in analytics? In fact, we cannot give analytek a page view of “
/ unsubscribe ” or similar, because The user is now in a different state (on another "page"). But gamp supports and events. Accordingly, we send him an event about blocking the user.
use Irazasyed\LaravelGAMP\Facades\GAMP; ... $gamp = GAMP::setClientId( '123456' ); $gamp->setEventCategory('User') ->setEventAction('Unsubscribe') ->setEventLabel('Blocked') ->sendEvent(); ...
Bot geography
Since all messages come from the same server, its geographical affiliation is almost irrelevant. We are interested in the distribution of the bot audience. Basically, we can find out about a user's location in two ways: by the sent geolocation or by his ip.

The attentive reader may have noticed that for some reason Greenland has almost as many sessions as Russia. The fact is that this is a little trick. Not all users follow the links or send their location. Since it is important for us to understand not only the geographical location, but also how many users did not provide it to us, we decided to everyone who did not have time to tell us about their location in a large but sparsely populated Greenland.