Hello folks,
As already mentioned in another thread (NGINX Caching, PHP dynamic field population, UTM parameters and other problems), I wanted to save utm_source and utm_content in 2 fields of my GF form but ideally WITH caching enabled.
I finally found a way like this:
<script type="text/javascript">
jQuery(document).ready(function($) {
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
//GETTING UTM source & content PARAMETERs
UtmSource = getParameterByName("utm_source");
UtmContent = getParameterByName("utm_content");
$('.js_cachebuster_utm_source input').val(UtmSource);
$('.js_cachebuster_utm_content input').val(UtmContent);
});
</script>
This just needs the form to have 2 fields with CSS classes of js_cachebuster_utm_source and js_cachebuster_utm_content to work fine.
Right now I’ve put that script in my post HTML, right below the form shortcode… It looks like it can also work inside a form HTML field but I’m wondering : where is the best place to add that kind of script?
Thanks a lot,
Cheers,