Website Analytics with GA4

GA4 is installed on your site, but when you open it you see user counts going up and down and none of the answers you actually need: where buyers come from, which pages drive sign-...

Website Analytics with GA4

GA4 is installed on your site, but when you open it you see user counts going up and down and none of the answers you actually need: where buyers come from, which pages drive sign-ups, and at which step people give up. The problem is rarely GA4 itself. Usually the important events are not tracked, internal visits are counted, and core settings such as data retention are still on their defaults.

This guide shows how to set GA4 up so it is genuinely useful for an online store, a service website, or a Laravel application, including code for tracking purchases.

How GA4 Thinks About Data

Universal Analytics was built around sessions and hits. GA4 treats every interaction as an event: viewing a page is page_view, scrolling is scroll, buying is purchase. Events carry parameters such as order value or product name. Events you mark as important are called key events (formerly conversions).

Event typeHow it is enabledExamples
AutomaticAs soon as the tag is installedfirst_visit, session_start, page_view
Enhanced measurementToggled in the web data stream settingsscroll (90% depth), outbound clicks, site search, file downloads, form interactions
RecommendedSent by you using Google's standard namessign_up, generate_lead, add_to_cart, begin_checkout, purchase
CustomSent by you with your own namesclick_chat, download_brochure

Use recommended names whenever one exists. GA4's ecommerce reports only populate when event and parameter names follow Google's schema.

Write a Tracking Plan First

The costliest GA4 mistake is adding events ad hoc and discovering a year later that names are inconsistent and nothing compares. Before touching code, make a spreadsheet with columns for business goal, event name, parameters, trigger, and owner. Use lowercase with underscores consistently, because GA4 event names are case-sensitive.

Setting It Up Properly

  1. Create a property and a web data stream and note the Measurement ID (G-XXXXXXX).
  2. Install the tag once, either through Google Tag Manager or by adding gtag.js to your main layout. Never both, or every page view is counted twice.
  3. Verify in Realtime and DebugView by browsing your site in another tab.
  4. Raise data retention from 2 to 14 months under Admin, Data collection and modification, Data retention. This limits how far back Explorations can look.
  5. Filter internal traffic by defining your office IP addresses and activating the filter.
  6. Mark two to five key events that matter to the business, such as purchase and generate_lead.
  7. Link Google Search Console so organic queries sit next to behavior data.
  8. Configure consent if you serve visitors in regions such as the EU or UK; Google's consent mode adjusts tag behavior based on the visitor's choice.

Tracking Purchases from a Laravel App

Send purchase on the thank-you page after payment is confirmed. In a Blade view, pass the order from the controller and print values safely with @json:

{{-- resources/views/checkout/thanks.blade.php --}}
@if ($order->isPaid() && ! $order->ga_tracked)
<script>
  gtag('event', 'purchase', {
    transaction_id: @json($order->code),
    value: {{ (float) $order->total }},
    currency: @json($order->currency),
    items: @json($order->items->map(fn ($i) => [
        'item_id'   => $i->sku,
        'item_name' => $i->name,
        'price'     => (float) $i->price,
        'quantity'  => $i->qty,
    ]))
  });
</script>
@php($order->update(['ga_tracked' => true]))
@endif

The ga_tracked flag stops a refresh from sending the same purchase twice. GA4 also deduplicates on transaction_id, but guarding it in your app is safer. If payments are confirmed by a webhook rather than a redirect, use the Measurement Protocol to send the event server-side so it does not depend on the buyer reaching the thank-you page.

For a chat or call button, a custom event on click is enough:

<a href="tel:+15555550123"
   onclick="gtag('event', 'click_call', { placement: 'product_page' })">
  Call us
</a>

To use a parameter like placement in reports, register it as a custom dimension under Admin, Custom definitions.

Reports Worth Reading Every Week

Traffic acquisition

Shows where sessions come from by default channel group (Organic Search, Direct, Paid Social, Referral) alongside key events per channel. Small channels with high conversion rates often deserve more attention.

Pages and screens

Lists the most viewed pages and their engagement time. A product page with plenty of views and almost no add_to_cart events needs work: photos, price clarity, or shipping information.

Funnel exploration

Build steps such as view item, add to cart, begin checkout, purchase. The chart shows where people drop. For example, a big drop between checkout and purchase often points to limited payment options or surprise fees.

Path exploration

Shows the routes visitors take before converting, such as whether they read a blog guide first.

Common Setup Mistakes

  • Double tagging through GTM and hard-coded gtag. Symptom: inflated page views per session.
  • Purchase events without currency. Revenue will not be recorded.
  • Payment provider self-referrals. Buyers returning from Stripe or PayPal show as new referral sessions; list those domains under unwanted referrals.
  • Too many key events. Marking scrolls as key events makes conversion rates meaningless.
  • No change log. Keep a short note whenever tags or events change so later spikes can be explained.

GA4 Checklist for a Business Site

  • One tag only, verified in Realtime and DebugView.
  • Data retention set to 14 months.
  • Internal traffic filter active.
  • Enhanced measurement reviewed toggle by toggle.
  • purchase or generate_lead sent with value and currency.
  • Two to five key events tied to business goals.
  • Search Console linked and consent configured where required.
  • A saved funnel exploration for your purchase or sign-up flow.

From Data to Decisions

Block 30 minutes a week and answer three questions: which channel produces the most key events, which pages get views but little action, and where the largest funnel drop sits. Pick one fix, ship it, and measure again next week. A small habit like this beats an elaborate dashboard nobody opens.

GA4 shows website behavior, while real sales numbers live in your POS or order system; the benefits of business applications for small businesses explains how those pieces fit together, and this payment gateway integration walkthrough shows where a server-side purchase event would hook into a webhook. If your store is built on a Laravel source code package, for instance one from GudangCode, the event pattern above drops straight into the existing checkout views.

Yudhi
Written by
Yudhi
Founder & Lead Developer, GudangCode

Yudhi is the founder of GudangCode and a Laravel developer who has built dozens of ready-to-use business information systems — from POS and HRIS to management apps. He writes guides and articles on GudangCode to help Indonesian developers run, understand, and deploy Laravel source code correctly.

LaravelPHPMySQLSistem Informasi Bisnis See all articles by Yudhi
Want the full source code & apps?

Sign up free to download ready-to-use business applications, information systems, and Laravel source code.

Sign Up Free & Download
Google Analytics 4 Marketing & SEO
Share this article
Back to Blog
📚 Free Learning Hub

Learn Coding for Free at DhieCoderWeb

Explore Laravel, PHP, JavaScript tutorials, source code, web development guides, and practical programming tips.

DhieCoderWeb
100+
Tutorials
Free
Learning
SEO
Tips
Visit Dhiecoderweb.com →

Get Full Access Now!

Join our membership and unlock exclusive access to all premium features. Fast, easy, and ready to use instantly.

Join Membership Now
Tim Support
Online
Isi data dulu untuk mulai chat:
Beri rating & testimoni sebelum menutup:
Live chat by gudangcode.com