Issue with Google Tag Manager where the class name is ending with '-ok' is causing problems

Utilizing Google Tag Manager for monitoring clicks within my search engine, which showcases various book details such as cover images, titles, and authors. When a book is in stock, it displays a checkmark and "Leverbaar" (In stock) below the price tag ($17.90).

https://i.sstatic.net/pCKC2.png I have implemented an Event tracking Tag with specific triggers set as follows: Trigger when on a particular page,

Triggers on All Elements, Some Clicks:
Click Element Matches CSS Selector :
.zoekresultaat-cover, .zoekresultaat-titel, .zoekresultaat-auteur, .zoekresultaat-ondertitel, .zoekresultaat-leverbaar-ok, .zoekresultaat-leverbaar-nok

HTML

<div class="cb-Artikel-row cb-meerdere-Titels">
    <div class="cb-col1">
        <figure class="artikel-cover">
            <div class="cb-Titeldetails">
                <img src="https://cbonline.boekhuis.nl/thumbnails/2552/9789463332552_covrtn.jpg" class="cb-Titeldetails zoekresultaat-cover">
            </div>
        </figure>
    </div>

    <div class="cb-col2">
        <div class="zoekresultaat-auteur"></div>
        <div class="zoekresultaat-titel">Hallo! Kraambezoek</div>
        <div class="zoekresultaat-reeks">Hello Baby</div>
        <div class="cb-Titeldetails-artikelgegevens">
            <div class="zoekresultaat-bindwijze">Hardcover</div>
        </div>
        <div class="cb-Titeldetails-titelgegevens">
            <span class="taal zoekresultaat-taal">Nederlands</span>
            <span class="verdeler">|</span>
            <span class="verschijningsdatum zoekresultaat-verschijningsdatum">2018</span>
            <span class="verdeler">|</span>
            <span class="ISBN zoekresultaat-isbn">9789463332552</span>
        </div>
    </div>

    <div class="cb-col3">
        <div class="cb-col3-Wrapper">
            <div class="cb-Prijs-En-Leverbaarheid">
                <div class="cb-Titeldetails-prijs zoekresultaat-prijs">13,95</div>
                <div class="cb-Titeldetails-boeksoort zoekresultaat-boeksoort"> (Algemeen)</div>
                <div class="cb-BeschikbaarheidMelding">
                <div class="cb-Titeldetails-leverbaar-ok zoekresultaat-leverbaar-ok">Leverbaar</div>
                <div><span style="color:black" class="CBIcon-CBO-095-pijltje_verder" aria-hidden="true"></span></div>
                <div class="cb-Titeldetails-assortiment zoekresultaat-assortimenttype">CB-assortiment</div>
                </div>
            </div>
        </div>
    </div>
</div>

The Event Label features a Custom Javascript variable with the following code:

function(){
 // Searching for elements like cover by clicking.
 if({{Click Classes}}.indexOf('zoekresultaat-cover') >= 0){
   var ISBN = {{Click ID}};
   ISBN = ISBN.replace('titel_img_','');
   return 'cover || ISBN:' + ISBN;
 }
 // Price tag click.
 if({{Click Classes}}.indexOf('zoekresultaat-prijs') >= 0){
   var ISBN = $({{Click Element}}).parent().parent().parent().parent().find('.zoekresultaat-isbn').text();
   return 'price || ISBN:' + ISBN; ;
 }
 // Checking stock status for availability.
 if({{Click Element}}.indexOf('zoekresultaat-leverbaar-ok') >= 0){
   var ISBN = $({{Click Element}}).parent().parent().parent().parent().find('.zoekresultaat-isbn').text();
   return 'Stock Status: Available || ISBN:' + ISBN; 
 }
 // Handling out of stock scenarios.
 if({{Click Classes}}.indexOf('zoekresultaat-leverbaar-nok') >= 0){
   var ISBN = $({{Click Element}}).parent().parent().parent().parent().find('.zoekresultaat-isbn').text();
   return 'Stock Status: Not available || ISBN:' + ISBN; 
 }

 // For other elements clicked.
 else{
   return 'Unknown'; // Unknown element has been clicked.
 }
}

During the preview mode activation in Google Tag Manager for testing purposes, all div elements including author, cover, price, and title function correctly.

However, incorrect results are observed solely for the stock status divs: .zoekresultaat-leverbaar-ok and .zoekresultaat-leverbaar-nok :

It appears that Tag Manager wrongly registers clicks on the cover image... https://i.sstatic.net/HVh5m.png https://i.sstatic.net/a06BF.png

Inspecting elements in Chrome https://i.sstatic.net/4M5pX.png https://i.sstatic.net/re4tt.png

The .cb-col1, .cb-col2, .cb-col3 div contains the CSS property: display:inline-block.

Answer №1

It seems that Google Tag Manager encounters problems with classes that end in '-ok'.

I decided to experiment and see if the issue was related to the number of '-' within a classname. When I tested 'cb-Titeldetails-leverbaar-o', Tag Manager correctly identified it when I clicked on the div. However, when I tried 'cb-Titeldetails-leverbaar-ok', it did not work.

For my third test, I used 'cb-Titeldetails-leverbaar-oke', which was also successfully recognized by Tag Manager. This led me to conclude that Tag Manager struggles with classes ending in '-ok'.

To resolve this issue, I changed the class to cb-Titeldetails-leverbaar-Y.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

"Bringing the power of JavaScript to your WordPress

I have set up a wordpress page and integrated some JavaScript into it. When working in wordpress, there are two tabs on a page where you can input text - 'Visual' and 'Text'. The 'Text' tab is used for adding HTML and scripts ...

Using setInterval together with jQuery to animate CSS based on changes in window size

I've been troubleshooting this issue and trying various methods, but despite it seeming logical, nothing is working. Any assistance would be greatly appreciated since I'm not very skilled in coding. My current challenge involves animating an obj ...

Automatically shutting windows using jQuery after a certain number of seconds

I am currently trying to find a solution to this issue. The problem I am facing is that I need to close a window after it has been open for 7 seconds each time. I have managed to make the windows close using SetInterval, however, the timing is not precise ...

Unable to select checkbox within a table using Selenium WebDriver with Java

Having trouble checking a checkbox inside a table using Selenium Webdriver in Java? Even with version 2.52.0 of Selenium, the element not found error persists across different web browsers. The iFrame seems to be correct as I can interact with other compon ...

Tips for building an interactive jQuery data table using JSON information and AJAX requests

Currently, I am attempting to develop a dynamic data table using jQuery and JSON. My objective is to extract the keys from the JSON data and utilize them as headers in the table, while the values within those keys will be displayed as rows. Here's th ...

Create an Array of Objects by Sharing Your Post

Can someone guide me on the correct way to post my data here? I have been encountering errors while trying to insert data into user.SavedMachines.Id and user.SavedMachines.Date. I attempted using user.SavedMachines.Id = req.body.SavedMachinesId and user. ...

Create a random word from a single string within the data in Nuxt.js

I am in need of assistance. In my Vue Nuxtjs project, I am fetching random words generated from my backend Laravel application through an API response. I need to generate multiple random words from a single string value in the data obtained from my Axios r ...

Modify the background color of a single page while keeping the other pages unchanged

Is there a way to have a blue background on only one page of my rails application, while keeping all other pages with a white background? I attempted using the following code: <%= javascript_include_tag params[:controller] %> or <%= stylesheet_ ...

unable to implement $http method in angular.js

I am attempting to retrieve data from a web API. When running on a single HTML page, I receive the response with the data successfully. However, if this script is written separately (outside the HTML page), I am unable to fetch the data. This is the first ...

Generating a new POST header

I have encountered a challenge: I need to transfer an array to another page without using AJAX. My goal is to either redirect the user to the new page or open a popup displaying the new page, all while ensuring the array data is sent via a POST request. C ...

Is there a way to incorporate icons into the rows of a react ag-grid?

I'm currently using the react ag-grid library and I've attempted to use the cellRenderer function, but unfortunately, it's not working as expected. columnDefinationWaterUsage: [ { headerName: "", cellRenderer: count ...

What is the best way to effectively clear memory in THREE.js?

After successfully rendering the model, rotating and zooming work perfectly. However, when attempting to clear the scene by clicking the button#clear, issues arise. The expectation is to traverse through the scene, add its children to an array, iterate ov ...

Troubleshooting objects in Javascript: Understanding the scope problem with 'this'

Here is my code snippet: var tradingInterface = function() { this.json = ''; this.init = function() { $.get( '/whatever',{}, function(data) { this.json = data; // Rebuilds Everything ...

PHP not compatible with Fancybox iframe

I'm facing a simple problem that I can't seem to figure out. I have a button that, when clicked, opens a fancybox with an iframe displaying a page from my website. This page includes a form for sending an email. Everything works fine except that ...

Handling errors within classes in JavaScript/TypeScript

Imagine having an interface structured as follows: class Something { constructor(things) { if (things) { doSomething(); } else return { errorCode: 1 } } } Does this code appear to be correct? When using TypeScript, I en ...

Interested in learning how to redirect to a different page using vanilla JavaScript after submitting an HTML form with a Django backend?

Recently delving into Django, I encountered a challenge of linking a js file to my HTML form page and saving the form data before moving on to the next screen. My aim was to incorporate a feature where users can click a picture and POST it along with their ...

How can I refresh a window in Internet Explorer without it taking focus away?

Occasionally, I have a page where I need to update the URL with certain GET parameters in the background using JavaScript. This allows the page to refresh with the new parameters. For instance, I might use: window.location.href = window.location.host + & ...

PyScript <script type="py-editor"> Issue: SharedArrayBuffer cannot be used in an insecure environment

I am currently using PyScript to execute a basic Python script within my HTML file in order to show a pandas DataFrame. However, upon loading the page in the browser and attempting to run the code block by clicking the run button, I encounter an error rela ...

What is the optimal method for fetching JSON information with Angular?

I have data that I organized in a JSON-like structure, as shown below: { "Id": { "1": [ { "Item1": "Item One", "Item2": "Item Two", "Item3": "Item Three" ...

Choosing a value using Jquery on change is not effective

NOTE: Unnecessary information has been removed I am looking to select the parent element when the value of a select element is changed, and then serialize that parent: jQuery('body').on('change','.shop_table select',function ...