1. Open Marketo and find Google Analytics Client ID field that Marketo should have brought from Salesforce. If it didn’t, follow this instruction from Marketo.
2. Add this field as a hidden field to all your forms.
3. Open one of the forms and located this hidden field. It should look something like this:
1 2 3 4 |
<div class="mktoFormRow"> <input type="hidden" name="gacid" class="mktoField mktoFieldDescriptor mktoFormCol" value="" style="margin-bottom: 10px;"> <div class="mktoClear"></div> </div> |
4. Locate the name attribute of this field. In this example, it’s “gacid”. But in your case, it could be called differently.
5. Add this piece JavaScript code to the website (you may need to replace “gacid” with your GA CID input name on line #35):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
<script> function getCookie(cname) { var name = cname + "="; var ca = document.cookie.split(';'); for (var i = 0; i < ca.length; i++) { var c = ca[i]; while (c.charAt(0) == ' ') c = c.substring(1); if (c.indexOf(name) == 0) { return c.substring(name.length, c.length); } } return ""; } function getCID() { var _ga = getCookie('_ga'); var gaObj = window[window.GoogleAnalyticsObject]; if (typeof gaObj !== 'undefined' && typeof gaObj['getAll'] !== 'undefined') { var tracker = gaObj.getAll()[0]; return tracker.get("clientId"); } else if (typeof _ga === 'string' && _ga.length > 0) { var cidArr = _ga.split('.'); return cidArr.slice(cidArr.length - 2, cidArr.length).join('.'); } } function setHiddenFieldWithCID() { var cid = getCID(); if (typeof cid === 'undefined') { setTimeout(function() { setHiddenFieldWithCID(callback); }, 500); } else { $('input[name="gacid"], input#gacid').val(cid); } } setHiddenFieldWithCID(); setInterval(setHiddenFieldWithCID,1000); </script> |
That’s it – now GA Client IDs should be automatically populated to the hidden fields, which will be synced with Salesforce.