gtag <\/em>method.<\/p>\n\n\n\nAdd this snippet to any page that has a form you want to track.<\/p>\n\n\n\n
<script>\njQuery(\"form input, form select, form textarea\").change(function() {\n gtag('event', 'form interaction', {\n 'form_field': jQuery(this).attr('placeholder')\n });\n});\n<\/script><\/code><\/pre>\n\n\n\nYou can also create a similar tracker for Facebook pixel events by altering the script (both GA and FB events can sit under a single script):<\/p>\n\n\n\n
<script>\njQuery(\"form input, form select, form textarea\").change(function() {\nfbq('track', 'ViewContent', {\n content_name: jQuery(this).attr('placeholder')\n });\n});\n<\/script><\/code><\/pre>\n\n\n\nVanilla JavaScript (w\/o jQuery)<\/h2>\n\n\n\n
in case your site doesn’t use jQuery, you can still use a simpler version of this solution. Since JS lacks some of the methods that are trivial in jQuery (without complex setup), we can only grab the immediate value of the field’s name\/label.<\/p>\n\n\n\n
If you’re using Google Tag Manager, simply use this snippet. You can change the value of form<\/em> to capture a specific form by class or id (e.g. .class or #id). You can also change the value of the attribute you’re <\/p>\n\n\n\n<script>\ndocument.querySelector('form').addEventListener('change', function(e) {\n dataLayer.push({\n 'event': 'form interaction',\n 'form_field': e['target'].getAttribute('name')\n });\n});\n<\/script><\/code><\/pre>\n\n\n\nIf you’re not using Google Tag Manager, you can use this snippet to trigger the event into Google Analytics.<\/p>\n\n\n\n
<script>\ndocument.querySelector('form').addEventListener('change', function(e) {\n gtag('event', 'form interaction', {\n 'form_field': e['target'].getAttribute('name')\n });\n});\n<\/script><\/code><\/pre>\n\n\n\nTesting your selectors<\/h2>\n\n\n\n
If you want to test that you have the correct selectors, you can use this script. Simply paste it in your browser’s Console (click F-12 and navigate to the Console tab) and then interacting with any form on that page (the function resets on page navigation).<\/p>\n\n\n\n
jQuery<\/h3>\n\n\n\njQuery(\"form input, form select, form textarea\").change(function() {\n alert('The field value is '+jQuery(this).attr('placeholder'))\n});<\/code><\/pre>\n\n\n\nVanilla JavaScript<\/h3>\n\n\n\ndocument.querySelector('form').addEventListener('change', function(e) {\n alert('The field value is ' + e['target'].getAttribute('name'))\n});<\/code><\/pre>\n\n\n\nCaveats<\/h2>\n\n\n\n
While this approach is pretty simple, it does bring some challenges.<\/p>\n\n\n\n
\n- This method doesn’t take into account the form’s ID. If you have one for per page, that’s no big deal (as GA events are tied to the page the user triggered them on). If you have multiple forms, e.g. a contact us form and newsletter footer , these can be difficult to analyze separately.
In that case my suggestion is simply to add the form’s ID to the Event Label field (requires additional code, see above).<\/li>\n\n\n\n - Fields can be tracked multiple times – if a user edits a field multiple times, this will be recorded (not necessarily a bad thing)<\/li>\n\n\n\n
- Browser autocomplete will trigger the fields impacted (again, not a bad thing)<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"
A simple guide to tracking from abandonment events for improving conversion rates and campaign targeting.<\/p>\n","protected":false},"author":1,"featured_media":4629,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,2,39,42],"tags":[49,43,200,48],"class_list":["post-4603","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-facebook","category-google-analytics","category-google-tag-manager","category-hubspot","tag-contact-form-7","tag-elementor","tag-forms","tag-gravity-forms"],"_links":{"self":[{"href":"https:\/\/trackingchef.com\/wp-json\/wp\/v2\/posts\/4603","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/trackingchef.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/trackingchef.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/trackingchef.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/trackingchef.com\/wp-json\/wp\/v2\/comments?post=4603"}],"version-history":[{"count":18,"href":"https:\/\/trackingchef.com\/wp-json\/wp\/v2\/posts\/4603\/revisions"}],"predecessor-version":[{"id":6080,"href":"https:\/\/trackingchef.com\/wp-json\/wp\/v2\/posts\/4603\/revisions\/6080"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/trackingchef.com\/wp-json\/wp\/v2\/media\/4629"}],"wp:attachment":[{"href":"https:\/\/trackingchef.com\/wp-json\/wp\/v2\/media?parent=4603"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/trackingchef.com\/wp-json\/wp\/v2\/categories?post=4603"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/trackingchef.com\/wp-json\/wp\/v2\/tags?post=4603"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}