Skip to content

Access Analytics (GA4)

KUKAN can track page views, file downloads, and search keywords using Google Analytics 4. This feature is designed for internet-facing deployments. In closed networks (LGWAN, air-gapped), leave the configuration unset and analytics will be fully disabled.

What is tracked How
Page views Automatic (gtag.js)
File downloads Custom event on download button click
Site search keywords Automatic (Enhanced Measurement detects ?q= parameter)

Analytics data can be viewed in the GA4 console. With GA4 Data API configured, you can also view analytics on the KUKAN admin Access Analytics page.

  1. Go to Google Analytics and sign in
  2. Click Admin (gear icon) in the bottom-left
  3. Click Create > Property
  4. Enter a property name (e.g. “My City Open Data Catalog”)
  5. Select your time zone and currency
  6. Choose Web as the platform
  7. Enter your site URL and a stream name
  8. After creation, copy the Measurement ID (format: G-XXXXXXXXXX)

Enhanced Measurement is usually enabled by default. Verify:

  1. In GA4 Admin, go to Data Streams and click your web stream
  2. Under Enhanced measurement, ensure these are toggled on:
    • Page views (always on)
    • Site search — detects the q parameter in URLs like /dataset?q=...
    • File downloads — optional (KUKAN also sends a custom event)

Set the Measurement ID in your brand configuration file:

// apps/web/brands/default/brand-config.ts (or brands/<name>/ for other brands)
export const brandConfig: BrandConfig = {
// ...other settings
gaMeasurementId: 'G-XXXXXXXXXX', // your Measurement ID
}

Redeploy after saving the file. When gaMeasurementId is set, the gtag.js script is automatically loaded on every page.

When gaMeasurementId is null (the default), no external scripts are loaded and no data is sent to Google.

The Measurement ID is part of the brand, so to use a different Measurement ID per site in a multi-site setup, give each site its own brand (see Multiple Brands).

Step 4: Register Custom Dimensions (Optional)

Section titled “Step 4: Register Custom Dimensions (Optional)”

KUKAN sends a file_download custom event with additional parameters. To use these in GA4 reports:

  1. In GA4 Admin, go to Custom definitions > Custom dimensions
  2. Create the following event-scoped dimensions:
Dimension name Event parameter Scope
Dataset Name dataset_name Event
Resource ID resource_id Event
File Format format Event

This step is optional but recommended for detailed download analysis.

The KUKAN admin Access Analytics page shows dataset view counts, resource view counts, download counts, and search keyword rankings fetched from the GA4 Data API. This requires a Google Cloud service account:

  1. Create a Service Account in a GCP project (new or existing)
  2. Enable the Google Analytics Data API in the GCP project
  3. In GA4 Admin > Property Access Management, add the service account email with Viewer role
  4. Set the following environment variables in your deployment:
Variable Value
GA4_PROPERTY_ID Your GA4 property ID (numeric, found in Admin > Property Settings)
GA4_CLIENT_EMAIL Service account email address
GA4_PRIVATE_KEY Service account private key (PEM format, from the JSON key’s private_key field)

On AWS, set enableGa4DataApi: true on the environment in environments.ts (on the site entry in a multi-site environment), deploy, and store the values in the three Secrets Manager secrets it creates.

After deploying with a Measurement ID configured:

  1. Open your site in a browser
  2. In GA4, go to Reports > Realtime
  3. You should see your visit appear within a few seconds
  4. Click a download button and verify a file_download event appears in Realtime
  5. Perform a search and verify a view_search_results event appears

Does this work in closed networks (LGWAN)?

Section titled “Does this work in closed networks (LGWAN)?”

No. GA4 requires internet access to send data to Google servers. In closed networks, leave gaMeasurementId as null (default). No external scripts will be loaded.

KUKAN uses gtag.js directly for simplicity and performance. GTM is not needed since the only tracking tag is GA4. If you have a specific need for GTM, leave gaMeasurementId as null and place the GTM snippet in a Header (or other) override component (see Appearance Customization).

GA4 only tracks browser-based access. API calls made directly (e.g. via curl or programmatic clients) are not captured. On AWS, CloudFront access logs are stored per site, API calls included, and can be queried with Athena (see Access logs (CloudFront)).

Real-time data appears within seconds in the GA4 Realtime report. Standard reports may take 24-48 hours to fully process.