> ## Knowledge Base Index
> Fetch the complete knowledge base index at: https://help.trustmary.com/sitemap.xml
> Use this file to discover available pages before exploring further.
> Pure-Markdown content can be obtained by appending a '.md' suffix to the content URLs listed in the sitemap (without the trailing slash).

# Traffic source specific A/B testing for inpage widgets


1. Add Trustmary tag script to your website head tag or with [Google Tag Manager](https://trustmary.tawk.help/article/installing-trustmary-tag-with-google-tag-manager)
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**

```javascript
<div id="tm-conditional-1"></div>
<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**.

```javascript
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](https://developer.mozilla.org/en-US/docs/Web/API/Document/referrer) includes "google.com" and widget with id "DEFAULT123" for other visitors

```javascript
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.