Tracking JavaScript buttons with Klaviyo

I am currently facing an issue with a JavaScript script I have implemented to track button clicks on my website and send information to Klaviyo. I have set up a flow in Klaviyo to send emails based on the button click "Add To Wishlist," but for some reason, it is not functioning correctly.

Following advice from this post on Stack Overflow: getElementsByClassName() with two classes

Since I have 2 classes, I have used a query selector. Here are screenshots of them: 1. On Collection Page http://prntscr.com/rn50ok

2.On Product Page: http://prntscr.com/rn51n0

P.S

Although this may seem basic, I have very limited knowledge of JavaScript and APIs. I merely followed Klaviyo's documentation and attempted to create the code based on their Add To Cart example.

<script text="text/javascript">
var _learnq = _learnq || [];

var classname = document.querySelectorAll(".yith-wcwl-add-button jas_add_wishlist,.add_nitro_wishlist add_to_wishlist gecko-tooltip");

var myFunction = function() {
_learnq.push(['track', 'Add to Wishlist', item]);
};

for (var i = 0; i < classname.length; i++) {
classname[i].addEventListener('click', myFunction, false);
}
</script>

Answer №1

Is it necessary to utilize two classes here? Using just one class could make the code cleaner. For example, let's use the class "jas_add_wishlist":

<script text="text/javascript">
var _learnq = _learnq || [];

var classname = document.getElementsByClassName("jas_add_wishlist");

var myFunction = function() {
_learnq.push(['track', 'Add to Wishlist', item]);
};

for (var i = 0; i < classname.length; i++) {
classname[i].addEventListener('click', myFunction, false);
}
</script>

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

Using Puppeteer to Retrieve a List of Items with Identical Selectors

Issue: I am currently working on developing an end-to-end regression test for an EmberJS solution using NodeJS/CucumberJS/Puppeteer. However, I have encountered a challenge that I need help with. Challenge: The problem lies in selecting (page.click) and ...

Issue adding dictionary value to an array in JavaScript

Let's analyze the code snippet below: var array = []; var obj = [{id: "xxxxx", name: "Friend name"}, {id: "xxxxx", name: "Friend name"}] for (x in obj){ array.push(x.name) } After running this code, the array ends up with the correct length but ...

What strategies can be employed to preserve certain fields while dynamically populating others using JSON in a form?

Currently, I am utilizing jquery Populate to dynamically fill a field with the information from the previous Firstname and Surname fields within the same form. However, an issue arises when using the Populate javascript function: $(formname).populate(newfi ...

Does the language setting on a browser always stay consistent?

Using javascript, I am able to identify the language of my browser function detectLanguage(){ return navigator.language || navigator.userLanguage; } This code snippet returns 'en-EN' as the language. I'm curious if this i ...

Discover the pixel width of a Bootstrap grid row or container using JavaScript

How can I calculate the width of a Bootstrap grid row or container in pixels using JavaScript? I am working with Aurelia for my JavaScript project, but I'm open to solutions in standard JS (no jQuery, please). Looking at the Bootstrap documentation, ...

The property number will have no effect on the time

Currently, I am in the process of developing an audio player that includes essential functions such as backward, play, and forward buttons. Strangely enough, the backward function operates perfectly fine, but the forward button is not functioning properly ...

Tips for arranging elements in proper order following a rotation

Having trouble aligning rotated divs? Let's say we rotate .straight by 30deg, and now we want to find the new offset coordinates of its bottom right corner. This way, we can perfectly match up the bottom left corners of .curve with this new coordinate ...

Implementing momentLocalizer with moment.js in react-big-calendar alongside fullcalendar.js

I'm currently working with react-big-calendar and I require assistance in setting up localization as per the example provided on GitHub. import BigCalendar from 'react-big-calendar'; import moment from 'moment'; BigCalendar.setLo ...

initiating a submission upon the occurrence of an onchange event on an input field of type "file"

I have encountered an issue while trying to submit a form using the onchange event of an input element with type file. The problem is that it submits an empty form even when a file has been chosen. Here is the code snippet: var form = document.createElem ...

Enhance your tooltip pie chart in echarts4r by incorporating additional variables

Currently, I am in the process of creating a doughnut chart with echarts4r. As I delve into adding a custom tooltip to enhance the user experience, I have successfully referenced examples from Stack Overflow on stacked area charts (Echarts4r : Create stack ...

What is the best way to update the type = date values with my "SearchDate" parameter in a Python template?

I have the variable search_date in my view and I need to display this data in a template. How can I achieve this? In the object, the date is set as "2020-09-01". I tried to write the following code but it did not work as expected: {% extends 'bas ...

When utilizing a prisma query with a callback function, it appears that try/catch blocks are being overlooked in Node.js

After referencing error handling methods from the prisma documentation, I encountered an issue with my code: try { prisma.daRevisionare.create({ data: { "idTweet": tweet.id, "testo": testotweet, url } }).then((dati) => { bo ...

"React Antd Element Type Validation Failure: received an unexpected object instead of the required element type. Issue

I recently upgraded from antd version 3.7.0 to the latest version 3.23.4 and now I'm encountering a strange error: Uncaught Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite co ...

Choose a shade from Three.js' color selector

Currently working on a project using A-FRAME, I am in the process of creating a menu for hololens. However, I am facing some challenges with a color picker. I have developed a color picker (link: Color picker) and my goal is to select a color and have it d ...

Split the string into individual parts and enclose each part in HTML using JavaScript

Currently, I am utilizing a content editable div to create tags. Upon pressing the return key, my objective is to select the preceding text (excluding the prior tags) and transform it into a new tag. The format for a tag will be enclosed within . For insta ...

Unable to receive Ajax response

My current programming setup involves using a combination of JavaScript and PHP to implement an Ajax code. However, at this point in time, the outcome is showing up as undefined. To circumvent this issue, I have resorted to utilizing localStorage to trans ...

Remove an element from a mapping of type <String,String> in Javascript

Question! How can I remove a specific element from this JavaScript object by its ID? [ "{\"id\":\"b00a3a47-783a-4af5-90d9-59c4deb7a9e3\",\"notes\":\"sdfsdf\",\"recordType\":0}", "{\"id\": ...

Implementing functions on React component classes

Recently, I decided to convert a slideshow from w3s schools into a React component. The process involved changing all the functions into methods on the class and setting the initial state to display the first slide. However, upon clicking the buttons or do ...

An error of type 'TypeError' has occurred, where it is unable to access the property 'render' of an undefined element in

I'm using a function in my controller to render the "result" in my "home-page" view, which is calling my model to execute the query. exports.searchNoms = (req, res) => { getDatabaseModel.searchNoms(req).then(function(result) { console.l ...

Can anyone provide guidance on how to calculate the total sum of a JavaScript array within an asynchronous function?

Currently, I am working with Angularjs Protractor for end-to-end testing and faced an issue while trying to calculate the sum of values in a column. Although I am able to print out each value within the loop successfully, I am struggling to figure out ho ...