How does Unbounce pass UTM parameters through to destination URL on link clicks to external site?


#1

I love how Unbounce passes through UTM parameters from my paid ads, and over to other sites when visitors click through my Unbounce landing pages.

I’m looking for guidance on how that is setup in Unbounce – so I can set it up on my own website as well.

Any guidance is greatly appreciated.

Thank you.


#2

Hey Robert

You can access the URL parameters in javascript by calling

‘window.location.search’

You can use this to reference and append it to the end of your pages links.

Hope that helps!


#3

Thanks for the speedy reply. We’ll try that :slight_smile:


#4

Robert,

Just to put my tuppence worth in, I use a two JS routines called ParseUri (Steven Levithan)  and Get Cookie (Shelley Powers) combined in one file. You can then easily include the file and read, write, split and pass the URL parameters or store them in cookies.

If you want the code blocks just drop me a message and I’d be happy to share.

Cheers

Stuart.


#5

Hi Stuart,

Thanks for your help.

If you don’t mind, I’d love to see the example/code you’ve got working for this.

Thanks so much! :slight_smile:


#6

// parseUri 1.2.2> // © Steven Levithan <stevenlevithan.com></stevenlevithan.com>> // MIT License> > function parseUri (str) {> var o   = parseUri.options,> m   = o.parser[o.strictMode ? “strict” : “loose”].exec(str),> uri = {},> i   = 14;> > while (i–) uri[o.key[i]] = m[i] || “”;> > uri[o.q.name] = {};> uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) {> if ($1) uri[o.q.name][$1] = 2;> });> > return uri;> };> > parseUri.options = {> strictMode: false,> key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],> q: &nbsp; {> name: &nbsp; "queryKey",> parser: /(?:^|&)([^&=]\*)=?([^&]\*)/g> },> parser: {> strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]\*)(?::([^:@]\*))?)?@)?([^:\/?#]\*)(?::(\d\*))?))?((((?:[^?#\/]\*\/)\*)([^?#]\*))(?:\?([^#]\*))?(?:#(.\*))?)/,> loose: &nbsp;/^(?:(?![^:@]+:[^:@\/]\*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]\*)(?::([^:@]\*))?)?@)?([^:\/?#]\*)(?::(\d\*))?)(((\/(?:[^?#](?![^?#\/]\*\.[^?#\/.]+(?:[?#]|)))*/?)?([^?#/]*))(?:?([^#]*))?(?:#(.*))?)/> }> };> > //Get cookie routine by Shelley Powers > function get_cookie(Name) {> var search = Name + “=”> var returnvalue = “”;> if (document.cookie.length > 0) {> offset = document.cookie.indexOf(search)> // if cookie exists> if (offset != -1) { > offset += search.length> // set index of beginning of value> end = document.cookie.indexOf(";", offset);> // set index of end of cookie value> if (end == -1) end = document.cookie.length;> returnvalue=unescape(document.cookie.substring(offset, end))> }> }> return returnvalue;> }> > function setCookie(cname, cvalue, exdays) {>     var d = new Date();>     d.setTime(d.getTime() + (exdays*24*60*60*1000));>     var expires = “expires=”+d.toUTCString();>     document.cookie = cname + “=” + cvalue + "; " + expires + “;” + “path=/”;> }> > //Set URL parameters into cookies to store for 1 year to track original parameters - Stuart Mitchell> var cooked_urlpara = get_cookie(“c_urlpara”);> > if (cooked_urlpara != “” && cooked_urlpara != null) { > setCookie (“c_set”, “not set”, 365);> > } else {> > setCookie (“c_urlpara”, parseUri(document.URL).query, 365);> setCookie (“c_utm_medium”, parseUri(document.URL).queryKey.utm_medium, 365);> setCookie (“c_utm_source”, parseUri(document.URL).queryKey.utm_source, 365);> setCookie (“c_utm_content”, parseUri(document.URL).queryKey.utm_content, 365);> setCookie (“c_utm_campaign”, parseUri(document.URL).queryKey.utm_campaign, 365);> setCookie (“c_utm_term”, parseUri(document.URL).queryKey.utm_term, 365);> }Stick that in a JS file, and reference it from your template/header file and it puts the original parameters into cookies for 365 days. I then pull those cookies back into my forms when they are submitted and include them so I can track where the conversion came from originally. I will be expanding this to give some history tracking for multiple visits so I can see the conversion journey. 

I hope that helps a bit, if you need any more clarification then email me stuart@digitalenrich.com

Cheers

Stuart.


#7

Stuart, you’re the man. 


#8

Thank you so much, Stuart! :slight_smile: