keen / common-web

Turn web user activity into a analyzable stream of JSON event data
MIT License
493 stars 62 forks source link

Allow custom events #15

Open josephwegner opened 9 years ago

josephwegner commented 9 years ago

I'd like to get some opinions on this... I'm not sure if this is CommonWeb's problem to solve, or not.

CommonWeb kind of abstracts away the idea of what tracking backend you are using, so it's not entirely clear how I can track things that don't fall under the CommonWeb umbrella (ie: someone entered failed CC details into stripe checkout).

I know I could technically access the Keen client by digging through the internals of CommonWeb, but that's brittle and not ideal.

It might be nice to have a function like CommonWeb.customEvent, that essentially just wraps CommonWeb.Callback. Perhaps it would also merge in the global properties.

joshed-io commented 9 years ago

Yeah, I think custom events make sense here. The main benefit of going through CW instead of direct-to-keen is all the CW data model goodness you get to keep.

joshed-io commented 9 years ago

Interface could be something simple like:

CommonWeb.trackCustomEvent("click", $(".thing"), { "moar" : "properties" });

Or, like I think you were saying, just give access to a function that logs an event through CW and takes the properties you want to include:

// including the JS event object so CW can glean properties from it
$(".thing").click(function (event) { CommonWeb.sendCustomEvent(event, { "moar" : "properties" }});

Seems like offering both options wouldn't be too hard.

josephwegner commented 9 years ago

That trackCustomEvent interface seems a little weird. I get what you're going for, but it seems pretty verbose for what we want to achieve.

I'm not sure if this is better, because it's kind of non-standard for javascript, but it might be more readable:

$('.thing').on('click', CommonWeb.customEvent({ "moar" : "properties" }));

That would essentially just return an bound instance of CommonWeb.sendCustomEvent. This has the added benefit of not being so intertwined with jQuery - CommonWeb.customEvent() could be passed as the callback for any sort of event handler.

Thoughts?

joshed-io commented 9 years ago

Like it.

On Thu, Mar 5, 2015 at 1:50 PM, Joe Wegner notifications@github.com wrote:

That trackCustomEvent interface seems a little weird. I get what you're going for, but it seems pretty verbose for what we want to achieve. I'm not sure if this is better, because it's kind of non-standard for javascript, but it might be more readable:

$('.thing').on('click', CommonWeb.customEvent({ "moar" : "properties" }));

That would essentially just return an bound instance of CommonWeb.sendCustomEvent. This has the added benefit of not being so intertwined with jQuery - CommonWeb.customEvent() could be passed as the callback for any sort of event handler.

Thoughts?

Reply to this email directly or view it on GitHub: https://github.com/keen/common-web/issues/15#issuecomment-77437850

OElesin commented 7 years ago

@josephwegner, was anyone able to get this done? This would be a really cool feature.