1. Add Trustmary tag script to your website head tag or with Google Tag Manager (See the links below.)

  2. Pick and customize one of the examples below and add it to your preferred location in your website.

Example 1: Show experiment with id "EXP1234567" only if utm_campaign query parameter equals august_newsletter

<div id="tm-conditional-1"></div> 
<script>
let wrapperId = `tm-conditional-1`;

function getEmbedCode() {
if (window.location.search.includes(`utm_campaign=august_newsletter`))
return `<div data-trustmary-experiment="EXP1234567</div>`;
else return false;
}

let embedCode = getEmbedCode();
let wrapperElement = document.getElementById(wrapperId);
if (embedCode && wrapperElement) {
wrapperElement.innerHTML = embedCode;
if (window.TrustmaryEmbed) {
window.TrustmaryEmbed.initAllExperiments();
window.TrustmaryEmbed.initAllWidgets();
}
}
</script>

For the rest of the examples use the same code, but replace getEmbedCode function with the provided example.

Example 2: Same as Example 1, but show widget with id "DEFAULT123" to visitors who are not part of the august_newsletter utm_campaign.

function getEmbedCode() { 
if (window.location.search.includes(`utm_campaign=august_newsletter`))
return `<div data-trustmary-experiment="EXP1234567"></div>`;
else return `<div data-trustmary-widget="DEFAULT123"></div>`;
}

Example 3: Show widget with id "WIDGET1234" to visitors whose referrer includes "google.com" and widget with id "DEFAULT123" for other visitors

function getEmbedCode() { 
if (document.referrer.includes(`google.com`))
return `<div data-trustmary-widget="WIDGET1234"></div>`;
else return `<div data-trustmary-widget="DEFAULT123"</div>`;
}


You can conditionally display embeds in different parts of your website by repeating the above process with different wrapperIds: tm-conditional-2, tm-conditional-3, etc.

Here are couple of links to help you with the first step if necessary.

Did this answer your question?