In my previous post I’ve talked about how to manage to use the native Optimizely tracking when using Google Tag Manager . Now we’re going further and we’ll learn how to track the experiment that are based on redirects in the best way possible.
So, firstly you’ll need to enable the Optimizely and Google Analytics integration. Now here is the tricky part. If we’re sending users to an experiment page that it’s based on a redirect we’ll be likely going to lost the original referral info (if not using utm parameters). As it’s a javascript redirection, the original referrer info won’t be kept.
In case we’re lucky because optimizely will write a cookie with the original referral info, se we can read it later! :). That way we could override the referrer field within our pageview tag to keep the real attribution for those visits.
We’ll need a 1st Party Cookie variable to read this cookie value:
Then we’ll need to do use this variable in our pageview tag this way:
There we go, now even if something lands on a redirect experiment, the original referral will be tracked in Google Analytics.