UTM Trackers & Cookies
The intention of UTM tracker plugins is:
- To collect UTM, referrer and similar information from the first user visit and store this information as a cookie
- To embed this info into every form on-site, by default, so we can use it and submit it together with the form
We are using only the first function, as the second is not needed for now.
Plugins we are using now
We had two plugins for the same task installed, and there is no need for both of them.
So let’s decide on the better one; and the decisive winner is - UTM Tracker!
Configuring UTM Tracker
Domain must be prefixed with a period like “.cnc24.com” to allow cookies to propagate on subdomains also.
JS libraries ‘utm_cookie’ and ‘utm_form’
Coding this feature is fairly straightforward, but is not needed as plugin UTM Tracker is obviously already using the code from the same library.
This JS library medius/utm_cookie saves UTM info in a cookie and another library medius/utm_form adds this extra UTM information as hidden fields on a any form. More explanation in accopanying article: How To Add UTM And Referrer Information To Lead Forms?
Again, very important!
When defining a cookie, the domain must start WITH a period, so cookies will propagate also to any subdomain, in our case: wizard.cnc24.com.
As we are avoiding using jQuery anymore, the shortest vanilla-JS function to get a value of a cookie is the following:
const getCookie = (name) => ( document.cookie.match('(^|;)\\s*' + name + '\\s*=\\s*([^;]+)')?.pop() || '' )