segmentio/analytics.js-integrations — pull request #162 by dbow (2014-05-27 22:26:18+00:00)
Title: Updates to Chartbeat integration

Hello!

This includes 5 small updates/fixes to the Chartbeat integration:

1. Point README link to homepage instead of dashboard login.
2. Add another option called ```useCanonical``` and default it to ```true```.

```useCanonical``` tells Chartbeat to check for a [canonical link element](https://chartbeat.com/docs/configuration_variables/#useCanonical) to use as the path. If none exists, we fall back to using the page path. But a site with that canonical link element probably wants us to use it, so defaulting to true makes sense.

3. In the existing implementation, anything added by a site to ```_sf_async_config``` independently would be overridden by the ```options``` object after the Chartbeat integration is instantiated. This lets a site set ```_sf_async_config``` values that will be preserved (unless overridden specifically by options/settings).

4. We now support HTTP and HTTPS traffic from the [same endpoint](https://chartbeat.com/docs/adding_the_code/). Updated the load function to reflect that.

5. Chartbeat.js attempts to access ```document.body``` properties/methods immediately on execution, which is why we instruct people to include the async loading script right before the closing ```

``` tag. We received reports from a site implementing Chartbeat via segment.io that they got intermittent errors from Chartbeat.js where it attempted to access properties of a null or undefined object. The only scenario that would cause those errors in that part of our code is if ```document.body``` did not exist. This moves the ```load()``` call inside ```onBody``` to help ensure that ```document.body``` always exists when Chartbeat.js loads and executes.

Note: I was unable to figure out a good way to write a test that makes sure it only loads when ```document.body``` is present. If there's a good way, please let me know! Otherwise, I'm happy to assume the ```on-body``` tests pass and trust that functionality.

Note 2: Seems like there are other tests that are already not passing when I run ```make tests```, even before my changes. All the Chartbeat tests pass though.

Lemme know if I missed anything or you have any questions/comments!