Facebook Instant Articles

The JavaScript SDK can be used to track activity in Facebook Instant Articles. To initialize the JavaScript SDK in your Instant Articles, you need to embed the snippet inside an <iframe> tag, somewhere in the <body> of the article.

You must explicitly set useNativeSdk to false for the SDK to work inside a Facebook mobile webview.

<figure class="op-tracker">
      <script type="text/javascript">
        (function(apiKey) {
          console.log("function called")
          window.mParticle = window.mParticle || {};
          window.mParticle.config = window.mParticle.config || {
            useNativeSdk: false,
          window.mParticle.config.rq = [];
          window.mParticle.ready = function(f) {
          window.mParticle.ready(function() {
            var details = {
              "title": "Dewey Defeats Truman",
              "slug": "1948-11-03-dewey-defeats-truman",
              "platform": "Facebook Instant Articles"
            details['referrer_source'] = document.referrer;
            mParticle.logEvent('Content Viewed', mParticle.EventType.Navigation, details);
          var mp = document.createElement('script');
          mp.type = 'text/javascript';
          mp.async = true;
          mp.src = ('https:' == document.location.protocol ? 'https://jssdkcdns' : 'http://jssdkcdn') + '.mparticle.com/js/v2/' + apiKey + '/mparticle.js';
          var s = document.getElementsByTagName('script')[0];
          s.parentNode.insertBefore(mp, s);

Facebook will set the document origin to be the same as the resolved URL used to post or share the Instant Article or, if that URL returns a redirect response, to the last URL in the redirect chain.

Facebook also exposes an ia_document JavaScript object which can be used to populate tracking data.

See Facebook’s Instant Article documentation for more information.