Content publishers are busy building chatbots — yet another medium for the users to consume content using Facebook Messenger.

Most publishers already track total number of page views on their Instant Articles using Google Analytics. This is how to track IA page views on GA:

<figure class="op-tracker"> 
    <iframe hidden>
        <script>
 (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); ga('create', 'YOUR_GA_ID', 'auto'); ga('send', 'pageview');
        </script>
    </iframe>
</figure>

FB documentation — https://developers.facebook.com/docs/instant-articles/analytics

Note that this doesn’t differentiate between page views coming from various sources.

Quite similar to how we track traffic from different sources for non-IA pages, we can also use query parameters for IA pages.

URL opened by a user is accessible inside IA tracking script under the variable ia_document.shareURL

So all you need to do is add a source query param to the URL sent by your chatbot:

Example URL: https://www.nytimes.com/2017/06/29/business/media/trump-mika-brzezinski-facelift.html?source=chatbot

<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

ga('create', 'YOUR GA ID', 'auto');
ga('require', 'displayfeatures');

var qParams= new URL(ia_document.shareURL).searchParams;
var source = qParams['utm_source'];
var medium = qParams['utm_medium'] ;
var campaign = qParams['utm_campaign'];

ga('set', 'campaignSource', source);
ga('set', 'campaignMedium', medium);
ga('set', 'campaignName', campaign);
ga('set', 'title', 'FBIA: '+ia_document.title);
ga('set', 'referrer', 'ia_document.referrer');
ga('send', 'pageview');
</script>