{"id":610,"date":"2017-02-22T00:00:00","date_gmt":"2017-02-22T00:00:00","guid":{"rendered":"http:\/\/blog.hostinger.io\/hostinger-tutorials\/uncategorized\/wordpresshow-to-add-google-analytics-to-wordpress\/"},"modified":"2026-03-10T10:07:47","modified_gmt":"2026-03-10T10:07:47","slug":"how-to-add-google-analytics-to-wordpress","status":"publish","type":"post","link":"\/my\/tutorials\/how-to-add-google-analytics-to-wordpress","title":{"rendered":"How to add Google Analytics to a WordPress website"},"content":{"rendered":"<?xml encoding=\"utf-8\" ?><p>Google Analytics is a web analytics service that tracks and reports website traffic, providing deep insights into how visitors interact with your content.<\/p><p>By connecting Google Analytics to your WordPress site, you can identify your most popular pages, understand where your traffic comes from, and track conversion goals like form submissions or product purchases.<\/p><p>These insights help you optimize your site&rsquo;s user experience, improve your SEO strategy, and ultimately grow your online presence.<\/p><p>There are three ways to add Google Analytics to WordPress, ranging from beginner-friendly plugins to code-level tweaks:<\/p><ol class=\"wp-block-list\">\n<li><strong>Using a WordPress plugin.<\/strong> Using plugins like Site Kit by Google is the easiest method to connect Google Analytics to a WordPress site. It also allows you to view your traffic data directly within your WordPress dashboard.<\/li>\n\n\n\n<li><strong>Via Google Tag Manager.<\/strong> This advanced method uses a single &ldquo;container&rdquo; to manage multiple tracking scripts at once. It&rsquo;s ideal for users who want to track complex interactions, such as button clicks or video engagement, without needing to edit code frequently.<\/li>\n\n\n\n<li><strong>Adding a code snippet to the functions.php file.<\/strong> This method involves adding a PHP function to your child theme&rsquo;s <strong>functions.php<\/strong> file to inject the tracking script. It is a lightweight, high-performance option that avoids the need for extra plugins.<\/li>\n<\/ol><p>Feel free to select a method that aligns with your technical comfort level and the amount of data you need to track.<\/p><p>\n\n\n\n<\/p><h2 class=\"wp-block-heading\" id=\"h-how-to-create-a-google-analytics-4-property\">How to create a Google Analytics 4 property<\/h2><p>To start tracking data, you must first set up a <a href=\"\/my\/tutorials\/google-analytics-4-tutorial\">Google Analytics 4 (GA4)<\/a> property and obtain a <strong>Measurement ID<\/strong>. This ID tells Google which specific website the data belongs to, and you&rsquo;ll need this code to connect Google Analytics to WordPress, no matter which method you choose.<\/p><p>Follow these steps to create a new Google Analytics property and find your <strong>Measurement ID<\/strong>:<\/p><ol class=\"wp-block-list\">\n<li>Go to the Google Analytics website and make sure you&rsquo;re signed into your Google account.<\/li>\n\n\n\n<li>Click <strong>Start measuring<\/strong> on the initial landing page.<\/li>\n\n\n\n<li>Insert your account name in the provided field.&nbsp;<\/li>\n\n\n\n<li>Type in your property name, which represents your website name.<\/li>\n\n\n\n<li>Select your business industry from the drop-down and specify your business size.<\/li>\n\n\n\n<li>Select your business objectives and complete the process by clicking <strong>Create<\/strong>.<\/li>\n\n\n\n<li>When you see the <strong>Start collecting data<\/strong> page, choose <strong>Web<\/strong>.<\/li>\n\n\n\n<li>Enter your <strong>Website URL <\/strong>and the <strong>Stream<\/strong> name in the respective fields. Click <strong>Create &amp; continue<\/strong>.<\/li>\n<\/ol><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"69e00ef67d0d0\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-large wp-lightbox-container\"><img decoding=\"async\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2017\/02\/set-up-data-stream-menu-on-google-analytics-1024x511.png\" alt=\"The set up data stream page on Google Analytics 4\" class=\"wp-image-138578\"><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>When you go to <strong>Home<\/strong>, you&rsquo;ll see the <strong>Measurement ID<\/strong>, which starts with &ldquo;G-&ldquo;.<\/p><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"69e00ef67e3c2\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-full wp-lightbox-container\"><img decoding=\"async\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2017\/02\/measurement-id-google-analytics.png\" alt=\"Measurement ID example on Google Analytics dashboard\" class=\"wp-image-138580\"><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><h3 class=\"wp-block-heading\">How to find Google Analytics Measurement ID in an existing property<\/h3><p>Your <strong>Measurement ID<\/strong> is the unique identifier (starting with &ldquo;G-&ldquo;) that links your website to your specific data stream.<\/p><ol class=\"wp-block-list\">\n<li>Sign in to your Google Analytics account.<\/li>\n\n\n\n<li>Click <strong>Admin <\/strong>(the gear icon) in the bottom-left corner of your dashboard.<\/li>\n\n\n\n<li>Look for the <strong>Property Settings<\/strong> column (the middle column) and click on <strong>Data Collection and Modification<\/strong> &rarr; <strong>Data Streams<\/strong>.<\/li>\n\n\n\n<li>Select your existing website&rsquo;s name.<\/li>\n\n\n\n<li>Locate the <strong>Measurement ID<\/strong> in the top-right corner of the <strong>Web<\/strong> <strong>stream details<\/strong> window.<\/li>\n\n\n\n<li>Click the <strong>Copy<\/strong> icon next to the ID to connect Google Analytics to WordPress using your preferred method.<\/li>\n<\/ol><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"69e00ef67f84b\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-large wp-lightbox-container\"><img decoding=\"async\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2017\/02\/google-analytics-measurement-id-example-1024x654.png\" alt=\"Google Analytics Measurement ID on the Web stream details page\" class=\"wp-image-138581\"><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p><div><p class=\"important\"><strong>Important!<\/strong> If you see an ID starting with &ldquo;UA-&ldquo;, you are looking at an old Universal Analytics property. Google Analytics 4 IDs always start with &ldquo;G-&ldquo;. If you don&rsquo;t have a &ldquo;G-&rdquo; ID, you need to create a new GA4 property.<\/p><\/div>\n\n\n\n<\/p><p>After creating a property and getting the <strong>Measurement ID<\/strong>, connect your WordPress site to the Google Analytics servers. You can choose any of the three methods below.<\/p><h2 class=\"wp-block-heading\" id=\"h-how-to-add-google-analytics-with-a-wordpress-plugin\">How to add Google Analytics with a WordPress plugin<\/h2><p>Using a <a href=\"\/my\/tutorials\/google-analytics-wordpress-plugins\">Google Analytics WordPress plugin<\/a> is the best method for users who want to view data directly inside their WordPress dashboard. We&rsquo;re using the <strong>Site Kit by Google <\/strong>plugin to demonstrate, as it&rsquo;s the official tool and integrates with other Google services automatically:<\/p><ol class=\"wp-block-list\">\n<li><a href=\"\/my\/tutorials\/how-to-install-wordpress-plugins\">Install the WordPress plugin<\/a> on your site.<\/li>\n\n\n\n<li>Click the <strong>Start Setup<\/strong> button on the dashboard notification.<\/li>\n\n\n\n<li>Sign in to your Google account.<\/li>\n\n\n\n<li>Grant the necessary permissions for Site Kit to access your data.<\/li>\n\n\n\n<li>Follow the steps to verify your site ownership.<\/li>\n\n\n\n<li>Select your <strong>Account<\/strong>, <strong>Property<\/strong>, and <strong>Data Stream<\/strong> from the dropdown menus.<\/li>\n\n\n\n<li>Click <strong>Complete setup<\/strong> to finish.<\/li>\n<\/ol><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"69e00ef680a67\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-large wp-lightbox-container\"><img decoding=\"async\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2017\/02\/google-site-kit-inteface-in-wordpress-dashboard-1024x357.png\" alt=\"Google Site Kit menu on a WordPress dashboard\" class=\"wp-image-138582\"><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><h2 class=\"wp-block-heading\" id=\"h-how-to-add-google-analytics-to-wordpress-using-google-tag-manager\">How to add Google Analytics to WordPress using Google Tag Manager<\/h2><p>Google Tag Manager (GTM) acts as a central hub for all your tracking scripts. Instead of adding separate code for Google Analytics, Facebook Pixel, and Google Ads, you can install a single GTM container only.<\/p><p>This method is ideal if you want to track specific user actions that standard Analytics might miss, such as button clicks, form submissions, or video engagement.<\/p><p>Connecting Google Analytics to WordPress via GTM requires multiple steps:<\/p><h3 class=\"wp-block-heading\">Set up your Google Tag Manager Container<\/h3><ol class=\"wp-block-list\">\n<li>Sign in to Google Tag Manager and click <strong>Create Account<\/strong>.<\/li>\n\n\n\n<li>Enter your company name and select your country.<\/li>\n\n\n\n<li>In the <strong>Container Setup<\/strong>, enter your domain name (e.g., domain.tld) and select <strong>Web<\/strong> as the platform.<\/li>\n\n\n\n<li>Click <strong>Create<\/strong> and accept the terms. A pop-up will appear with two code snippets. Keep this open.<\/li>\n<\/ol><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"69e00ef681c92\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-large wp-lightbox-container\"><img decoding=\"async\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2017\/02\/google-tag-manager-code-snippets-1024x767.png\" alt=\"Code snippets to install Google Tag Manager\" class=\"wp-image-138584\"><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><h3 class=\"wp-block-heading\">Install Google Tag Manager on WordPress<\/h3><p>The easiest way to install these snippets safely is with the <strong>Code Snippets<\/strong> plugin.<\/p><ol class=\"wp-block-list\">\n<li>In your WordPress dashboard, install and activate the <strong>Code Snippets <\/strong>plugin.<\/li>\n\n\n\n<li>Navigate to <strong>Snippets<\/strong> &rarr; <strong>Add New<\/strong>.<\/li>\n\n\n\n<li>Title it &ldquo;GTM Header&rdquo; and paste the following code into the <strong>Code<\/strong> box:<\/li>\n<\/ol><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">add_action( 'wp_head', function () { ?&gt;&nbsp;\n\n&lt;?php } );<\/pre><ol start=\"4\" class=\"wp-block-list\">\n<li>Paste your actual GTM script in the middle.<\/li>\n<\/ol><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"69e00ef682f2d\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-large wp-lightbox-container\"><img decoding=\"async\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2017\/02\/adding-GTM-script-using-code-snippet-plugin-1024x469.png\" alt=\"Adding a new Google Tag Manager script using Code Snippet plugin\" class=\"wp-image-138585\"><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><ol start=\"5\" class=\"wp-block-list\">\n<li>On the <strong>Location<\/strong> menu, select <strong>Run everywhere<\/strong> and click <strong>Save and Activate<\/strong>.<\/li>\n\n\n\n<li>Click the Add New button again.<\/li>\n\n\n\n<li>Title it &ldquo;GTM Body&rdquo; and paste the following code into the <strong>Code<\/strong> box:<\/li>\n<\/ol><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">add_action( 'wp_body_open', function () { ?&gt;&nbsp;\n\n&lt;?php } );<\/pre><ol start=\"8\" class=\"wp-block-list\">\n<li>Paste your actual GTM noscript code in the middle.<\/li>\n<\/ol><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"69e00ef684259\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-large wp-lightbox-container\"><img decoding=\"async\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2017\/02\/adding-GTM-noscript-using-code-snippet-plugin-1024x469.png\" alt=\"Adding a new Google Tag Manager noscript using Code Snippet plugin\" class=\"wp-image-138586\"><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><ol start=\"9\" class=\"wp-block-list\">\n<li>On the <strong>Location<\/strong> menu, select <strong>Run everywhere<\/strong> and click <strong>Save and Activate<\/strong>.<\/li>\n<\/ol><h3 class=\"wp-block-heading\">Connect Google Analytics via Google Tag Manager<\/h3><ol class=\"wp-block-list\">\n<li>In your GTM dashboard, go to <strong>Tags<\/strong> &rarr; <strong>New<\/strong>.<\/li>\n\n\n\n<li>Name the tag &ldquo;GA4 WordPress configuration&rdquo;.<\/li>\n\n\n\n<li>Click the pencil icon on the <strong>Tag Configuration <\/strong>menu, choose <strong>Google Analytics<\/strong> &rarr; <strong>Google Tag<\/strong>.<\/li>\n\n\n\n<li>Enter your Google Analytics <strong>Measurement ID <\/strong>in the <strong>Tag ID <\/strong>field. Click <strong>Save<\/strong>.<\/li>\n\n\n\n<li>Check your tag in the <strong>Tags<\/strong> menu, then click the blue <strong>Submit<\/strong> button in the top-right corner. Click <strong>Publish<\/strong> afterward to finish.<\/li>\n<\/ol><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"69e00ef685645\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-large wp-lightbox-container\"><img decoding=\"async\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"\/tutorials\/wp-content\/uploads\/sites\/2\/2017\/02\/submit-button-in-google-tag-manager-1024x528.png\" alt=\"The Submit button in Google Tag Manager\" class=\"wp-image-138587\"><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><h2 class=\"wp-block-heading\" id=\"h-how-to-add-google-analytics-to-wordpress-using-functions-php-code\">How to add Google Analytics to WordPress using functions.php code<\/h2><p>This method is preferred by developers who want to avoid extra plugins and keep the site&rsquo;s code footprint small. The process involves adding a <a href=\"\/my\/tutorials\/functions-php-wordpress\">PHP function<\/a> in conjunction with a <a href=\"\/my\/tutorials\/what-are-wordpress-hooks\">WordPress hook<\/a>.<\/p><p>If you wish to proceed with this step, ensure that you <a href=\"\/my\/tutorials\/how-to-create-wordpress-child-theme\">create a child theme<\/a> and add the code to its <strong>functions.php<\/strong> file. This way, you&rsquo;re keeping the tracking code intact even if the original theme files are going through version updates.<\/p><p>Follow these steps to add the Google Analytics script manually to your WordPress <strong>functions.php<\/strong> file:<\/p><ol class=\"wp-block-list\">\n<li>Go to your <a href=\"\/my\/tutorials\/wordpress-theme-editor\">WordPress Theme File Editor<\/a>. If you are using a block theme, select <strong>Tools<\/strong> &rarr; <strong>Theme File Editor <\/strong>in your WordPress dashboard. If the Theme File Editor isn&rsquo;t available, you&rsquo;ll need to access your site via FTP\/SFTP and edit the file directly.<\/li>\n\n\n\n<li>Select your child theme from the <strong>Select theme to edit <\/strong>dropdown menu.<\/li>\n\n\n\n<li>Open the <strong>functions.php<\/strong> file from the list on the right.<\/li>\n\n\n\n<li>Paste the following code snippet at the very bottom of the file:<\/li>\n<\/ol><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\/\/ Add Google Analytics 4 (GA4) Tracking Code to WordPress Header\nadd_action('wp_head', 'wp_custom_add_google_analytics');\nfunction wp_custom_add_google_analytics() {\n   ?&gt;\n   &lt;script async src=\"https:\/\/www.googletagmanager.com\/gtag\/js?id=G-MEASUREMENT-ID\"&gt;&lt;\/script&gt;\n   &lt;script&gt;\n     window.dataLayer = window.dataLayer || [];\n     function gtag(){dataLayer.push(arguments);}\n     gtag('js', new Date());\n\n     gtag('config', 'G-MEASUREMENT-ID');\n   &lt;\/script&gt;\n   &lt;?php\n}<\/pre><ol start=\"5\" class=\"wp-block-list\">\n<li>Replace both instances of G-MEASUREMENT-ID with your actual Measurement ID.<\/li>\n\n\n\n<li>Click <strong>Update File<\/strong>.<\/li>\n<\/ol><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"69e00ef686aba\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-large wp-lightbox-container\"><img decoding=\"async\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/www.hostinger.com\/tutorials\/wp-content\/uploads\/sites\/2\/2017\/02\/google-analytics-script-snippet-in-wordpress-functions-php-file-2-1024x621.png\" alt=\"The Google Analytics script in a functions.php WordPress file\" class=\"wp-image-138629\"><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>Note that after adding the code to your<strong> functions.php<\/strong> file, your WordPress dashboard won&rsquo;t reflect any changes. Unlike using a plugin like Site Kit, manual code injection does not create a dashboard inside WordPress.<\/p><p>So, follow these steps to verify that the script is actually loading on your site:<\/p><ol class=\"wp-block-list\">\n<li>Open your website in a browser.<\/li>\n\n\n\n<li>Right-click anywhere on the page and select <strong>View Page Source<\/strong>.<\/li>\n\n\n\n<li>Press <strong>Ctrl + F<\/strong> (or <strong>Cmd + F<\/strong> on Mac) and search for your <strong>Measurement ID<\/strong>.<\/li>\n\n\n\n<li>If you see your code snippet in the source code, the tracking is active.<\/li>\n<\/ol><h2 class=\"wp-block-heading\" id=\"h-why-is-google-analytics-important\">Why is Google Analytics important?<\/h2><p>Here are the reasons why you should consider adding Google Analytics to your WordPress site:<\/p><ul class=\"wp-block-list\">\n\n<li><strong>Traffic source visibility. <\/strong>Track traffic sources such as organic search, direct visits, referrals, and social media to understand what drives visitors to your site.<\/li>\n\n\n<li><strong>Content performance insights. <\/strong>Identify pages that attract the most traffic and engagement, so you can update, expand, or replicate high-performing content.<\/li>\n\n\n<li><strong>Navigation patterns and exit points. <\/strong>See how visitors navigate your site and where they leave, helping you improve page structure, content flow, and user experience.<\/li>\n\n\n<li><strong>SEO strategy validation. <\/strong>Monitor organic traffic and landing page performance to evaluate whether your SEO efforts are increasing visibility and engagement.<\/li>\n\n\n<li><strong>Impact measurement. <\/strong>Track changes in traffic and user behavior after content updates, technical fixes, or SEO improvements to confirm what works.<\/li>\n\n\n<li><strong>Data-driven insights. <\/strong>Use real user data to improve content relevance, site usability, and long-term traffic growth instead of relying on assumptions.<\/li>\n\n<\/ul><h2 class=\"wp-block-heading\" id=\"h-next-steps-drive-traffic-to-your-website\">Next steps: Drive traffic to your website<\/h2><p>After connecting Google Analytics to WordPress, you&rsquo;ll get to see more detailed data like where visitors come from, which pages attract organic traffic, and how users interact with your content.<\/p><p>These insights help you understand what already performs well in search and what needs improvement. And instead of guessing, you&rsquo;re using real user behavior to guide your optimization efforts.<\/p><p>For example, you can identify pages with strong impressions but low engagement, spot content that generates organic traffic, and further optimize it. You can also pinpoint pages with high bounce rates that may require better structure or clearer alignment with search intent.<\/p><p>To consistently increase traffic, combine Google Analytics insights with proven <a href=\"\/my\/tutorials\/wordpress-seo-tips\">WordPress SEO best practices<\/a>, including enhancing content quality, implementing internal linking, optimizing site speed, and refining on-page optimization.<\/p><p>As you apply these SEO improvements, use Google Analytics to monitor the changes in organic traffic, engagement, and conversions. This ongoing measurement helps you validate what works, refine your strategy, and scale the SEO efforts that drive results.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Google Analytics is a web analytics service that tracks and reports website traffic, providing deep insights into how visitors interact with your content. By connecting Google Analytics to your WordPress site, you can identify your most popular pages, understand where your traffic comes from, and track conversion goals like form submissions or product purchases. These [&#8230;]<\/p>\n<p><a class=\"btn btn-secondary understrap-read-more-link\" href=\"\/my\/tutorials\/how-to-add-google-analytics-to-wordpress\">Read More&#8230;<\/a><\/p>\n","protected":false},"author":257,"featured_media":127786,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_title":"How to add Google Analytics to WordPress: A beginner's guide","rank_math_description":"Learn how to add Google Analytics to WordPress using three methods: plugins, Tag Manager, or manual code. Start growing your site with data-driven insights.","rank_math_focus_keyword":"add google analytics to wordpress","footnotes":""},"categories":[22632],"tags":[],"class_list":["post-610","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-wordpress"],"hreflangs":[{"locale":"en-US","link":"https:\/\/www.hostinger.com\/tutorials\/how-to-add-google-analytics-to-wordpress","default":0},{"locale":"fr-FR","link":"https:\/\/www.hostinger.com\/fr\/tutoriels\/google-analytics-wordpress","default":0},{"locale":"id-ID","link":"https:\/\/www.hostinger.com\/id\/tutorial\/cara-memasang-google-analytics-di-wordpress","default":0},{"locale":"nl-NL","link":"https:\/\/www.hostinger.com\/nl\/tutorials\/hoe-google-analytics-toevoegen-aan-wordpress","default":0},{"locale":"en-UK","link":"https:\/\/www.hostinger.com\/uk\/tutorials\/how-to-add-google-analytics-to-wordpress","default":0},{"locale":"en-MY","link":"https:\/\/www.hostinger.com\/my\/tutorials\/how-to-add-google-analytics-to-wordpress","default":0},{"locale":"en-PH","link":"https:\/\/www.hostinger.com\/ph\/tutorials\/how-to-add-google-analytics-to-wordpress","default":0},{"locale":"en-IN","link":"https:\/\/www.hostinger.com\/in\/tutorials\/how-to-add-google-analytics-to-wordpress","default":0},{"locale":"en-CA","link":"https:\/\/www.hostinger.com\/ca\/tutorials\/how-to-add-google-analytics-to-wordpress","default":0},{"locale":"en-AU","link":"https:\/\/www.hostinger.com\/au\/tutorials\/how-to-add-google-analytics-to-wordpress","default":0},{"locale":"en-NG","link":"https:\/\/www.hostinger.com\/ng\/tutorials\/how-to-add-google-analytics-to-wordpress","default":0}],"_links":{"self":[{"href":"https:\/\/www.hostinger.com\/my\/tutorials\/wp-json\/wp\/v2\/posts\/610","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hostinger.com\/my\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hostinger.com\/my\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/my\/tutorials\/wp-json\/wp\/v2\/users\/257"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/my\/tutorials\/wp-json\/wp\/v2\/comments?post=610"}],"version-history":[{"count":57,"href":"https:\/\/www.hostinger.com\/my\/tutorials\/wp-json\/wp\/v2\/posts\/610\/revisions"}],"predecessor-version":[{"id":127785,"href":"https:\/\/www.hostinger.com\/my\/tutorials\/wp-json\/wp\/v2\/posts\/610\/revisions\/127785"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/my\/tutorials\/wp-json\/wp\/v2\/media\/127786"}],"wp:attachment":[{"href":"https:\/\/www.hostinger.com\/my\/tutorials\/wp-json\/wp\/v2\/media?parent=610"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hostinger.com\/my\/tutorials\/wp-json\/wp\/v2\/categories?post=610"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hostinger.com\/my\/tutorials\/wp-json\/wp\/v2\/tags?post=610"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}