# Chartbeat Tracking for SmartNews

## Intro to SmartNews

SmartNews is a news aggregation app that allows its publisher partners multiple display formats for their articles within the app. Publishers participating in SmartNews' **SmartView First** native format program have the option to include external analytics code (Chartbeat, Google Analytics, etc) in their [SmartFormat v2.0+ feeds](https://publishers.smartnews.com/hc/en-us/categories/360001838493-SmartFormat-Specification). If your organization uses this SmartView First native display format for your articles in SmartNews, Chartbeat will only track engagement on those pages if our code is added to your SmartFormat feed following the instructions below.

If your organization uses SmartNews' standard web view format, Chartbeat code cannot be added directly to your [SmartFormat v1.1.4 feed](https://publishers.smartnews.com/hc/en-us/articles/360022906393) as outlined below — this integration is only supported for SmartFormat feeds version 2.0 and above. Instead, readers of your content in the SmartNews app will open a web view version of your page which should already include our standard website tracking or AMP code for your mobile-web pages, and Chartbeat tracking for your SmartNews audience should occur automatically as SmartNews referred in your website's primary Real-time Dashboard under the 'Links' traffic source category.

## Setting up a SmartNews Chartbeat Beta Dashboard

We currently require that your SmartView First traffic data belong to a separate Chartbeat Site (dashboard) from your website's primary Real-Time Dashboard. We do not support engaged time tracking for this integration yet, so we insist that all SmartView engagement data appear in SmartNews-only Chartbeat dashboards to prevent deflating average engaged time numbers in your website's primary Chartbeat Site.

Your Chartbeat Customer Success representative or Implementation Engineer can assist with creating a new Site on your Chartbeat account using the following format: **yourdomainname.smartnews.** For example, if my website is bigcitypaper.com, my Chartbeat SmartNews Site should be called **bigcitypaper.smartnews**.

## Add our tracking code to your SmartFormat feed

To start tracking SmartView First traffic, you will need to add Chartbeat tracking code to the SmartFormat feed. This can be done by inserting our code snippet to a [`<snf:analytics>`](https://publishers.smartnews.com/hc/en-us/articles/360036526213-SmartFormat-Specification-Version-2-1-#lt-snf-analytics-gt) tag as seen below:

```markup
<snf:analytics>
    <script type='text/javascript'>
        (function() {
            /** CONFIGURATION START **/
            var _sf_async_config = window._sf_async_config = (window._sf_async_config || {});
            _sf_async_config.uid = #####; //CHANGE THIS
            _sf_async_config.domain = 'yourdomain.smartnews'; //CHANGE THIS
            _sf_async_config.path = ''; //SET PAGE CANONICAL URL
            _sf_async_config.title = ''; //SET PAGE TITLE
            _sf_async_config.sections = ''; //CHANGE THIS TO YOUR SECTION NAME(s)
            _sf_async_config.authors = ''; //CHANGE THIS TO YOUR AUTHOR NAME(s)
            /** CONFIGURATION END **/
            function loadChartbeat() {
                var e = document.createElement('script');
                var n = document.getElementsByTagName('script')[0];
                e.type = 'text/javascript';
                e.async = true;
                e.src = '//static.chartbeat.com/js/chartbeat.js';
                n.parentNode.insertBefore(e, n);
            }
            loadChartbeat();
         })();
    </script>
</snf:analytics>
```

The `uid`  configuration variable in the above snippet should be assigned to your Chartbeat account id. The `domain` configuration variable should be assigned to your SmartNews-Chartbeat Site id, in the format of **yourdomainname.smartnews**.

Section, author, and title variables should be populated by your SmartFormat feed generator with page metadata that matches precisely the page metadata sent from your standard website. Similarly, if the Chartbeat code on your website utilizes our `useCanonical` and `useCanonicalDomain` settings for our tracker to collect the canonical URL from your page HTML, your SmartNews Chartbeat code should send the same canonical URL via the `path` configuration variable. For example, if an article's canonical URL is `https://mysite.com/news/article-xyz.html`, the path variable should be populated as follows in that page's SmartFormat RSS:

```javascript
_sf_async_config.path = 'mysite.com/news/article-xyz.html';
```

{% hint style="warning" %}
**Important:** If adding multiple analytics scripts to the SmartFormat feed, ensure these scripts are all enclosed in a single`<snf:analytics>` tag, but separate `<script>` tags.
{% endhint %}

## Limitations

While this integration is still in beta, engaged time and recirculation metrics cannot be measured for your SmartNews app audience.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.chartbeat.com/smartnews/-MAg3MugaG06rYaCVgfc/master.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
