Skip to content

Render "original" variant when user has opted out of analytics? #4

Description

@lukehorvat

Hi. Cool lib, but I'm wondering how to handle the case where the user has opted out of analytics (either via a website's privacy settings, or an adblocker is preventing Optimize from loading).

In such a case, it would be nice to always render the "original" variant. I thought that setting the default prop on a variant might work, but it doesn't – nothing is rendered.

I came up with a solution that works, but it's ugly:

render() {
  const original = <p>Original</p>;

  return (
    <div>
      {user.isAnalyticsEnabled() ? (
        <Experiment name="my-test">
          <Variant default id="0">
            {original}
          </Variant>
          <Variant id="1">
            <p>Variant 1</p>
          </Variant>
        </Experiment>
      ) : (
        original
      )}
    </div>
  );
}

Could the lib handle this somehow? I think it's a pretty common case.

An imagined implementation:

import { Experiment } from 'react-google-optimize';

if (user.isAnalyticsEnabled()) {
  // Load gtag script
} else {
  Experiment.disabled = true; // Causes all experiments to render the 'default' variant
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions