Learn business growth with Google Analytics 4 Forums Google Analytics 4 How can I track hover events for multiple elements in this code? Reply To: How can I track hover events for multiple elements in this code?

  • Jackson

    Member
    27 May 2023 at 7:42 pm

    Sure, I can surely point you in the right direction. For your first problem, the code is actually capable of tracking more than one image at a time. The ‘selector’ parameter in the function can accept multiple selectors separated by commas. So, instead of just one class, you could send in multiple like ‘img.afg-celebrate, img.anotherClass, img.yetAnotherClass’.

    Your second problem is a bit tricky but not impossible to solve either. The ‘alt’ text can indeed be used to select an element. Just like we used classes for selection, we can use attributes like ‘alt’. However, you’ll have to know the exact ‘alt’ text to select the correct element. The selector could look like this: ‘img[alt=”Your Alt Text”]’. Make sure to replace ‘Your Alt Text’ with the actual alt text of the image you’re trying to track. Happy coding!