...
Blogg
How to Set Up Google Analytics on Your Website – Step-by-Step GuideHow to Set Up Google Analytics on Your Website – Step-by-Step Guide">

How to Set Up Google Analytics on Your Website – Step-by-Step Guide

Alexandra Blake, Key-g.com
av 
Alexandra Blake, Key-g.com
13 minutes read
Blogg
december 05, 2025

Recommendation: Set up a GA4 property and install the global site tag (gtag.js) on every page to begin collecting data. Use the ready, guided flow and a single window to copy and paste the code.

From the Google Analytics account, use the dropdown to select Web as the data stream type. Choose a distinct, descriptive name for the property and confirm the measurement parameter is GA4. This helps organize data by dimensions such as page_title, page_location, and device category. A clean setup makes analysis smoother.

You can install the tag manually in your site code or use Google Tag Manager for automated deployment. If you go manual, insert the snippet directly into the head tag on every page. In GTM, create a new GA4 configuration tag and publish. If you’re tempted to change the ID later, avoid changing the measurement ID.

Double-check the measurement ID in your tag against the one shown in the GA4 interface. Watch for typos in the ID and in your property name; a small typo can stop data from appearing. In the setup window, verify that data streams are active and that you can see a recent sign of activity in Real Time. If something looks off, stop and re-check.

Configure basic events and parameters to capture actions such as page_view, scroll, and clicks. Use parameters like event_name and page_location to capture context. In the Measurements section, enable enhanced measurement to collect standard events automatically without adding code. Be sure you set up these events to reflect your goals and audience.

Verify data collection after installation by visiting a page and checking the Real-Time report. If you see data, extend monitoring to a full day window to confirm trends and adjust your target goals. If you manage multiple sites, reuse the same GA4 property with distinct data streams so you can compare performance without creating separate accounts.

If you need help, contact the team or a trusted analytics partner. The system will show key dimensions such as city, device, and source, helping you optimize campaigns and content.

Next steps: set up conversions and define your targets, then review the admin settings and double-check that data is flowing to GA4 before making changes. Monitor the data in a dedicated window and adjust as needed to keep insights fresh.

Method 1: Set Up GA4 With Google Tag Manager

Install GA4 via Google Tag Manager to migrate across your digital presence, quickly centralize tags, and support templates used in your general site architecture.

Make sure GTM is installed on every page. If not, insert the container snippet into your general site template so it loads across devices and helps cover all pages.

In GTM, create a GA4 Configuration tag using the built-in templates. Enter your Measurement ID and enable the default page_view to start tracking visits across sections and devices.

Set triggers: All Pages for the configuration tag. Add GA4 Event tags for key interactions, such as clicks on “site-nav__linkmain” links, form submissions, and video plays. Use precise triggers so data were sent to GA4 with clean parameters.

Keep a single source of truth by mapping events to a spreadsheet eller file and align them with four common cases: page_view, click, form_submit, and video_start. This helps any teammate explore the events and keep their changes coordinated across sections.

Testing: enable GTM Preview to verify that tags fire before publishing. Check the Real-time reports in GA4 after publishing to confirm tracks appear in your data stream. If issues occur, review the dataLayer and the general settings to ensure the events were sent with the expected parameters.

Migration tip: if you migrate from another analytics tool, export key events from that system, map them to GA4 events in your templates, and document the mapping in a post or guide. Store templates and their mappings in a shared folder so their owners stay aware of changes.

Ongoing: confirm coverage across devices, and use the four sections of the GTM workspace–Tags, Triggers, Variables, and Data Layer–to keep changes organized and avoid conflicts on busy sites. After each update, close the editor and re-publish when ready.

Check Prerequisites: Google Account, GTM Container, and GA4 Property

Create a Google account if you don’t have one, then sign in and create a GTM container for your site (Web) and a GA4 property in that order. This trio–Google Account, GTM container, GA4 property–provides a different foundation for capturing signals and controlling tags without touching site code. This setup works across different sites, including woocommerce stores, and lays a solid base for product-related tracking.

In GTM, create the container with a primary name and Web type, then install the container snippet on your site. This allows tags to fire immediately. Use a common approach: configure a Page View tag, a menu_click trigger, and a GA4 Configuration tag. For woocommerce sites, set up a product_view and add_to_cart events to be captured.

In GA4, create a data stream for your website and copy the measurement_id to GTM’s GA4 Configuration tag. This setup ensures events are captured and can be extended with custom events later. Implementing a macro for event parameters like label and product helps maintain consistency across ones and this moment of interaction.

Test in GTM Preview mode to ensure events fire and are captured correctly in GA4, then use DebugView to confirm. If debugging reveals gaps, check the install placement and permissions in the GTM account; come through debugging steps and prepare for coming updates in tagging standards. Keep a structured summary of what you validated.

Set data retention policies and address privacy requirements. In GA4 and GTM, create a few labels to distinguish common events (page_view, click, purchase) and keep the length of reports manageable. This helps long-term retention and smoother reporting.

Next, customize additional events for different product pages and checkout steps, especially for woocommerce stores. Use the install step in GTM to add a custom event like macro_checkout_complete or woocommerce_order_completed to refine your data. Keep a concise summary of what you implemented, and review retention settings and conversion paths to improve your macro-based reporting approach. More tips come from practical debugging and testing, so you can come back with improvements at the next moment.

Create GA4 Property and Data Stream

Create GA4 Property and Data Stream

Create a GA4 property, then add a Web data stream to start getting insights right away. In Google Analytics, go to Admin, click Create Property, and fill in the general details: property name, time zone, and currency. After you confirm, GA4 establishes the main measurement framework and you can adjust the general settings to fit your needs. This step sets the scope for data collection and starts the trail for future reporting.

Set up a Web data stream: choose Web, enter your site URL, stream name, and enable enhanced measurement to capture page views, scrolls, clicks, and more. This creates a measurement ID that links the site to GA4, enabling built-in controls for data collection. If you also run a mobile app, add a separate app stream to keep app data separate but connected in a single property.

Install the snippet or use Tag Manager: GA4 offers a built-in snippet and GTM integrations. Paste the snippet into your site header, or deploy via Tag Manager. The snippet looks like: gtag('config', 'G-XXXXXXXXXX'); Replace the placeholder with your actual measurement ID. After this is done, visit your site to verify that data is arriving in Real-time reports.

Verify data flow and create audience segments: use Real-time reports to confirm events are firing and the data is getting into your property. Use variables to capture specific event parameters and tailor insights for reporting. Build audience segments by behavior, device, or location to support targeted testing and personalized messaging. The scope of your data stream defines which reports reflect the events you track.

Integrations and ongoing optimization: connect your GA4 property with Google Ads, Search Console, and other platforms to broaden insights. For clicks, apply custom classes and track them with the link_classes convention to enrich engagement data. This supports many recommended dashboards and easy sharing with clients. After you finish, run through a quick audit and tell stakeholders what changed, using the main reports to show performance across channels and devices.

Install Google Tag Manager on Your Website

Install the GTM container and place the code blocks as described in your documentation. The two-part snippet loads in the window and enables measures like clicks and conversions across sections of your site. Copy the head script and the noscript iframe: insert the head script immediately after the opening <head> tag, and place the noscript iframe in the body right after the opening <body> tag to keep performance stable on devices.

Configure tags, triggers, and variables in GTM. This provides a centralized approach for linking your site with measurement tools. The default configuration covers GA4 and Google Ads; adding events for sales milestones, form submissions, and product interactions is straightforward. Use the UI to add an item, choose a tag type, select a trigger, and save. You can toggle between Test and Live to compare outcomes and ensure you capture the right data across devices.

To verify setup and catch issues early, use Preview mode (debugging). The Preview panel shows which tags fire and when. Use the search field to locate specific functions, and check the window.dataLayer entries as you navigate pages. The arrow in the panel lets you expand details for each tag. Unlike manual tagging, this method keeps your documentation tidy and reduces duplication for managers working on campaigns.

Steg Action Notes
1 Create a Google Tag Manager account and container for your website Use a single container per domain; default naming helps cross-team sharing
2 Install the GTM snippet Place the head script in the <head> and the noscript iframe in the <body> after opening tag
3 Add a GA4 tag and necessary triggers Link to GA4 data streams; set event names like view_item, add_to_cart
4 Preview and debug Click Preview, navigate pages, observe firing and dataLayer, search for functions
5 Publish and monitor Release changes, monitor real-time and conversions, revisit configuration after changes

Configure GA4 Configuration Tag in GTM

Create a GA4 Configuration tag in GTM using your GA4 Measurement ID and enable it to fire on All Pages. This creates a solid data baseline for web and apps, ensuring page_view and session signals are captured consistently.

  1. Tag configuration: In GTM, click Tag > New > Tag Configuration > Google Analytics: GA4 Configuration. Enter Measurement ID (G-XXXXXXXXXX) and confirm that the GA4 property name matches your GA4 property. This keeps data aligned across products and apps.

  2. Fields to Set: Leave core fields default. If you need to pass extra context, add fields like page_title and page_path. For file_download tracking, you can add a parameter named file_download with the relevant value, but this is optional for a baseline setup.

  3. Send Page View: Enable Send Page View on load to ensure the initial page signal is sent automatically with every page load. This plus reduces the need for separate events to capture first-page impressions.

  4. Trigger: Set the tag to fire on All Pages. For sites using dynamic routing, consider a small additional trigger for route changes to catch single-page updates.

  5. Control duplicates: If you replaced an older GA tag, dont leave the old one enabled. Remove duplicates at once to avoid skewed metrics and double counting.

  6. Naming and icon: Name the tag clearly, for example GA4 Configuration – Main, and rely on the icon to identify it quickly in the list. This helps quick search and easy navigation for joining teammates who work on analytics.

  7. Testing: Use Preview mode and check GA4 DebugView to confirm a page_view fires on several pages. If any issue appears, double-check the Measurement ID and the data stream, then correct and re-test.

Summary: A well-configured GA4 Configuration tag on All Pages provides the foundation for accurate metrics across sites and apps. After this, you can add GA4 Event tags for specific actions, like interactive product clicks or file downloads, to enrich your data without touching the core configuration. Treat this tag as a baseline, then expand with additional event tracking as needed. This approach keeps things easy and scalable, with a clear path to future enhancements like search events or additional features.

Test and Validate Tracking with DebugView and Real-Time Reports

Test and Validate Tracking with DebugView and Real-Time Reports

Enable DebugView and Real-Time reports to verify tracking within a second and avoid gaps. This approach keeps your measurement visible for your management and stakeholders.

First, confirm the GA4 tag is installed on all pages and the measurement ID is correct. Then enable debug mode by adding this snippet: gtag(‘config’, ‘G-XXXXXXXXXX’, { ‘debug_mode’: true }); or use the GA Debugger extension. This step makes the incoming hits easy to inspect.

Open DebugView in your GA4 property and perform actions such as go to a page, click a CTA, or submit a form. DebugView lists hits with a timestamp and shows fields for event_name and event_params; you’ll see an icon next to each row that indicates the hit type.

Switch to Real-Time reports: Real-time > Live reports; watch the same events appear, verify counts, and check timing against your expected flow. Validate key parameters like page_location, page_title, and any custom dimensions to ensure the field values match definitions.

Create a definitions list mapping event names to your business actions, then compare against reports to confirm tracking matches your plan. Note any item where a value is none and adjust the event mapping or parameter names accordingly.

Troubleshoot: if an event doesnt appear, verify the tag fires on the action, review any blockers that may hide the hit, and confirm the measurement ID is installed on the page. Keep privacy prompts and consent settings in mind as they can pause data collection.

Use this method to maintain global visibility across properties and advertising dashboards; when a change lands, you’ll see its impact in real time, without guesswork. Thus you gain confidence that your setup provides reliable data for decisions.

Quick tips: keep validation focused and actionable, run the second pass after updates, and maintain a short list of field values you expect so you can share findings with the team, even if havenh t changes occur in the moment. Remember to protect user privacy and avoid storing personal data in event fields.