TegBooks

Google Analytics Introduction and UTM Framework

Issue link: https://activate.tegrita.com/i/1174290

Contents of this Issue

Navigation

Page 9 of 11

10 How To #3: Integrating Google Analytics with Eloqua C. Capturing UTM Parameters in Form Submissions Javascript Method: To accomplish the same task using JavaScript reference the following code snippet: // --------------- // Requires jQuery // --------------- // ---------------------------------------------------------- // Utility function for getting Query String Parameter values // ---------------------------------------------------------- getParameterByName = function(name) { query = window.location.search.toString(); name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]"); var regexS = "[\\?&]" + name + "=([^&#]*)"; var regex = new RegExp(regexS); results = regex.exec(query); if (results == null) return ""; else return decodeURIComponent(results[1].replace(/\+/g, " ")); } $(document).ready(function() { // ------------------------------------------------------------------------- // Set these variables to the HTML names of the fields if they are different // ------------------------------------------------------------------------- var $utmSource = $('[name=utm_source]'), $utmMedium = $('[name=utm_medium]'), $utmContent = $('[name=utm_content]'), $utmCampaign = $('[name=utm_campaign]'); // -------------- // Set the values // -------------- $utmSource.val(getParameterByName('utm_source')); $utmMedium.val(getParameterByName('utm_medium')); $utmContent.val(getParameterByName('utm_content')); $utmCampaign.val(getParameterByName('utm_campaign')); }); For a working example please visit: https://tegrita.com/capture-utm-parameters-like-a-pro/

Articles in this issue

Links on this page

view archives of TegBooks - Google Analytics Introduction and UTM Framework