ecommerce tracking – Pietro Mingotti https://pietromingotti.com Technical SEO, Advanced CPC and Digital Analytics Case Studies Fri, 03 May 2024 15:33:40 +0000 en-US hourly 1 https://pietromingotti.com/wp-content/uploads/2023/04/cropped-cropped-Pietro-Mingotti-2023-Web-High-Res-1-32x32.jpg ecommerce tracking – Pietro Mingotti https://pietromingotti.com 32 32 Fixing Double DataLayer Pushes on Ecommerce Events because of eventModel https://pietromingotti.com/eventmodel-double-datalayer-pushes-fix/ https://pietromingotti.com/eventmodel-double-datalayer-pushes-fix/#comments Fri, 03 May 2024 15:22:01 +0000 https://pietromingotti.com/?p=1312 Read more]]> Here’s a typical problem in Shopify and Woocommerce configurations: in Google Tag Manager, you notice double datalayer pushes of ecommerce events, specifically “view_item”, “add_to_cart”, and “purchase” events. This pollutes your data, and it’s caused by the simultaneous presence of one app or plugin pushing GA4 DataLayer events, and another one pushing Google Shopping DataLayer events.

Here’s how to fix it.

The double DataLayer pushes of ecommerce events

We have noticed this in many Shopify installations, but also often in Woocommerce. Let’s focus on the latter now, but the same approach applies to Shopify.

You navigate your preview mode of GTM and you see something like this on a product page (for the scope of this debug, we’re going to focus only on the view_item event).

duplicated view item event in gtm

When you inspect the duplicated view_item event, you notice these two different syntaxes.

GA4 Syntax
dataLayer.push({
  ecommerce: {
    currency: "EUR",
    value: 250,
    items: [
      {
        item_id: "XXX",
        item_name: "Product Name",
        sku: "XXX",
        price: 250,
        stocklevel: 9,
        stockstatus: "instock",
        google_business_vertical: "retail",
        item_category: "Category Name",
        id: "XXX"
      }
    ]
  },
  event: "view_item",
  gtm.uniqueEventId: 9
})

The other view_item event, has this syntax

Old Google Shopping Syntax
dataLayer.push({
  event: "view_item",
  eventModel: {
    ecomm_pagetype: "product",
    value: 250,
    items: [
      {
        id: "XXX",
        price: 250,
        google_business_vertical: "retail",
        name: "Product Name",
        category: "Category Name" +
                  "amp; Category Name amp" +
                  "; Category Name"
      }
    ]
  },
  gtm.uniqueEventId: 8
})

How to solve the double datalayer pushes of ecommerce hits

At this point you typically have three options.

Obviously option 3 offers the best solution, as you’ll be able to send data to all the relevant platforms in the right syntax, but also Option 2 is a viable option.

So here’s how to filter the double datalayer push of your ecommerce events for your GA4 Triggers.

Filtering your ecommerce tracking triggers

The goal is for your ecommerce events triggers to ignore the duplicated push that contains the syntax based on “eventModel”, while firing only when the syntax doesn’t contain “eventModel”.

The way to achieve this depends on your current Ecommerce Tracking. On our end, we have the following implementation for tracking ecommerce events.

Ecommerce Tags configuration example

Let’s say that these are all the ecommerce events that you want to track in GA4:

  • menu_click
  • view_promotion
  • view_category
  • select_promotion
  • view_item
  • view_item_list
  • select_item
  • add_to_cart
  • remove_from_cart
  • view_cart
  • begin_checkout
  • add_payment_info
  • add_shipping_info
  • purchase

It would be really messy to make one trigger per each event, so it’s likely you’ve configured your trigger this way:

Trigger Configuration: Custom Event

Event (with regex matching checked): view_promotion|view_category|select_promotion|view_item|view_item_list|select_item|add_to_cart|remove_from_cart|view_cart|begin_checkout|add_payment_info|add_shipping_info|purchase

Then, most likely, you have one GA4 Event tag that sends the triggering event with all the custom paramters using the DataLayer information, to GA4.

Filtering with a Boolean Javascript

The most obvious way to try and fix the problem, is to set a condition to the Ecommerce Trigger so that it will fire when it reads one of your events, but only in specific cases:

ecommerce tracking trigger with regex matching

You can use a custom javascript variable to look for the presence of the object “eventModel”; if it’s found, it should output “true”; if not found, it should output “false”. Here’s an example javascript:

JavaScript
function() {
    var isEventModelPresent = false;
    if (typeof dataLayer !== 'undefined') {
        var dataLayerString = JSON.stringify(dataLayer);
        if (dataLayerString.indexOf('eventModel') !== -1) {
            isEventModelPresent = true;
        }
    }
    return isEventModelPresent;
}

But, depending on your implementation and how soon the DataLayer is populated compared to when the variable runs the script, this approach might be unreliable. I will update this post in the future after further investigation.

Filtering with Data Layer Variable lookup

Another and tested approach is to look for the “undefined” value of the first key in the eventModel object. Infact, if Google Tag Manager finds the key, it will render the content of the key, but if not, it will return “undefined”. You can leverage this behavior to stop your trigger from firing.

Here’s how:

Step 1:

Create the variable “eventModel”.

accessing the eventModel object in datalayer

Step 2:

Create the Javascript that will read the content of eventModel:

JavaScript
function() {
  var eventModel = {{eventModel}};
  if (eventModel) {
    return eventModel;
  } else {
    return undefined;
  }
}

Step 3:

Now access the first level of your DataLayer push. In this case, it was “eventModel.ecomm_pagetype

event model reading trough gtm

Step 4:

Now that we can read the content of ecomm_pagetype, we can hunt down that “undefined” response when the eventModel object is not present at all.

preventing double datalayer pushes recognition of the trigger

Conclusions

As a result, your ecommerce events are going to fire the tag associating with this redesigned trigger, only when the syntax of the DataLayer is the standard one (or the one of your choice). Hope this helps.

]]>
https://pietromingotti.com/eventmodel-double-datalayer-pushes-fix/feed/ 2
GTM & GA4 DataLayer Blueprints for Ecommerce Measurement https://pietromingotti.com/gtm-ga4-datalayer-for-ecommerce-measurement/ https://pietromingotti.com/gtm-ga4-datalayer-for-ecommerce-measurement/#respond Tue, 30 Apr 2024 13:27:20 +0000 https://pietromingotti.com/?p=1254 Read more]]> Here’s Fuel LAB‘s internal Data Layer blueprints designed for successful integration with the Google Marketing Platform. We use this daily as all of our integrations are done this way.

This documentation covers all the DataLayer Push for GTM and GA4; the syntax is compatible with all the products of the Google Marketing Platform.

This tracking blueprint will feature also non e-commerce items to include standard best practices.

an image of the datalayer seen from the chrome web inspector


GA4 Events you can push with the DataLayer

Events are the core of the data layer push process. They allow you to track user behaviors or interactions with your website, such as clicking a button or view a product page. Events are triggered when the user performs an action, such as clicking a button or viewing a product page, and they can be used to capture data, including product data or user-specific data. Therefor, every implementation is different in terms of what triggers these events, trough datalayer pushes.

EventExample Trigger
view_promotionVisualization of the promotional content on page; typically caused by the screen rendering of an element or group of elements tagged accordingly as promotion.
select_promotionClick on a product contained in the tagged container “promotion” of your website, or any other placement dedicated to promotions.
view_itemLanding on a Woocommerce Product Page, Shopify Product page, and so on.
view_item_listVisualization of any group of products; it could be the shop page, it could be the product selectors in the landing pages, it could be the cross sell grid of products on a product page.. that’s why using parameters like “item_list_id” is fundamental to accurately reading data.
select_itemClick pointing to the product page, be it from the item list in the shop page, or in any other product display placement.
select_categoryThis is a custom event we use to track collections and categories view, or landing page groups.
view_categoryAnother custom event we use to track the count of views of a specific category content.
add_to_cartWhen a click performs an add to cart.
remove_from_cartWhen an item is removed from the cart.
view_cartPageview of the cart page.
begin_checkoutPageview of the checkout page.
add_payment_infoWhen the desired payment method has been selected.
purchaseOn purhcase, on the order receipt page.
user_loginWhen a user logs in.
user_signupWhen a visitor becomes a user, creating an account.
menu_clickThis is a custom event. Triggered when menu items are clicked on.
generate_leadWhen a contact form is successfully sent.
This table lists the events we recommend to track trough the datalayer implementation.

Ecommerce Parameters

The parameters to pass in custom events for Google Analytics 4 and Google Ads are important for tracking user interactions and understanding user behaviour on your website. These events can help you gain insights into user behaviour, track conversions, and measure the success of your marketing campaigns. Notably, they are fundamental also for Google Ads’s campaigns to optimize correctly (depending on your usage of audiences, and micro conversions).

The parameters that can be passed in for DataLayer pushed events include, as an example:

  • ecommerce: An object containing information about the user’s purchase (e.g. the items purchased, the currency, and the total value of the purchase).
  • currency: The currency in which the purchase was made (e.g. EUR).
  • value: The total value of the purchase.
  • items: An array of objects containing parametric information about each item purchased (e.g. item_id, item_name, item_category, etc.).
  • authenticationMethod: The method used to authenticate the user (e.g. email).
  • userId: An identifier for the user (e.g. abc123).
  • userType: The type of user (e.g. Free User).
  • item_list_id: An identifier for the list of items purchased.
  • item_list_name: The name of the list of items purchased.
  • listposition: The position of the item in the list of items purchased.
  • coupon: The coupon code used for the purchase (if any).
  • discount: The discount amount applied to the purchase (if any).

Deepening the syntax and structure of the Data Layer, we find product data, promotion data and action data.

Product Data

ParameterDescription
item_idID / SKU of the product.
item_nameName of the product.
item_list_nameProduct list name.
item_list_idProduct list identifier.
indexProduct position in the list.
item_brandProduct brand.
item_categoryProduct category top-level.
item_category2Product category 2nd level (or alternative).
item_category3Product category 3rd level (or alternative).
item_category4Product category 4th level (or alternative).
item_category5Product category 5th level (or alternative).
item_variantItem variant name or description.
affiliationThe store affiliation for this event.
discountAny discount associated with this product.
couponCoupon associated with this product.
pricePrice of this product.
currencyCurrency of the price that is collected.
quantityQuantity of the item. Must be an integer.
A list of parameters related to products and ecommerce tracking.

Promotion Data

ParameterDescription
promotion_idID of the promotion.
promotion_nameName of the promotion.
creative_nameName of the creative associated with the promotion.
creative_slotName of the slot where the creative was shown.
location_idThe physical location associated with the item. It’s recommended to use the Google Place ID that corresponds to the location.
A set of parameters related to promotions and ecommerce tracking.

Action Data

ParameterDescription
transaction_idUnique ID for the transaction. Required for purchase and refund events.
affiliationThe store or affiliation where the purchase occurred.
valueThe value associated with the event.
currencyLocal currency of the collected price. Required for purchase events.
taxHow much tax is included in the total revenue of the purchase.
shippingShipping costs included in the total revenue of the purchase.
itemsProducts associated with the event.
shipping_tierThe shipping tier used with add_shipping_info.
payment_typeThe payment method sent with add_payment_info.
couponCoupon associated with the event.
promotion_idID of a promotion associated with the event.
promotion_nameName of a promotion associated with the event.
creative_nameName of a promotion creative associated with the event.
creative_slotName of the creative slot associated with the event.
location_idThe physical location associated with the item. It’s recommended to use the Google Place ID that corresponds to the location.
item_list_nameName of the list associated with the event.
item_list_idID of the list associated with the event.
form_idThe forminator Form ID
form_nameThe forminator Form Name
form_typesales, support
These parameters are used to populate dynamic information associated with the e-commerce and performance events.

Practical Data Layer Push Examples

Here’s our Data Layer pushes; obviously the rendered data is dummy-text that will change reflecting your ecommerce or website’s content, accordingly to implementation.

🚨 We recommend using the following command to delete the e-commerce object before executing a push of an e-commerce event at the data level. The deletion of the object will prevent multiple e-commerce events on a page from affecting each other.

Link to Documentation: https://developers.google.com/analytics/devguides/collection/ga4/ecommerce?hl=it&client_type=gtm

dataLayer.push({ ecommerce: null });  // Clear the previous ecommerce object.
JavaScript
dataLayer.push({ ecommerce: null });  // Clear the previous ecommerce object.
Custom Event
window.dataLayer = window.dataLayer || [];
 window.dataLayer.push({
  event: "menu_click",
  ecommerce: {
			currency: "EUR",
			items: {
menudata_item_listposition: 1, 
menudata_item_url: "https://exampleurl.com/",
menudata_item_category: "Jackets",
menudata_item_name: "Discover Field Jackets - Made in Italy", 
menudata_item_id: 34789 }  },
})

View Promotion

Recommended Event
dataLayer.push({ ecommerce: null });
dataLayer.push({
  event: 'view_promotion',
  ecommerce: {
      promotion_id: 'yourPromoId1',
      promotion_name: 'Jackets_Cyber_Monday23',
      creative_name: 'Happy_Family_Wearing_Jackets',
      creative_slot: 'featured_promotions',
      location_id: 'hero_slider',
			currency: "EUR",

	items: [{
				item_id: 230,
        item_name: "Field Jacket Dora",
        item_brand: "",
        price: 49,
        item_category: "Outdoor Jackets",
        item_variant: "Nylon FJM Ruby Red",
        quantity: 2,
        google_business_vertical: "retail",
        id: "230"

    }],
  }
});

Select Promotion

Recommended Event
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
  event: 'select_promotion',
  ecommerce: {
      promotion_id: 'yourPromoId1',
      promotion_name: 'Jackets_Cyber_Monday23',
      creative_name: 'Happy_Family_Wearing_Jackets',
      creative_slot: 'featured_promotions',
      location_id: 'hero_slider',
			currency: "EUR",

	items: [{
				item_id: 230,
        item_name: "Field Jacket Dora",
        item_brand: "",
        price: 49,
        item_category: "Outdoor Jackets",
        item_variant: "Nylon FJM Ruby Red",
        quantity: 2,
        google_business_vertical: "retail",
        id: "230"

    }],
});

View Item

Recommended Event
window.dataLayer = window.dataLayer || [];
 window.dataLayer.push({
  event: "view_item",
  ecommerce: {
		currency: "EUR",
		value: "49",
    items: [
      {
       item_id: 230,
        item_name: "Field Jacket Dora",
        item_brand: "",
        price: 49,
        item_category: "Outdoor Jackets",
        item_variant: "Nylon FJM Ruby Red",
        quantity: 2,
        google_business_vertical: "retail",
        id: "230"
      },
})

View Item List

Recommended Event
window.dataLayer = window.dataLayer || [];
 window.dataLayer.push({ 
	event: "view_item_list",
  ecommerce: {
		item_list_id: "related_products", // This will require custom ids or classes on your backend
	  item_list_name: "Related products", // This will require custom ids or classes on your backend
    currency: "EUR",
    items: [
      {
        item_id: 230,
        item_name: "Field Jacket Dora",
        item_brand: "Crazy Butterfiles",
        price: 49,
        item_category: "Outdoor Jackets",
        item_variant: "Nylon FJM Ruby Red",
        quantity: 2,
        google_business_vertical: "retail",
        id: 230
      },
      {
        item_id: 217,
        item_name: "Running Trousers Dora",
        item_brand: "Crazy Butterfiles",
        price: 23.00,
        item_category: "Sports Set",
        index: 1,
        google_business_vertical: "retail",
        id: 217
      },
      {
        item_id: 345798,
        item_name: "Air Max Shoes",
        item_brand: "Nike",
        price: 229.00,
        item_category: "Footwear",
        index: 1,
        google_business_vertical: "retail",
        id: 345798
      },
      {
        item_id: 368784,
        item_name: "Jordan Shoes",
        item_brand: "Nike",
				item_variant: "Limited Edition Orange",
        price: 1900.00,
        item_category: "Footwear",
        index: 1,
        google_business_vertical: "retail",
        id: 368784
      },
      {
        item_id: 357715,
        item_name: "Leather Jacket Reneaged",
        item_brand: "Diesel",
        price: 660.00,
        item_category: "Jackets",
        index: 1,
        google_business_vertical: "retail",
        id: 357715
      },
      {
        item_id: 302108,
        item_name: "Biker Wallet 01299",
        item_brand: "Diesel",
        price: 104.00,
        item_category: "Accessories",
        index: 1,
        google_business_vertical: "retail",
        id: 302108
      },
      {
        item_id: 440,
        item_name: "Sport Watch Band - Silicone",
        item_brand: "Apple",
        price: 65.00,
        item_category: "Accessories",
        index: 1,
        google_business_vertical: "retail",
        id: 440
      }
    ]
  },
})

Select Item

Recommended Event
window.dataLayer = window.dataLayer || [];
 window.dataLayer.push({
  event: "select_item",
  ecommerce: {
		currency: "EUR",
    items: [
      {
        item_id: 368784,
        item_name: "Jordan Shoes",
        item_brand: "Nike",
				item_variant: "Limited Edition Orange",
        price: 1900.00,
        item_category: "Footwear",
        index: 1,
        google_business_vertical: "retail",
        id: 368784
      },
})

Select Category

Custom Event
window.dataLayer = window.dataLayer || [];
 window.dataLayer.push({
  event: "view_item",
  ecommerce: {
		currency: "EUR",
		value: 49,
    items: [
      {
         item_id: 368784,
        item_name: "Jordan Shoes",
        item_brand: "Nike",
				item_variant: "Limited Edition Orange",
        price: 1900.00,
        item_category: "Footwear",
        index: 1,
        google_business_vertical: "retail",
        id: 368784
      },
})

View Category

Recommended Event
window.dataLayer = window.dataLayer || [];
 window.dataLayer.push({
  event: "view_category",
	pageType: "Landing Page",
	pageTitle: "Jackets - Outdoors and Indoors",
	visitorLoginState: "notLogged",
	pageCategory: "Jackets",
  ecommerce: {
    currency: "EUR",
    items: [
      {
            item_id: 230,
        item_name: "Field Jacket Dora",
        item_brand: "Crazy Butterfiles",
        price: 49,
        item_category: "Outdoor Jackets",
        item_variant: "Nylon FJM Ruby Red",
        quantity: 2,
        google_business_vertical: "retail",
        id: 230
      },
      {
        item_id: 217,
        item_name: "Running Trousers Dora",
        item_brand: "Crazy Butterfiles",
        price: 23.00,
        item_category: "Sports Set",
        index: 1,
        google_business_vertical: "retail",
        id: 217
      },
      {
        item_id: 345798,
        item_name: "Air Max Shoes",
        item_brand: "Nike",
        price: 229.00,
        item_category: "Footwear",
        index: 1,
        google_business_vertical: "retail",
        id: 345798
      }
    ]
  },
})

Add to Cart

Recommended Event
window.dataLayer = window.dataLayer || [];
 window.dataLayer.push({
  event: "add_to_cart",
  ecommerce: {
		currency: "EUR",
		value: 98,
    items: [
      {
        productlist_name: "Landing page",
				listposition: "1",
				item_id: 217,
        item_name: "Running Trousers Dora",
        item_brand: "Crazy Butterfiles",
        price: 98.00,
        item_category: "Sports Set",
        item_variant: "hello kitty set",
        index: 1,
        google_business_vertical: "retail",
        id: 217
      },
    ]
  },
})

Remove From Cart

Recommended Event
window.dataLayer = window.dataLayer || [];
 window.dataLayer.push({
  event: "remove_from_cart",
		currency: "EUR",
		value: 122.9,
	  ecommerce: {
	    items: [
      {
       item_id: 217,
        item_name: "Running Trousers Dora",
        item_brand: "Crazy Butterfiles",
        price: 98.00,
        item_category: "Sports Set",
        item_variant: "hello kitty set",
        index: 1,
        google_business_vertical: "retail",
        id: 217
      }
    ]
  },
})

View Cart

Recommended Event
window.dataLayer = window.dataLayer || [];
 window.dataLayer.push({
  event: "view_cart",
  ecommerce: {
    currency: "EUR",
    value: "122.90",
    items: [
      {
        item_id: 230,
        item_name: "Field Jacket Dora",
        item_brand: "Crazy Butterfiles",
        price: 49,
        item_category: "Outdoor Jackets",
        item_variant: "Nylon FJM Ruby Red",
        quantity: 2,
        google_business_vertical: "retail",
        id: 230
      },
      {
        item_id: 217,
        item_name: "Running Trousers Dora",
        item_brand: "Crazy Butterfiles",
        price: 23.00,
        item_category: "Sports Set",
        index: 1,
        google_business_vertical: "retail",
        id: 217
      }
    ]
  },
})

Begin Checkout

Recommended Event
window.dataLayer = window.dataLayer || [];
 window.dataLayer.push({
  event: "begin_checkout",
  ecommerce: {
    currency: "EUR",
    value: 122.9,
		coupon: "some_coupon",
    items: [
      {
        item_id: 230,
        item_name: "Field Jacket Dora",
        item_brand: "Crazy Butterfiles",
        price: 49,
        item_category: "Outdoor Jackets",
        item_variant: "Nylon FJM Ruby Red",
        quantity: 2,
        google_business_vertical: "retail",
        id: 230
      },
      {
        item_id: 217,
        item_name: "Running Trousers Dora",
        item_brand: "Crazy Butterfiles",
        price: 23.00,
        item_category: "Sports Set",
        index: 1,
        google_business_vertical: "retail",
        id: 217
      }
    ]
  },
})

Add Payment Info

Recommended Event
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
  event: 'add_payment_info',
  ecommerce: {
    payment_type: 'PayPal', // o CDC, o quello che vogliamo
    currency: "EUR",
    value: 122.9,
    items: [
      {
         item_id: 230,
        item_name: "Field Jacket Dora",
        item_brand: "Crazy Butterfiles",
        price: 49,
        item_category: "Outdoor Jackets",
        item_variant: "Nylon FJM Ruby Red",
        quantity: 2,
        google_business_vertical: "retail",
        id: 230
      },
      {
        item_id: 217,
        item_name: "Running Trousers Dora",
        item_brand: "Crazy Butterfiles",
        price: 23.00,
        item_category: "Sports Set",
        index: 1,
        google_business_vertical: "retail",
        id: 217
      }
    ]
  },
})

Purchase (with Enhanced Conversion data)

Conversion Event
window.dataLayer = window.dataLayer || [];
 window.dataLayer.push({
	new_customer: false, (boolean
  event: "purchase",
  ecommerce: {
    currency: "EUR",
		transaction_id: "IT-402902",
		discount: "somediscount"
		coupon: "somecoupon",
    affiliation: "",
    value: 134,
    items: [
      {
         item_id: 230,
        item_name: "Field Jacket Dora",
        item_brand: "Crazy Butterfiles",
        price: 49,
        item_category: "Outdoor Jackets",
        item_variant: "Nylon FJM Ruby Red",
        quantity: 2,
        google_business_vertical: "retail",
        id: 230
      },
      {
        item_id: 217,
        item_name: "Running Trousers Dora",
        item_brand: "Crazy Butterfiles",
        price: 23.00,
        item_category: "Sports Set",
        index: 1,
        google_business_vertical: "retail",
        id: 217
      }
    ],
		userdata:{
				user_type: private,professional (boolean),
				email: "123@google.com",
				name: "pietro",
				surname: "mingotti",
				address: "strada del datalayer 155",
				city: "Vicenza",
				country: "Italy",
				zip: "36100",
				phone: "00393201124822"
	},
  },
})

User Login

Advanced Event
window.dataLayer = window.dataLayer || [];
 window.dataLayer.push({
	'event' : 'login',
	'authenticationMethod' : 'email',
	'userId' : 'abc123' //this should be replaced with an actual ID
 });

User Signup

Advanced Event
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
    'event': 'signup',
    'userType': 'Free User'
});

Generate Lead (with Enhanced Conversion Data)

Conversion Event
window.dataLayer = window.dataLayer || [];
 window.dataLayer.push({
  event: 'generate_lead',
  form_id: 'form id',
  form_name: 'form name',
  form_type: 'support or sales or else',
  pageType: "",
  pageTitle: "",
  pagePath: "",
	 userdata:{
				user_type: private,professional (boolean),
				email: "123@google.com",
				name: "pietro",
				surname: "mingotti",
				address: "strada del datalayer 155",
				city: "Vicenza",
				country: "Italy",
				zip: "36100",
				phone: "00393201124822"
	},
});

The items Array

It is important to consider that the “items” Array, within “ecommerce”, can populate all these fields (example data).

JavaScript
items: [
      {item_id: "SKU_12345",
      item_name: "Jordan Crazy Shoes",
      affiliation: "",
      coupon: "COUPON_TEST",
      currency: "EUR",
      discount: 12.22,
      index: 1,
      item_brand: "Nike",
      item_category: "Footwear",
      item_list_id: "homepage_widget",
      item_list_name: "Homepage Widget",
      item_variant: "Jordan Autograph Red",
      price: 119.99,
      quantity: 1
      },
      {...}]

Non-Ecommerce Parameters

Here’s a list of parameters not necessarily linked to e-commerce tracking, but valuable to enhance you e-commerce tracking.

ParameterDescription
pageTypeType of page (e.g. home page, product page, category page, etc.)
pageTitleTitle of the page
pageCategoryCategory of the page (e.g. men’s clothing, electronics, etc.)
pagePathPath of the page (e.g. /category/mens-clothing/shirts)
pageLanguageLanguage of the page
pageLocationGeographical location of the page (e.g. country, state, city)
visitorIdUnique identifier for the visitor
visitorTypeType of visitor (e.g. new visitor, returning visitor, etc.)
visitorLoginStateWhether the visitor is logged in or not
visitorAgeRangeAge range of the visitor
visitorGenderGender of the visitor
deviceTypeType of device used to access the website (e.g. desktop, mobile, tablet)
browserTypeType of web browser used by the visitor
browserVersionVersion of the web browser used by the visitor
OSOperating system used by the visitor

Base DataLayer Content

The DataLayer, without specific triggers, must populate these information at every page load:

JavaScript
{
pageType:,
pageTitle:,
pageCategory:,
visitorLoginState:,
ecommerce:{
currency:,
items:,
}}

The typical data values for pageType are:

JavaScript
if (is_front_page())  $pageType = 'frontpage';
	if (is_page())  $pageType = 'page';
	if (is_single())  $pageType = 'post';
	if (is_category())  $pageType = 'category';
	if (is_tag())  $pageType = 'tag';
	if (is_author())  $pageType = 'author';
	if (is_search())  $pageType = 'search';
	if (is_404())  $pageType = '404';
	if (is_archive())  $pageType = 'archive';
	if (is_shop())  $pageType = 'shop';
	if (is_product())  $pageType = 'product';
	if (is_product_category())  $pageType = 'product_category';
	if (is_product_tag())  $pageType = 'product_tag';
	if (is_cart())  $pageType = 'cart';
	if (is_checkout())  $pageType = 'checkout';
	if (is_checkout() && !empty(is_wc_endpoint_url('order-received'))) $dataLayer['pagePostType'] = 'purchase';
	if (is_account_page())  $pageType = 'account';
	if (is_order_received_page())  $pageType = 'order_received';
	if ($pageTemplate == 'views/template-landing-page.blade.php') $pageType = 'product';

How to push the DataLayer

I hope our blueprints were useful for your debug or implementation sessions. It’s impossible to depict “how to push the data layer”, without looking at your specific website. Feel free to press the floating button on this page to request a meeting and an implementation.

However, something to start with a basic tracking, if you’re using WordPress with WooCommerce, would be the Google Tag Manager for WordPress plugin. Many websites use it, it’s well done and lightweight.

]]>
https://pietromingotti.com/gtm-ga4-datalayer-for-ecommerce-measurement/feed/ 0