|
<!-- Load cookie library --> |
|
<!-- Gocumentation: https://github.com/js-cookie/js-cookie --> |
|
<script src="https://cdn.jsdelivr.net/npm/js-cookie@rc/dist/js.cookie.min.js"></script> |
|
<!-- Save UTMs on coookie Example. https://www.socialbits.net/web-app-de-recruiting-para-rrhh/?utm_source=google&utm_campaing=promo --> |
|
<script type="text/javascript"> |
|
// Get utms from URL and store as cookies |
|
function getUrlVars() { |
|
var vars = {}; |
|
var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m, key, value) { |
|
vars[key] = value; |
|
Cookies.set(key, value, { |
|
expires: 7, |
|
path: '', |
|
domain: 'socialbits.net' |
|
}); |
|
}); |
|
}; |
|
|
|
getUrlVars(); |
|
|
|
// Send cookie info put only on page with form |
|
function getCookies() { |
|
// fix spaces on url |
|
var utm_term = Cookies.get('utm_term'); |
|
var utm_term = decodeURI(utm_term); |
|
var utm_term = utm_term.replace(/%2B/g, "+"); |
|
|
|
var utm_medium = Cookies.get('utm_medium'); |
|
jQuery("input[name='field[90]']").val(utm_medium); |
|
var utm_campaign = Cookies.get('utm_campaign'); |
|
jQuery("input[name='field[91]']").val(utm_campaign); |
|
utm_source = Cookies.get('utm_source'); |
|
jQuery("input[name='field[89]']").val(utm_source); |
|
utm_content = Cookies.get('utm_content'); |
|
jQuery("input[name='field[92]']").val(utm_content); |
|
}; |
|
|
|
document.addEventListener("DOMContentLoaded", function() { |
|
getCookies(); |
|
}); |
|
|
|
// clean localStorage UTMs |
|
// var button = document.getElementsByClassName('form-submit-btn'); |
|
// button[0].addEventListener('click', event => { |
|
// Cookies.remove('utm_medium'); |
|
// Cookies.remove('utm_campaign'); |
|
// Cookies.remove('utm_source'); |
|
// Cookies.remove('utm_content'); |
|
// }); |
|
</script> |