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
}
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
defaultprop on a variant might work, but it doesn't – nothing is rendered.I came up with a solution that works, but it's ugly:
Could the lib handle this somehow? I think it's a pretty common case.
An imagined implementation: