Skip to content

Instantly share code, notes, and snippets.

@dansutherland-engineer
Created February 22, 2024 14:01
Show Gist options
  • Save dansutherland-engineer/aabf843de42c81b866f844f783d62d7e to your computer and use it in GitHub Desktop.
Save dansutherland-engineer/aabf843de42c81b866f844f783d62d7e to your computer and use it in GitHub Desktop.
Liquid A/B Test
{% assign randomNumber = "now" | date: "%N" | modulo: 100 %}
{% if randomNumber > 50 %}
{% render 'snippet-B' %}
<script>
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
'event': 'ABTest',
'variant': 'B'
});
</script>
{% else %}
{% render 'snippet-A' %}
<script>
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
'event': 'ABTest',
'variant': 'A'
});
</script>
{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment