The following is an example of how to add the Optimise Sale tag to Google Tag Manager (GTM) using a cookie to record the referral source. The Optimise tag is only activated if the referral source is Optimise, so the campaign landing page should be e.g

1. Create a new custom HTML tag with the following code

<script language="javascript" type="text/javascript">
var ssSessionId = '';
if(ssGetURLParameter('utm_source') != null) {
var ssSessionId = ssGetURLParameter('utm_source');
if (ssSessionId.toLowerCase() == 'optimise') {
function ssGetURLParameter(name) {
return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(||[,""])[1].replace(/\+/g, '%20'))||null
function ssSetCookie(cValue) {
document.cookie = cValue + "=" + cValue + ";expires= " + ssCalculateExpireDate(30) +"; path=/";
function ssCalculateExpireDate (days)
 {var d = new Date();
 d.setTime(d.getTime() + (days*24*60*60*1000));
 return d;

IMPORTANT: the cookie duration (ssCalculateExpireDate above) must be set to match the cookie duration of the campaign.

2. Create a trigger and test the above tag

  1. Create a trigger to activate the above tag  on every page.
  2. Test the above tag is being activated by going to e.g and check that an Optimise cookie is present.

3. Create a new custom HTML tag with the following code and set it to trigger on the completion or thank you page


<script language="javascript" type="text/javascript">
var ssOrderID = '';
var ssAmount = '';
function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i=0; i<ca.length; i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1);
if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
return "";
var ssSessionID = getCookie('optimise');
if(ssSessionID) {
var ssUrl = "{MID}&PID={PID}&AppID={{SaleReference}}&Status={{SaleValue}}";
var oJS;
oJS = document.createElement('script');
oJS.src = ssUrl;


IMPORTANT: {MID} and {PID} must be replaced with the correct values for your campaign. Your Optimise contact will be able to provide these values. {{SaleReference}} and {{SaleValue}} must be replaced with your relevant data layer variables. where relevant. If no Sale Value is required this can be left blank.

4. Create a trigger and test

  1. Create a new trigger to activate the above tag when the thank you or completion page has loaded

IMPORTANT: The trigger must be activated on Window Loaded (not Page View):


2. Test the above by deleting cookies and then completing a transaction from e.g

3. Check your login for a tracked transaction (you may need to wait for up to 1 hour) or ask your Optimise contact to check.