E-commerce

How to install Google Analytics on WordPress to track traffic?

How to install Google Analytics on WordPress to track traffic?

October 31, 2026

Wondering how to install Google Analytics on your WordPress site to track traffic?

In just a few minutes, you can collect reliable data on your visitors and drive your marketing decisions.

This operation is simple, but you must avoid common pitfalls such as incorrect code placement or using an inadequate plugin.

So how do you install Google Analytics on WordPress? Here is the plan:

  • What is the tracking code to retrieve from Google Analytics?

  • How to insert the code into the WordPress header or footer?

  • Which WordPress plugin simplifies Google Analytics integration?

  • How to verify that tracking is working correctly?

  • How does Qstomy optimize e-commerce performance tracking?

Let's go.

By following these steps, you will have full visibility into your visitors' behavior, allowing you to adjust your strategy and increase conversions.

Summary

What is the tracking code to retrieve from Google Analytics?

Log in to your Google Analytics account or create one if you don't have one yet. In the dashboard, click Admin, choose the property corresponding to your site, then select Tracking Info → Tracking Code. You will access a JavaScript snippet called the 'tracking code', typically in the format gtag(’config’, ’UA‑XXXXX‑Y’);. Copy it in its entirety, as this tag will identify your site every time a visitor loads a page.

Note that Google now offers GA4, whose code has the format gtag(’js’, new Date()); gtag(’config’, ’G‑XXXXXXXXXX’);. The principle remains the same: you must place this snippet in your WordPress theme.

Once the snippet is inserted, you can verify its presence via the browser inspection tool or by viewing the source code; this ensures tracking starts from the first visit.

Convert over 2,000 customers on average per month with Qstomy.

The world’s 1st Shopify AI dedicated to customer conversion

Empowering 200+ e-commerce merchants

How to insert the code into the WordPress header or footer?

From your WordPress site administration (self-hosted), go to Apparence → Theme Editor. Open the file header.php if you want the script to run at the very beginning of loading, or footer.php if you prefer it to load at the end. In the chosen file, locate the </head> (header) ou </body> (footer) tag and paste the tracking code just before it. Save the changes.

Placing the code in the header ensures every visit is counted, even if the rest of the page does not load completely. Placing it in the footer may slightly improve perceived load time, but carries the risk of losing hits if loading fails. Choose the method that best suits your performance strategy.

To preserve your changes during theme updates, create a child theme and add the code in the header.php file of the child theme; this prevents the snippet from being overwritten.

Which WordPress plugin simplifies Google Analytics integration?

If you do not want to touch the code, several reliable plugins exist. The most popular is Google Analytics for WordPress (MonsterInsights), which guides you step-by-step, automatically creates the snippet, and offers advanced options like event tracking and reporting in the WordPress dashboard.

For WooCommerce stores, the plugin WooCommerce Google Analytics Integration adds tracking for sales, cart, and conversions without additional configuration. Install the plugin via the Extensionsmenu, activate it, then enter your tracking ID (UA-XXXXX-Y or G-XXXXXXXXXX) in the settings. The plugin then handles injecting the code in the right place and transmitting e-commerce data to GA.

A native alternative to Google is the Site Kit by Google plugin, which offers seamless integration, reports in the WordPress dashboard, and the ability to activate other Google services like Search Console.

How to verify that tracking is working correctly?

After adding the code, open your site in a new tab and browse a few pages (home, product, cart). Return to Google Analytics and click on Real-time → Vue d’ensemble. You should see your visit appear immediately, along with the page visited.

If no data appears, inspect the page source (CTRL+U) to verify the snippet is present. Ensure there are no conflicts with other JavaScript scripts. You can also install the extension Google Tag Assistant which detects setup errors and tells you how to fix them.

The Google Analytics Debugger extension, available on Chrome, shows every hit sent to GA and flags any configuration errors, speeding up the setup process.

How to configure goals and e‑commerce tracking in GA?

In Google Analytics, go to Admin → Objectifs and create a new goal named 'Purchase'. Choose the 'Destination' type and enter the URL of your thank‑you page (e.g., /merci). This way, every conversion will be counted as soon as the customer reaches that page.

Then enable e‑commerce tracking by going to E‑commerce Settings and checking 'Enable e‑commerce tracking'. If you use the WooCommerce Google Analytics Integration plugin, transaction details (value, SKU, payment method) will be automatically sent to GA, allowing you to analyze revenue by product, conversion rate, and average order value.

Also consider setting up the conversion funnel to visualize the steps where users drop off, as well as enhanced e‑commerce tracking to retrieve product information on detail pages.

How to leverage advanced segments for actionable data?

Segments allow you to isolate specific visitor groups to better understand their behaviors. In GA, click on + Add Segment and choose from templates (e.g., 'Organic Traffic', 'Paid Campaigns', 'Mobile Users') or create a custom segment by combining multiple criteria (source, device, new session, etc.).

For example, compare the conversion rate of visitors from Google Ads with those from organic search. You might find that organic visitors have a higher average order value, which will guide your advertising investments. Insights gained from segments are directly actionable to optimize your campaigns and product experience.

Cohort analysis allows you to track the behavior of a user group over multiple periods, revealing the impact of site changes on long‑term retention.

How to combine GA data with other sources for a complete view?

Export your reports from Google Analytics in CSV format or connect them directly to your CRM or Business Intelligence tool. You can also create custom dashboards in Google Data Studio to cross‑reference GA metrics with data from your SEO platform, advertising campaigns, or email solution.

This 360° view helps you identify friction points, measure the return on each acquisition channel, and justify your marketing budgets to leadership.

Connectors like Supermetrics or Power My Analytics automate the daily extraction of GA reports to Google Sheets or your data warehouse, facilitating cross‑analysis.

How to measure the impact of promotions and ads using GA?

For each promotional or advertising campaign, add UTM parameters to your URLs (source, medium, campaign). GA automatically captures these tags and allows you to compare sales lift during the promotion period. Consult the report Acquisition » Campaigns » All Campaigns to view the number of sessions, conversion rate, and revenue generated by each campaign.

By combining this data with e‑commerce tracking, you can calculate the exact ROI of each advertising action, identify the most profitable promotions, and adjust your marketing calendar accordingly.

By defining a custom dimension 'promotion type', you can differentiate between sales, promo codes, and bundles, then compare their contribution to revenue.

How to track product profitability using GA?

Enable product tracking in the GA e-commerce module. The report Comportement » Produits shows the number of views, cart additions, and sales per SKU. By exporting this data, you can combine it with your purchase costs or advertising fees to calculate the gross margin for each item.

This detailed analysis helps you identify high-potential items, optimize your catalog, and adjust prices or ad placements to maximize profits.

By cross-referencing gross margin data with the Product report, you can quickly spot low-profitability items and decide whether to adjust prices or purchase volumes.

How to detect fraud and invalid conversions using GA?

Configure IP exclusion filters to ignore internal traffic (e.g., your team's IP addresses). Also, create a 'Suspicious Transactions' segment based on unusual criteria: excessive transaction volume from a single address, abnormally high conversion rates, or very short visit times before purchase.

These segments allow you to monitor fraudulent behavior in real-time and intervene quickly (IP blocking, payment rule updates) to protect your store and revenue.

Set up automatic alerts in GA that notify you via email when a spike in suspicious transactions exceeds a predefined threshold, enabling immediate action.

How does Qstomy help optimize e-commerce performance tracking?

Qstomy connects directly to your Google Analytics account and centralizes data in the Shopify dashboard. You can instantly view traffic, conversion rate, average order value, shipping costs, and customer support tracking. Our AI analyzes these metrics, suggests upsell actions, automatically adjusts your ad campaigns, and alerts you as soon as a traffic anomaly appears.

Thanks to this integration, you no longer waste time navigating between multiple tools, you gain precision, and you can focus your efforts on growing your store.

Qstomy's AI offers cross-selling recommendations based on user journeys identified in GA, increasing average order value without extra effort.

What checklist before launching Google Analytics tracking and what are common FAQs?

Pre-integration checklist

  • Create or verify your Google Analytics account (GA4 recommended).

  • Retrieve the full tracking code (gtag.js).

  • Choose the code placement: header for reliability, footer for speed.

  • If using a plugin, install and activate the appropriate plugin, then enter the tracking ID.

  • Test real-time tracking and configure e-commerce goals.

Don't forget to regularly test GDPR compliance by simulating consent refusals to ensure tracking deactivates correctly.

In short

Installing Google Analytics on WordPress takes five minutes, whether you use manual code or a plugin. Once the script is active, leverage segments, goals, and e-commerce tracking to make informed decisions and increase sales.

FAQ

  • Does the plugin slow down my site? Modern plugins (MonsterInsights, WooCommerce GA Integration) are optimized and inject the script at the end of the page, not impacting perceived load time.

  • Do I need to reinstall the code if I change my theme? Yes, insert the snippet into the new file header.php or reactivate it via your plugin.

  • Does Google Analytics comply with GDPR? Enable IP address anonymization in GA settings and inform visitors in your privacy policy.

To go further: Why use social media for e-commerce customer service? - Qstomy, Integrating CS responses into a useful e-commerce SEO strategy for customers - Qstomy, How does SEO work for e-commerce sites? - Qstomy.

Enzo

October 31, 2026

Convert over 2,000 customers on average per month with Qstomy.

The world’s 1st Shopify AI dedicated to customer conversion

Empowering 200+ e-commerce merchants

Subscribe to the newsletter and get a personalized e-book!

No-code solution, no technical knowledge required. AI trained on your e-shop and non-intrusive.

*Unsubscribe at any time. We do not send spam.

Subscribe to the newsletter and get a personalized e-book!

No-code solution, no technical knowledge required. AI trained on your e-shop and non-intrusive.

*Unsubscribe at any time. We do not send spam.