Google Analytics 4 (GA4) Tutorials

repository·main·Indexed 41 days ago

https://github.com/googleanalytics/ga4-tutorials

A collection of code examples and demo websites used in the Google Analytics Tutorial Series on YouTube. This resource provides implementation guides for GA4, including initial setup, events, custom events, and consent mode, utilizing Deno for local server hosting.

Tokens
1.5K
Snippets
13
Records
14
Agent score
52%

What's inside GA4 Tutorials

  1. Run the GA Events tutorial local server

    main

    This tutorial uses Deno to run a local web server. To start the server, navigate to the /tutorials/2-events directory and execute the deno run command with the necessary permissions for network and file system access.

    By default, the server listens on port 80. After running the command, access the site at http://localhost.

    deno run --allow-net --allow-read ./src/index.ts
  2. Run the current version of the website

    main

    To run the demo website, you must have Deno installed. The project uses Deno tasks to manage the local web server.

    To start the server on the default port (80), run:

    deno task start

    If port 80 is unavailable, you can specify a different port using the --port argument:

    deno task start --port 8000

    After starting the server, access the site at http://localhost or http://localhost:8000 depending on the port used.

  3. Run the initial setup tutorial website

    main

    The tutorial website is a simple Deno-based file server. You can run it using the Deno CLI. By default, it listens on port 80, but you can specify a custom port using the --port flag.

    When running, the server serves static files from the ./public directory. If you access the root path (/), it automatically serves index.html.

    deno run --allow-net --allow-read tutorials/1-initial-setup/src/index.ts --port 8080
  4. Run the Consent Mode tutorial website

    main

    The tutorial website is a Deno-based server that uses the Eta templating engine to serve .eta files and static assets from a public directory.

    To run the server, use the Deno CLI. You can optionally specify a custom port using the --port flag. By default, the server runs on port 80.

    Default behavior:

    • Requests for / are mapped to index.eta.
    • Requests for paths without an extension are mapped to {path}.eta.
    • .eta files are rendered as text/html.
    • Other files are served as static assets from the public directory.
    deno run --allow-net --allow-read tutorials/4-consent-mode/src/index.ts --port 8080