How to append a Variation ID as a parameter to page links

THIS ARTICLE WILL HELP YOU:

Issue

Sometimes we may want to attribute a conversion in a third party system to a specific variation. 

A real world example would be that we need to know which customer received a certain offer or discount that was run in a Convert experiment.

We might be able to catch that on a third party system such as a CRM, with a link parameter. 

This article will explain how to add the variation id to the links on your experiment page.

Solution 

Add the following code to your "Global Experience JS section". You can find it in the Visual Editor by clicking on the gear icon.

Make sure that you know the selector of the link you want to change, to replace it in the code. If you want to change all of them, just replace the "selector" to "A". That would change all link selectors.

*Split URL experiments do not have this section, so you would need to add it to the Global Project JavaScript section of your Project on those cases.

convert.$(document).ready(function(){

// Change the value between the quotes to match your link selector
// If modifying all links just enter A
var selector = "selector";

// In the next line change the experiment id to yours. Replace the 123456789
var newAttr = $("selector").attr('href') + '?variation=' + convert.currentData.experiments[123456789].variation_id;
convert.$("selector").attr("href", newAttr );

});

 

If you preview your variation with the preview or force variation links provided in the Visual Editor, you should see the change in your link.