segmentio/analytics.js-integrations — pull request #470 by marcua (2014-12-08 14:54:41+00:00)
Title: [buggy/need help] Add kroanosjs

Hello analytics.js friends! We're working on a [kronos.js](https://github.com/Locu/chronology/tree/master/kronos.js) integration as part of the [Chronology project](http://chronology.github.io/), and running into some problems that we've been wrestling with for the past week or so. I apologize in advance for anything I'm misunderstanding/abusing, and I would love some pointers if you have the time.

I've included the integration so far in this PR, with a test copied from the keen.io integration that's mostly commented out. We're trying to load the kronos.js library from a CDN, but it doesn't appear the window.kronosClient is loaded by the `load()` call. The bug must be in our use of `tag` or in how we asynchronously load the Kronos library in `initialize`.

Here's the output from running the test:

```
marcua@dev1:~/analytics.js-integrations (add-kronosjs)$ make test integration=kronosjs

building : test/index.js
built : test/index.js

Error loading resource http://localhost:51469/saucelabs.js (203). Details: Error downloading http://localhost:51469/saucelabs.js - server replied: Not Found

integrations
✓ should export our integrations

Kronos.js
✓ should have the right settings
loading
#initialize
◦ should create window.kronosClient: :::preload
1) should create window.kronosClient

2 passing (20ms)
1 failing

1) Kronos.js loading #initialize should create window.kronosClient:
Error: assertion failed
at http://localhost:51469/build.js:154
at http://localhost:51469/build.js:17708
at http://localhost:51469/test/mocha.js:4212
at http://localhost:51469/test/mocha.js:4584
at http://localhost:51469/test/mocha.js:4643
at next (http://localhost:51469/test/mocha.js:4510)
at http://localhost:51469/test/mocha.js:4519
at next (http://localhost:51469/test/mocha.js:4463)
at http://localhost:51469/test/mocha.js:4487
at timeslice (http://localhost:51469/test/mocha.js:5480)

:::loaded
undefined
undefined
:::did it work?
make: *** [test] Error 1
```

In particular, we reach before the `load` call (` :::preload`), and get inside the callback (`:::loaded`...`:::did it work`), but `kronos` and `window.kronos` appear to be undefined.

Here are some things We've tried so far
* Changing the protocol to be explicitly `https` instead of `http`.
* Changing script URL to a different location than the CDN, just to ensure the problem isn't with `cdnjs`.
* Verifying that it's not an obvious bug in `kronos.js` by [testing it in a simple browser demo](https://github.com/Locu/chronology/blob/master/kronos.js/demo.html).

We'd be very grateful to receive any pointers you can provide. It would be wonderful to wrap up this integration---let us know how we can help!