Skip to content

Web Analytics โ€” Tracking & Optimization Guide

DodaTech Updated 2026-06-21 8 min read

In this tutorial, you'll learn about Web Analytics. We cover key concepts, practical examples, and best practices.

Web analytics is the collection, measurement, and analysis of website data to understand user behaviour, improve performance, and drive business decisions.

What You'll Learn

  • Core web analytics metrics and what they mean
  • How to set up tracking with Google Analytics and privacy-friendly alternatives
  • How to use analytics data to optimize your site

Why It Matters

Without analytics, you're flying blind. You don't know where your traffic comes from, what users do on your site, or why they leave. Google Analytics is used by 28 million websites, but privacy regulations like GDPR are shifting the industry toward cookieless, privacy-first analytics.

Real-world use: The Doda Browser team uses analytics to track which features users engage with most. Durga Antivirus Pro analytics detect unusual traffic patterns that might indicate a DDoS attack or a bot scraping threat data.

Key Web Analytics Metrics

flowchart LR
  A[Users & Sessions] --> B[Bounce Rate]
  B --> C[Page Views & PV/Session]
  C --> D[Avg Session Duration]
  D --> E[Conversion Rate]
  E --> F[Goal Completions]
  style A fill:#f90,color:#fff
  style C fill:#4af,color:#fff
  style E fill:#4a4,color:#fff
  style F fill:#f4a,color:#fff

Metrics Explained

Metric Definition Good Range
Users Unique visitors (deduplicated) Depends on traffic goals
Sessions Visits (one user can have multiple) Track trend, not absolute
Bounce Rate Single-page sessions with no interaction 26โ€“40% excellent, 41โ€“55% average
Pages/Session Average pages viewed per visit 2โ€“3 is healthy for content sites
Avg Session Duration Time spent on site 2โ€“3 minutes for blogs, longer for SaaS
Conversion Rate Goal completions รท sessions 2โ€“5% e-commerce, 10โ€“30% lead gen

Setting Up Analytics Tracking

Example 1: Google Analytics 4 (GA4) Basic Setup

<!-- GA4 gtag.js snippet โ€” place in <head> -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){ dataLayer.push(arguments); }
  gtag('js', new Date());
  gtag('config', 'G-XXXXXXXXXX');
</script>

Expected output: Within 24 hours, GA4 shows real-time users, traffic sources, page views, and event data in your Analytics dashboard. You can verify the tracking is working by opening your site, then checking GA4's "Realtime" report โ€” you should see yourself as an active user.

Example 2: Tracking Custom Events with JavaScript

// Track button clicks and form submissions
document.addEventListener('DOMContentLoaded', () => {
  
  // Track downloads
  document.querySelectorAll('.download-btn').forEach(btn => {
    btn.addEventListener('click', (e) => {
      gtag('event', 'file_download', {
        'file_name': e.target.dataset.file,
        'file_type': e.target.dataset.type,
        'file_size': e.target.dataset.size
      });
      console.log(`Tracked download: ${e.target.dataset.file}`);
    });
  });

  // Track form abandonment (user leaves without submitting)
  const form = document.querySelector('#signup-form');
  let formStarted = false;
  
  form?.addEventListener('focusin', () => { formStarted = true; });
  
  document.addEventListener('beforeunload', () => {
    if (formStarted && !form.classList.contains('submitted')) {
      gtag('event', 'form_abandonment', {
        'form_id': form.id,
        'page_path': window.location.pathname
      });
    }
  });
});

Expected output: When users click download buttons or abandon forms, the events appear in GA4 under "Events" โ†’ "All events". You'll see file_download and form_abandonment events with their respective parameters, enabling conversion funnel analysis.

Example 3: Privacy-First Analytics with Plausible

<!-- Plausible Analytics โ€” privacy-friendly, no cookies -->
<script defer data-domain="example.com" src="https://plausible.io/js/script.js"></script>
// Track custom goals with Plausible (Goal: Newsletter signup)
function trackNewsletterSignup(email) {
  plausible('NewsletterSignup', {
    props: {
      method: 'footer_form',
      hashedEmail: simpleHash(email)  // Hash emails for privacy
    }
  });
}

function simpleHash(str) {
  let hash = 0;
  for (let i = 0; i < str.length; i++) {
    const char = str.charCodeAt(i);
    hash = ((hash << 5) - hash) + char;
    hash |= 0; // Convert to 32-bit integer
  }
  return Math.abs(hash).toString(16);
}

// Usage
trackNewsletterSignup('user@example.com');
// Output in Plausible dashboard: NewsletterSignup goal tracked

Expected output: Plausible shows page views, referrers, bounce rate, and visit duration without using cookies. Your custom goal NewsletterSignup appears in the Goals dashboard with the prop method: footer_form. No cookie consent banner needed.

Analytics Platforms Comparison

Feature Google Analytics 4 Plausible Matomo Fathom
Pricing Free From $19/mo Free self-hosted From $14/mo
Cookies Uses cookies No cookies Configurable No cookies
GDPR compliant Requires consent banner Yes, by design With config Yes
Custom events Yes Via goals Yes Limited
Data ownership Google Cloud hosted Self-hosted Cloud hosted
Page views tracked Sampled at high traffic Unsamped Unsamped Unsamped

Using Analytics to Optimize

Finding Likely Cause Fix
High bounce rate on landing pages Slow load time, poor content match Improve page speed, align content with search intent
Low pages/session No internal links, thin content Add SEO-optimized internal links, expand content
Drop-off on checkout page Form too long, unexpected costs Reduce form fields, show total price early
High traffic but low conversions Mismatched audience or weak CTA Review ad targeting, A/B test call-to-action buttons
Traffic spike with 0 conversions Bot traffic, DDoS Investigate source, add CAPTCHA, check server logs

Common Analytics Errors

  1. Tracking code placed in wrong location โ€” GA4 snippet must go in the <head>, not the footer. Some page builders delay script loading. Verify with Google Tag Assistant or check window.dataLayer.

  2. Not filtering internal traffic โ€” Your own visits skew analytics data. Create a filter in GA4 to exclude your office IP range. In Plausible, enable "Exclude admin users."

  3. Sampled data in GA4 โ€” Free GA4 uses data sampling when querying large datasets. For accurate numbers, keep date ranges under 14 days or upgrade to GA4 360.

  4. Cross-domain tracking not configured โ€” When users navigate between your main site and checkout subdomain, they appear as separate sessions. Set up cross-domain measurement in GA4 admin settings.

  5. UTM parameters incorrectly formatted โ€” Wrong case or misspelled params (utm_source not source) means campaigns don't appear in reports. Use a UTM builder tool. Standard format: ?utm_source=twitter&utm_medium=social&utm_campaign=spring_sale.

  6. Ad blockers blocking analytics โ€” Up to 30% of users use ad blockers that block GA4. Implement server-side tracking or use privacy-first tools that survive ad blockers.

Frequently Asked Questions

Is Google Analytics free to use?

Yes, Google Analytics 4 (GA4) is free for most websites. The free tier supports up to 10 million hits per month. GA4 360 (paid) offers higher limits, unsampled reports, and SLA guarantees for enterprise customers.

Do I need a cookie consent banner when using analytics?

It depends on your privacy jurisdiction. Under GDPR (Europe) and CCPA (California), you need a consent banner for Google Analytics because it sets cookies. Privacy-first tools like Plausible, Fathom, and Umami don't use cookies and don't require consent banners in most jurisdictions.

What is the difference between page views and unique page views?

Page views count every time a page is loaded, including reloads. Unique page views count the number of sessions during which a page was viewed at least once. If a user refreshes a page 5 times, that's 5 page views but 1 unique page view.

Practice Questions

  1. What is the difference between a user and a session in analytics? A user is a unique visitor identified by a cookie or device ID. A session is a single visit that can include multiple page views. One user can have many sessions over time.

  2. Why is bounce rate an important metric? A high bounce rate (over 70%) suggests users don't find what they're looking for, the page loads too slowly, or the content quality doesn't match the search intent.

  3. What does UTM tracking do? UTM parameters added to URLs track the source, medium, campaign, term, and content of traffic in analytics reports โ€” letting you know which marketing channels drive the most conversions.

  4. How does privacy-first analytics differ from traditional analytics? Privacy-first tools like Plausible and Fathom don't use cookies, don't track individual users across sessions, and don't require consent banners. They still provide aggregate metrics like page views, bounce rate, and referrers.

  5. What is a conversion funnel? A conversion funnel tracks the steps users take before completing a goal (e.g., landing page โ†’ product page โ†’ cart โ†’ checkout โ†’ purchase). Analyzing drop-off points helps optimize the flow.

Challenge

Set up GA4 on a test site, configure three custom events (button click, form submission, scroll depth), create a conversion funnel report, and analyze where users drop off. Then build a dashboard in Looker Studio (formerly Google Data Studio) showing traffic sources, top pages, and conversion rates over the last 30 days.

Real-World Task

The Durga Antivirus Pro download page has 50,000 monthly visitors but only a 2% download rate. Set up event tracking to measure clicks on the "Download Now" button, scroll depth on the features section, and form abandonment on the email signup. Analyse the data to identify the bottleneck and propose three changes to improve the conversion rate to 5%.


Related: Google Analytics Guide | Related: SEO Guide | Related: PWA Guide

Built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro