Passing GCLID through in the email from CF7
-
Hi, I’ve installed CF7 for a simple sidebar contact form and I want the GCLID from my google ad clicks to be passed on in the email as plain text so that I can copy/paste it into a spreadsheet if I make a sale and import that back into Google Analytics.
As per this article, my site has this code above the /body tag:
<!-- Google Conversion code --> <script type="text/javascript"> function setCookie(name, value, days){ var date = new Date(); date.setTime(date.getTime() + (days*24*60*60*1000)); var expires = "; expires=" + date.toGMTString(); document.cookie = name + "=" + value + expires; } function getParam(p){ var match = RegExp('[?&]' + p + '=([^&]*)').exec(window.location.search); return match && decodeURIComponent(match[1].replace(/\+/g, ' ')); } var gclid = getParam('gclid'); if(gclid){ var gclsrc = getParam('gclsrc'); if(!gclsrc || gclsrc.indexOf('aw') !== -1){ setCookie('gclid', gclid, 90); } } </script> <!-- End Google Conversion code --> <!-- Update Google Conversion code param --> <script> function readCookie(name) { var n = name + "="; var cookie = document.cookie.split(';'); for(var i=0;i < cookie.length;i++) { var c = cookie[i]; while (c.charAt(0)==' '){c = c.substring(1,c.length);} if (c.indexOf(n) == 0){return c.substring(n.length,c.length);} } return null; } window.onload = function() { document.getElementById('gclid_field').value = readCookie('gclid'); } </script> <!-- End Update Google Conversion param -->
and on the previous form I was using I had added this code in the widget-contact.php:
<input type="hidden" id="gclid_field" name="gclid_field" value="">
which meant I could then add this line of code to the contact-widget.php file (the one activated when the submit button was clicked):
$gclid_field = stripslashes($_POST['gclid_field']);
and I would then have gclid_field populated at the time of sending. That was where I had trouble, I couldn’t get that field to then be included in the email without breaking other stuff. It did work at one point, but the return email address and name of the user didn’t work ??
Anyways CF7 actually looks like a better option as it will easily let me track the number of times the submit button is clicked as well, something that wasn’t as easy in the other contact form.
So can anyone help me to have the GCLID passed on in the email?
Thanks a bunch
- The topic ‘Passing GCLID through in the email from CF7’ is closed to new replies.