segmentio / analytics.js-core

The hassle-free way to integrate analytics into any web application.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Warn if continue to use shim after real analytics loaded?

chishaku opened this issue · comments

#59 is unresolved.

I'm creating a new issue because I'm currently trying to resolve this problem and workarounds described in #59 are not working for me.

Description of the issue copied from #59:

I had some code that looked like this:

const analytics = window.analytics;

function page() {
  analytics.page(...)
}

It worked completely fine except in the rare case that the code ran before analytics.js was loaded.

In such cases the analytics.page() call still works and is queued by the snippet, to be flushed later by the true Analytics object (once it loads), I suppose. But the subtle bug in the above is that the reference const analytics above will in such cases always point to the shim! So future calls to page() will just not do anything (they will make calls on the now discarded shim).

Can I suggest to help future people who run into this that when you flush the messages from the shim, you also set the existing "factory" functions to throw and point users to some documentation explaining where they might be going wrong?

commented

This issue has been automatically marked stale because it has not had any activity in the last 60 days. If no further activity occurs within 7 days, it will be closed. Closed does not mean "never", just that it has no momentum to get accomplished any time soon. See CONTRIBUTING.md for more info.

commented

Closing due to staleness. Closed does not mean "never", just that it has no momentum to get accomplished any time soon. See CONTRIBUTING.md for more info.