đ Tagging on Shopify?
Check out our guides on installing our app here.
TLDR
This is a highly detailed document. A summary is as follows.
We have two key methods for tag implementation.
Add our hybrid async tag to the head of your site.
Add our synchronous tag to the head of your site.
Both options work well. Both let you test, personalise and track behaviour with no content flickering.
The file that runs is a small Loader file with some core methods. The Loader then downloads and runs only the tests that the user is eligible for. If a test is not on that page, or the user is not in that audience, we usually do not send the test code.
We recommend that you use one of these two options. Other methods can cause content flickering and lower CLS scores.
The sections below explain the tag, how it works, and your options.
What is the Webtrends Optimize Tag?
The Webtrends Optimize tag is the JavaScript tag that you add to your website. It lets us connect to your website. It is usually a single SCRIPT tag. When you add it to the HEAD tag of your website, we can:
run experiments and optimals
track user activity
give all the other experiences that we build.
You use this tag for client-side experimentation and personalisation. We also have implementation guides for Server-Side, Mobile app, IoT, etc.
How to get your Tag
You can find a full tagging guide in the Optimize UI. Open it from the top nav.
The guide in the UI explains placement, Content Security Policies and Tag Management containers.
In most cases, you put one SCRIPT tag in the HEAD of your website (or only on the pages where you want to test and track).
đ You may also need to update your Content Security Policies (CSPs).
Tagging options
There are three tagging options:
Hybrid Asynchronous
Fully Synchronous
Fully Asynchronous (not recommended)
The sections below explain what each option is, when to use it, and its possible limitations.
âšď¸ To learn how each tagging method affects page performance, read this guide.
Tagging option 1 - Hybrid Asynchronous
What is the Hybrid Asynchronous tag?
This is a newer version of our tag. It is an asynchronous (non-blocking) tag. It hides the page until the tag loads or fails. Users see the same result as with a synchronous tag: the page shows when the tag fires. And the rest of the page continues to load at the same time.
This tag also solves some problems of synchronous default tag, for example if the tag does not respond, or if performance is slower.
â ď¸ This tag is an example only, and it does not work. Please do not add it to your site or give it to other people. We will give you a tag that is unique to your account.
<script type="text/javascript">
!function(){
var src = "//c.webtrends-optimize.com/acs/accounts/abcdefgh-0123-ijkl-4567-mnopqrstuvqz/js/wt.js";
var timeout = 2000; // 2 seconds
var css={add:function(c, id){if(c instanceof Array){c=c.join(' ')}var a=document.getElementsByTagName('head')[0],b=document.createElement('style');b.type='text/css';if(id){b.id=id;}if(b.styleSheet){b.styleSheet.cssText=c}else{b.appendChild(document.createTextNode(c))}a.appendChild(b)}, del:function(id){var el=document.getElementById(id); if(el){el.parentNode.removeChild(el)}}};
var cssid = 'wt_tagHide';
css.add('body { opacity: 0.000001 !important; }', cssid);
var sc = document.createElement('script');
window.WT_ABORT = 0;
sc.src = src;
sc.onload = function(){
window.WT_ABORT = -1;
css.del(cssid);
};
sc.onerror = function(){
window.WT_ABORT = 1;
css.del(cssid);
};
document.getElementsByTagName('head')[0].appendChild(sc);
setTimeout(function(){
if(window.WT_ABORT !== -1) window.WT_ABORT = 1;
css.del(cssid);
}, timeout);
}();
</script>
Why is the Hybrid Asynchronous tag used?
Some websites have a lot of external content to load. With this tag, that content can load while we get and run tests.
This tag also has a timeout, so your page still loads if the tag does not respond.
What potential limitations are there to the Hybrid Asynchronous tag?
Some websites get better performance from a synchronous tag. Our own testing shows that sometimes this tag performs better. Testing is usually the best way to find the right option for your site. Think about the benefits and disadvantages of each option.
Example of Hybrid Asynchronous tag
To run tests on this page, add the query string ?runtest=true
You can also choose how to mask the page:
?mask=none - no masking
?mask=element - only mask the h1 element
?mask=page - mask the entire page
Tagging option 2 - Fully Synchronous
What is the Fully Synchronous tag?
This is our usual tag, and the easiest to add. It has a single remote script reference (to c.webtrends-optimize.com), as shown above.
When you add this tag to the head, we can do all the necessary actions.
<script type="text/javascript" src="//c.webtrends-optimize.com/acs/accounts/abcdefgh-0123-ijkl-4567-mnopqrstuvqz/js/wt.js"></script>
For best results, do not add async or defer attributes to this tag.
Why is the Fully Synchronous tag used?
We have used this tag format since Optimize started.
This tag is the easiest to understand and add. It has only one script reference.
It is a synchronous tag, so it delivers tests to the page a little faster. The browser does not put the tag response in a queue. It processes the response immediately when it arrives.
What potential limitations are there to the Fully Synchronous tag?
The Fully Synchronous tag has two main limitations:
Render-blocking - The browser waits for synchronous JavaScript before it processes the content after it. If your website makes a lot of requests, these other items can take a little longer to load.
Vulnerable to no-responses - Your tag is hosted on Azure CDN. If the tag does not respond at all (this is different from a response with errors), your website can wait for an indefinite time. This is true for all synchronous tags, not only ours. Some companies choose to protect against this risk.
Example of Fully Synchronous tag
To run tests on this page, add the query string ?runtest=true
You can also choose how to mask the page:
?mask=none - no masking
?mask=element - only mask the h1 element
?mask=page - mask the entire page
Tagging option 3 - Asynchronous / Delayed
Some companies add Optimize in a fully asynchronous way. The tag still works this way, because JavaScript usually runs correctly if it runs a little late. But note step 3 below: if the tag is async, step 3 happens too late.
What is an Asynchronous / Delayed tag?
... and why should it be avoided:
This is when users take our usual tag and do one of these things:
Add an async attribute. The tag no longer blocks the page, so we cannot mask the page before users see it.
Add a defer attribute. The browser delays the tag until it decides that it has enough bandwidth.
Write the tag with JavaScript instead of as an HTML tag. Unless you use document.write, this makes the tag async. Then we cannot prevent content flicker and CLS.
Put the tag in a tag management container. The container can be asynchronous. It will probably also write tags to the page with JavaScript, which adds a delay.
Choosing the right approach.
The best way to find the right approach is to try each one.
You do not have to do this through dev cycles with the IT team. You can use Chrome Dev Tools to inject tags and test each option. This needs some developer skill. But it is often a faster way to see the effect on metrics such as CLS, compared with putting different tags through dev cycles and measuring performance in non-production environments.


