common-web icon indicating copy to clipboard operation
common-web copied to clipboard

Allow custom events

Open josephwegner opened this issue 10 years ago • 5 comments

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.

josephwegner avatar Mar 04 '15 15:03 josephwegner

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 avatar Mar 04 '15 23:03 joshed-io

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.

joshed-io avatar Mar 04 '15 23:03 joshed-io

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?

josephwegner avatar Mar 05 '15 19:03 josephwegner

Like it.

On Thu, Mar 5, 2015 at 1:50 PM, Joe Wegner [email protected] 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

joshed-io avatar Mar 06 '15 23:03 joshed-io

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

OElesin avatar Jun 24 '17 05:06 OElesin