You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Go to a webshop that doesn't have an add to cart button per product on the category page
Click the product link (image, title, etc)
Check the dataLayer push result in the console
Expected result:
The product click is tracked properly
Actual result:
An error in the console is shown: Cannot read properties of null (reading 'querySelector')
Note
The script is fetching a parent element, which can be null based on the result of the function yireoGoogleTagManager2FindParentElementWithName. See this code snippet.
This happens when a product is not salable or if with customizations the form has been removed from the overview page. In the end only the product ID needs to be fetched, which is not shown anywhere else in the code expect for the missing hidden input field with the name product.
My first response was to check if there was a parent element. And if it's null, the code should break with a return. However, that will also remove the tracking of the clicks. Which doesn't do anything anyway when the product ID is not available.
The text was updated successfully, but these errors were encountered:
Steps to reproduce:
Expected result:
Actual result:
Cannot read properties of null (reading 'querySelector')
Note
The script is fetching a parent element, which can be
null
based on the result of the functionyireoGoogleTagManager2FindParentElementWithName
. See this code snippet.This happens when a product is not salable or if with customizations the form has been removed from the overview page. In the end only the product ID needs to be fetched, which is not shown anywhere else in the code expect for the missing hidden input field with the name
product
.My first response was to check if there was a parent element. And if it's
null
, the code should break with areturn
. However, that will also remove the tracking of the clicks. Which doesn't do anything anyway when the product ID is not available.The text was updated successfully, but these errors were encountered: