Skip to content
Login Contact

Facebook Instant Articles Marfeel tracking setup

Compass tracks visits and user behavior on Facebook Instant Articles (FBIA). Two implementation methods are available: the standard embed iframe approach and a custom URL tracker iframe for publishers who manage their own tracking setup. Both methods rely on the Marfeel JavaScript SDK loaded with a FBIA-specific configuration.

Insert the following JavaScript snippet anywhere in your FBIA page body to enable Compass tracking. Replace the value before /* AccountId */ with your unique account ID:

<figure class="op-tracker">
<iframe>
<script type="text/javascript">
function e(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],c=document.createElement("script");c.src=e,t?c.type="module":(c.async=!0,c.type="text/javascript",c.setAttribute("nomodule",""));var n=document.getElementsByTagName("script")[0];n.parentNode.insertBefore(c,n)}function t(t,c,n){var a,o,r;null!==(a=t.marfeel)&&void 0!==a||(t.marfeel={}),null!==(o=(r=t.marfeel).cmd)&&void 0!==o||(r.cmd=[]),t.marfeel.config=n,t.marfeel.config.accountId=c;var i="https://sdk.mrf.io/statics";e("".concat(i,"/marfeel-sdk.js?id=").concat(c),!0),e("".concat(i,"/marfeel-sdk.es5.js?id=").concat(c),!1)}!function(e,c){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};t(e,c,n)}(window,0 /* AccountId */,{pageType:"fbia"} /* Config */);
</script>
</iframe>
</figure>
Click to view the unminified version of this snippet:
<figure class="op-tracker">
<iframe>
<script type="text/javascript">
function injectScript(src) {
var isModule = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
var script = document.createElement('script');
script.src = src;
if (isModule) {
script.type = 'module';
} else {
script.async = true;
script.type = 'text/javascript';
script.setAttribute('nomodule', '');
}
var firstScript = document.getElementsByTagName('script')[0];
firstScript.parentNode.insertBefore(script, firstScript);
}
function load(window, id, userConfig) {
var _a, _b;
var _c;
(_a = window.marfeel) !== null && _a !== void 0 ? _a : window.marfeel = {};
(_b = (_c = window.marfeel).cmd) !== null && _b !== void 0 ? _b : _c.cmd = [];
window.marfeel.config = userConfig;
window.marfeel.config.accountId = id;
var resourcesPath = 'https://sdk.mrf.io/statics';
injectScript("".concat(resourcesPath, "/marfeel-sdk.js?id=").concat(id), true);
injectScript("".concat(resourcesPath, "/marfeel-sdk.es5.js?id=").concat(id), false);
}
(function (window, accountId) {
var clientConfig = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
load(window, accountId, clientConfig);
})(window, /* AccountId */, {pageType: 'fbia'} /* Config */);
</script>
</iframe>
</figure>

If you use a custom iframe-based tracker for your FBIA pages, you need both the Marfeel SDK snippet shown above and an additional script that provides context variables the Compass runtime requires. This approach is common for publishers who already have a proprietary tracking URL, similar to instrumentation for other distributed platforms like SmartNews.

For example, given a custom tracker like:

<figure class="op-tracker">
<iframe src="http://my-url-tracker.com/">
</figure>

Add the following scripts. The first sets the context variables and the second loads the Compass SDK:

<script type="text/javascript">
window.ia_document = {
shareURL: URL,
referrer: REFERRER_URL
}
</script>
<script type="text/javascript">
function e(e){var t=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],c=document.createElement("script");c.src=e,t?c.type="module":(c.async=!0,c.type="text/javascript",c.setAttribute("nomodule",""));var n=document.getElementsByTagName("script")[0];n.parentNode.insertBefore(c,n)}function t(t,c,n){var a,o,r;null!==(a=t.marfeel)&&void 0!==a||(t.marfeel={}),null!==(o=(r=t.marfeel).cmd)&&void 0!==o||(r.cmd=[]),t.marfeel.config=n,t.marfeel.config.accountId=c;var i="https://sdk.mrf.io/statics";e("".concat(i,"/marfeel-sdk.js?id=").concat(c),!0),e("".concat(i,"/marfeel-sdk.es5.js?id=").concat(c),!1)}!function(e,c){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};t(e,c,n)}(window, /* AccountId */,{pageType:"fbia"} /* Config */);
</script>
  • URL: The URL of the article being viewed. Facebook Instant Articles passes this as the ia_share_url query parameter on the iframe.
  • REFERRER_URL: The referrer URL of the article.
How do I enable Compass tracking on Facebook Instant Articles?

Insert the Marfeel JavaScript snippet inside a <figure class="op-tracker"><iframe> block anywhere in your FBIA page body, replacing the AccountId placeholder with your unique account ID.

What is the URL tracker iframe implementation for FBIA?

If you use a custom URL tracker iframe, add both the Marfeel SDK snippet and a window.ia_document object containing the article shareURL and referrer URL so the Compass runtime has the required context variables.