I needed a solution which allowed me to include Optimizely’s A/B testing snippet on certain pages, and have the ability to change those page rules without modifying code.
I do this using the Context module, I apply a class to the body for a node with the path “demo”, like so:
Then, in html.tpl.php, in the <head> of my document, I have the following code:
1 2 3 4 5 6 7 |
<?php if (!empty($classes)) { if (strpos($classes, 'has-optimizely') !== false) { print '<script src="https://cdn.optimizely.com/js/xxxx.js"></script>'; } } ?> |