Knowledge Base      


How do I replace Campaigns [cmc_vid] token in non-URL attributes?


By default, the cmc.js script will replace tokens in the href="..."src="..." and value="..." attributes of HTML elements.

If you need to use a [cmc_vid] token in another type of attribute, you can add the attribute type to the existing list of attributes by including a special attrs property in a clickmagick_cmc object.

For example, if you had a special data-url="..." attribute, you could add that to the list by including this piece of code before you load the cmc.js script:

<script>
   var clickmagick_cmc = {
      attrs: ['data-url'],
   }
</script>
<script src='//cdn.clkmc.com/cmc.js'></script>


If you needed to add more than one attribute type, separate each one with a comma:

attrs: ['data-url', 'placeholder', ...],

If you already have an existing clickmagick_cmc object on the page because you’re tracking a Campaign click or conversion, add the attrs line anywhere in the existing object. Just be sure to include that final comma at the end of the line.
 

Adding the [cmc_vid] value to JavaScript code

In other cases, you might need to use the [cmc_vid] value in your JavaScript code.

In this scenario, if you don’t already have a clickmagick_cmc object on your page, add one with an empty vid field before you load the cmc.js file, like this:

<script>
   var clickmagick_cmc = {
      vid: '',
   }
</script>
<script src='//cdn.clkmc.com/cmc.js'></script>


If the script sees a vid field, it will fill it in with the unique Visitor ID you can use. For example:

var url = 'https://affiliatenetwork.com?s2=' + clickmagick_cmc.vid;

For the vid property to be initialized, you need to load the cmc.js file before executing your JavaScript code.

Article 864 Last updated: 01/22/2024 10:20:38 AM
https://www.clickmagick.com/kb/?article=864