Embedding Semantic Data for Richer GA4 Reporting

Semantic data layers, where product terms and web analytics intersect, give conversion and SEO teams powerful means of accessing context that’s well beyond what you can do with page views and click data.

Embedding Schema.org structured data (in JSON-LD format) on product pages and relaying it to GA4 via Google Tag Manager (GTM) makes each event “meaningful” in terms of your product taxonomy, adding a strategic layer to your data.

In practice, this means that product pageviews, cart actions or purchases can be reported not just by URL but by product name, category, brand, price, etc. – exactly the dimensions marketers and CRO teams really care about.

Embed your Schema.org JSON

Embedding Schema.org JSON-LD in the page <head> adds rich context. For example, a product page might include:


{
  "@context": "http://schema.org",
  "@type": "Product",
  "name": "Example Widget",
  "brand": { "@type": "Brand", "name": "Acme Corp" },
  "category": "Gadgets",
  "sku": "WIDGET-123",
  "offers": {
    "@type": "Offer",
    "priceCurrency": "GBP",
    "price": "49.95",
    "availability": "http://schema.org/InStock"
  }
}

This standardised JSON-LD block (placed in the HTML head) tells search engines and our analytics exactly what product is on the page. Google’s own documentation points out that adding structured product data helps listings show price, availability and ratings in search results but the same data can power internal analytics. In short, a schema.org “Product” with fields like name, category, brand, price, etc. becomes machine-readable.

Push to DataLayer

Before we can push these attributes into GA4, we need a JavaScript snippet that can read the JSON-LD and push key fields into the GTM dataLayer. This can be added as a custom HTML script in Tag Manager. For instance:


// Locate and parse the JSON-LD for the product
(function(){
  var schemaEl = document.querySelector('script[type="application/ld+json"]');
  if (schemaEl) {
    var productData = JSON.parse(schemaEl.textContent);
    window.dataLayer = window.dataLayer || [];
    window.dataLayer.push({
      'event': 'ProductPageView',
      'product_name': productData.name,
      'product_id': productData.sku || productData.id,
      'product_brand': (productData.brand||{}).name || '',
      'product_category': productData.category || '',
      'product_price': productData.offers ? productData.offers.price : null
    });
  }
})();

Creating Custom Events

Next, in Google Tag Manager one would set up a GA4 Event tag triggered on the custom event ProductPageView. The tag’s configuration can map each Data Layer variable into GA4 event parameters. For example, a GTM GA4 Event tag could be defined conceptually as:


{
  "trigger": "ProductPageView",
  "event_name": "product_view",
  "parameters": {
    "product_name": "{{DLV - product_name}}",
    "product_brand": "{{DLV - product_brand}}",
    "product_category": "{{DLV - product_category}}",
    "price": "{{DLV - product_price}}"
  }
}

When ProductPageView fires in the dataLayer, GTM sends a GA4 event product_view with parameters drawn from the dataLayer variables (e.g. product_name, product_brand, etc.). Google’s documentation confirms that GA4 Event tags allow additional parameters to capture more detail. These parameters – now part of the GA4 event model – feed directly into reports and explorations.

Similarly, any other product-related actions (e.g. add_to_cart, begin_checkout, purchase) can reuse the same Data Layer variables or push new ones. For example, on “Add to Cart” you could try something like:


window.dataLayer.push({
  'event': 'addToCart',
  'product_name': 'Example Widget',
  'product_brand': 'Acme Corp',
  'price': 49.95
});

In Short

By combining JSON-LD with the GTM dataLayer, we close the loop between web content and analytics. Analysts can now ask GA4: “Which product categories convert best?” or “What is the average order value by brand?” and have GA4 answer directly from the enriched event data.

Without semantic data, an event might only carry a URL or product ID; with semantic enrichment, it carries fully-defined attributes. As a result, data quality and consistency improve significantly.

Give it a go and let me know how you get on.