ouija-io / ouija

Communicating with ghosts
http://ouija.io
BSD 3-Clause "New" or "Revised" License
128 stars 14 forks source link

[Discussion] Provide API Events #56

Closed halfdan closed 9 years ago

halfdan commented 10 years ago

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?

colinmacdonald commented 10 years ago

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)?

mattcreager commented 10 years ago

Must it be a breaking change?

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

colinmacdonald commented 10 years ago

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.