ouija-io/ouija

[Discussion] Provide API Events

Closed this issue · 3 comments

I would like to propose API events for giving users the ability to subscribe to certain events (like authenticating or commenting). Right now I can think of two events that could be used for tracking (with GA/GoSquared/Piwik/etc.):

ouija.on('authenticate', function (user) {
  // track authenticated user
  analytics.track('User auth', {
    name: user.name, // user name
    provider: user.provider // identity provider
  });
});
ouija.on('comment', function (comment) {
  // track authenticated user
  analytics.track('New comment', {
    user: comment.user.name, // user name
    provider: comment.user.provider, // identity provider
    comment: comment.text // content of the comment
  });
});

(Examples use the segment.io API). This would, together with passing the configuration as an object, require a new way to initialise Ouija.

Ideas / Suggestions?

Yeah, I'm a big fan of exposing stuff like this. Simple to implement and super useful for users trying to do the stuff like you mentioned. Only problem is it's a breaking change.

Maybe this should wait until we have to make other breaking changes (ghost apps api)?

Must it be a breaking change?

We could drop instantiation into the snippet & return an instance of ouija (with the proposed emitter).

To make the snippet change non-breaking for current users we can add an option to for automatically instantiate Ouija (default: true as it works currently) or false to allow you to do it yourself.