Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when clicking product in category without add to cart button #256

Open
ArjenMiedema opened this issue Nov 20, 2024 · 0 comments
Open

Comments

@ArjenMiedema
Copy link

ArjenMiedema commented Nov 20, 2024

Steps to reproduce:

  • 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant