Mida's tracking script typically initiates tests as soon as the page loads. However, certain scenarios require tests to be activated based on information that becomes available later on the page. For such situations, Mida's Manually with code option can help.
Take, for example, a scenario where you are testing various arrangements of your dropdown menu items. Rather than initiating the test as soon as the page loads, you would prefer to specifically target those visitors who interact with the menu. In this situation, the test is not activated until a visitor clicks on the menu. With this feature, you can ensure a more accurate and relevant test data collection.
Example: Trigger an experiment when someone clicks or hovers over a menu
In Configuration, under When to load test?, choose Manually with code. Mida shows the line to call, mida.execute(your test ID). The test won't run until your code calls it.
For all the loading options, see When to load test: choose when Mida applies your variant.
Then, go to Google Tag Manager, add the specific JS conditions as a new Custom HTML tag in Google Tag Manager and run it at pageload. Note, you need to change the test_id value to your actual test id from the script.
<script>
(function(){
// Find the menu element
var hamburg = document.querySelector('body > header > div.header-mobile > div > div> i > svg')
// If menu element is found
if (hamburg && hamburg.parentNode.parentNode) {
var hamburgParentContainer = hamburg.parentNode.parentNode
// When menu element was clicked
hamburgParentContainer.addEventListener('touchstart',function(e){
// Find the ID in Experiment > Configuration > When to load test? > Manually with code
var test_id = 1234; // Change this to your test id
mida.execute(test_id); // Execute Mida experiment
}, false);
}
})();
</script>

