Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example for emitting events without Segment/Mixpanel #31

Open
Johannes5 opened this issue Feb 23, 2022 · 1 comment
Open

Example for emitting events without Segment/Mixpanel #31

Johannes5 opened this issue Feb 23, 2022 · 1 comment

Comments

@Johannes5
Copy link

Thank you for releasing this tool for free! I think it's important to have a free alternative to a 30000€/y Optimizely or a Google-owned Google Optimize.

I'd like to send an event (to an analytics tool and/or my db. I'm not using segment/mixpanel) depending on which component won. But I'm not sure how to do that. I'm also unsure as to how I'm able to define "won".

I just want an event that tells me: visitor/user with this ID experienced variant B of that component.
The component may have a button CTA inside it, eg if the component is an entire landing page.
That would be a "win" directly associated with the variant.
Regardless of that, there are other wins further down the line of the user journey that might be influenced.
So it's important to save, whether a Variant has been experienced.

It would be really helpful to see a code example (in the already very helpful Readme) of events being sent without segment/mixpanel.

  1. for when a variant mounted
  2. for when something in that variant happened.
@skrivanos
Copy link

skrivanos commented Jul 21, 2022

We do this in our global init/setup code. Just implement trackEvent to do whatever you want, such as send a request to your API.

    emitter.addPlayListener((experimentName, variantName) => {
      trackEvent('Experiment Play', {
        experiment: experimentName,
        variant: variantName,
      });
    });

    emitter.addWinListener((experimentName, variantName) => {
      trackEvent('Experiment Win', {
        experiment: experimentName,
        variant: variantName,
      });
    });

Edit:

Oh and, you can simply use the normal emitWin APIs described in README.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants