{"id":243,"date":"2024-06-10T13:04:00","date_gmt":"2024-06-10T13:04:00","guid":{"rendered":"https:\/\/smartsource.com.sg\/blog\/?p=243"},"modified":"2024-06-10T13:04:00","modified_gmt":"2024-06-10T13:04:00","slug":"implementing-google-tag-manager-on-a-simple-html-file-with-a-form","status":"publish","type":"post","link":"https:\/\/smartsource.com.sg\/blog\/index.php\/2024\/06\/10\/implementing-google-tag-manager-on-a-simple-html-file-with-a-form\/","title":{"rendered":"Implementing Google Tag Manager on a Simple HTML File with a Form"},"content":{"rendered":"\n<p>This tutorial will guide you through the steps to implement Google Tag Manager (GTM) on a simple HTML file with a form. We will include the GTM container code, create a simple form, and track form submissions using GTM.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Step 1: Create a Google Tag Manager Account and Container<\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Sign in to Google Tag Manager<\/strong>: Go to <a href=\"https:\/\/tagmanager.google.com\/\">Google Tag Manager<\/a> and sign in with your Google account.<\/li>\n\n\n\n<li><strong>Create an Account<\/strong>: Click on &#8220;Create Account,&#8221; enter your account name, and set your country.<\/li>\n\n\n\n<li><strong>Create a Container<\/strong>: Enter a container name (e.g., &#8220;My Website&#8221;) and select &#8220;Web&#8221; as the target platform. Click &#8220;Create.&#8221;<\/li>\n\n\n\n<li><strong>Install GTM Code Snippets<\/strong>: After creating the container, GTM will provide two code snippets. Copy these snippets for later use.<\/li>\n<\/ol>\n\n\n\n<h4 class=\"wp-block-heading\">Step 2: Add GTM Code to Your HTML File<\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Create an HTML File<\/strong>: Create a new HTML file named <code>index.html<\/code>.<\/li>\n\n\n\n<li><strong>Add GTM Code Snippets<\/strong>: Insert the GTM code snippets into your HTML file. The first snippet goes inside the <code>&lt;head><\/code> tag, and the second snippet goes immediately after the opening <code>&lt;body><\/code> tag.<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!DOCTYPE html>\n&lt;html lang=\"en\">\n&lt;head>\n    &lt;meta charset=\"UTF-8\">\n    &lt;meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n    &lt;title>Simple Form with GTM&lt;\/title>\n    &lt;!-- Google Tag Manager -->\n    &lt;script>\n      (function(w,d,s,l,i){w&#91;l]=w&#91;l]||&#91;];w&#91;l].push({'gtm.start':\n      new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)&#91;0],\n      j=d.createElement(s),dl=l!='dataLayer'?'&amp;l='+l:'';j.async=true;j.src=\n      'https:\/\/www.googletagmanager.com\/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);\n      })(window,document,'script','dataLayer','GTM-XXXXXX'); \/\/ Replace GTM-XXXXXX with your container ID\n    &lt;\/script>\n    &lt;!-- End Google Tag Manager -->\n&lt;\/head>\n&lt;body>\n    &lt;!-- Google Tag Manager (noscript) -->\n    &lt;noscript>&lt;iframe src=\"https:\/\/www.googletagmanager.com\/ns.html?id=GTM-XXXXXX\"\n    height=\"0\" width=\"0\" style=\"display:none;visibility:hidden\">&lt;\/iframe>&lt;\/noscript>\n    &lt;!-- End Google Tag Manager (noscript) -->\n    \n    &lt;h1>Simple Form&lt;\/h1>\n    &lt;form id=\"simple-form\" action=\"#\" method=\"post\">\n        &lt;label for=\"name\">Name:&lt;\/label>\n        &lt;input type=\"text\" id=\"name\" name=\"name\" required>\n        &lt;br>&lt;br>\n        &lt;label for=\"email\">Email:&lt;\/label>\n        &lt;input type=\"email\" id=\"email\" name=\"email\" required>\n        &lt;br>&lt;br>\n        &lt;button type=\"submit\">Submit&lt;\/button>\n    &lt;\/form>\n\n    &lt;script>\n        document.getElementById('simple-form').addEventListener('submit', function(event) {\n            event.preventDefault(); \/\/ Prevent the default form submission\n            dataLayer.push({\n                'event': 'formSubmit',\n                'formId': 'simple-form',\n                'formName': 'Simple Form'\n            });\n            alert('Form submitted!');\n        });\n    &lt;\/script>\n&lt;\/body>\n&lt;\/html>\n\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Step 3: Configure GTM to Track Form Submissions<\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Go to Google Tag Manager<\/strong>: Open your GTM container.<\/li>\n\n\n\n<li><strong>Create a New Tag<\/strong>:\n<ul class=\"wp-block-list\">\n<li>Click on &#8220;Tags&#8221; in the left-hand menu.<\/li>\n\n\n\n<li>Click on &#8220;New&#8221; and name your tag (e.g., &#8220;Form Submission Tag&#8221;).<\/li>\n\n\n\n<li>Click on &#8220;Tag Configuration&#8221; and select &#8220;Google Analytics: GA4 Event.&#8221;<\/li>\n\n\n\n<li>Configure the tag:\n<ul class=\"wp-block-list\">\n<li>Measurement ID: Enter your GA4 Measurement ID.<\/li>\n\n\n\n<li>Event Name: <code>form_submit<\/code><\/li>\n\n\n\n<li>Event Parameters: Add parameters like <code>form_id<\/code> and <code>form_name<\/code> to match the dataLayer push.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Create a Trigger for Form Submissions<\/strong>:\n<ul class=\"wp-block-list\">\n<li>Click on &#8220;Triggering&#8221; and select &#8220;New.&#8221;<\/li>\n\n\n\n<li>Name your trigger (e.g., &#8220;Form Submit Trigger&#8221;).<\/li>\n\n\n\n<li>Choose &#8220;Custom Event&#8221; as the trigger type.<\/li>\n\n\n\n<li>Event Name: <code>formSubmit<\/code><\/li>\n\n\n\n<li>Save the trigger.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Save and Publish<\/strong>: Save your tag and trigger, then click &#8220;Submit&#8221; to publish your GTM container.<\/li>\n<\/ol>\n\n\n\n<h4 class=\"wp-block-heading\">Step 4: Verify Implementation<\/h4>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Preview GTM<\/strong>: In GTM, click on &#8220;Preview&#8221; to enter preview mode.<\/li>\n\n\n\n<li><strong>Open Your HTML File<\/strong>: Open <code>index.html<\/code> in your browser.<\/li>\n\n\n\n<li><strong>Submit the Form<\/strong>: Fill out the form and click &#8220;Submit.&#8221;<\/li>\n\n\n\n<li><strong>Check GTM Debug Console<\/strong>: Ensure that the <code>formSubmit<\/code> event is pushed to the dataLayer and that your tag fires correctly.<\/li>\n<\/ol>\n\n\n\n<p>By following these steps, you will successfully implement Google Tag Manager on a simple HTML file with a form, and track form submissions using GTM.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial will guide you through the steps to implement Google Tag Manager (GTM) on a simple HTML file with a form. We will include the GTM container code, create&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[189,188],"class_list":["post-243","post","type-post","status-publish","format-standard","hentry","category-tutorials","tag-datalayer","tag-google-tag-manager"],"_links":{"self":[{"href":"https:\/\/smartsource.com.sg\/blog\/index.php\/wp-json\/wp\/v2\/posts\/243","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/smartsource.com.sg\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/smartsource.com.sg\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/smartsource.com.sg\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/smartsource.com.sg\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=243"}],"version-history":[{"count":1,"href":"https:\/\/smartsource.com.sg\/blog\/index.php\/wp-json\/wp\/v2\/posts\/243\/revisions"}],"predecessor-version":[{"id":244,"href":"https:\/\/smartsource.com.sg\/blog\/index.php\/wp-json\/wp\/v2\/posts\/243\/revisions\/244"}],"wp:attachment":[{"href":"https:\/\/smartsource.com.sg\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=243"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/smartsource.com.sg\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=243"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/smartsource.com.sg\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=243"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}