On an Activity Registration web page, we have numerous "Add to Cart" buttons depending upon how many activities are available. How can we track clicks w/o adding an onHandler to each individual button?

Gold Contributor
Gold Contributor
jQuery onHandler Extension for multiple buttons
3 REPLIES 3

On an Activity Registration web page, we have numerous "Add to Cart" buttons depending upon how many activities are available. How can we track clicks w/o adding an onHandler to each individual button?

Employee Emeritus
Mark, do the buttons have a shared identifier like a class and a unique attribute that identifies each button? If so, then something like this: for the jQuery identifier: {code:javascript} .cart-shared-class {code} and then for a variable called "foo", use 'JS Code' in the "To" selector and a jQuery statement along these lines: {code:javascript} jQuery('this').attr("unique_attribute_for_this_button") {code} Because the identifier is a shared class across the objects, the jQuery onHandler will fire every time that object is clicked and then assuming that "unique_attribute_for_this_button" is actually unique per button and is mapped to "foo" and "foo" is mapped correctly in your tags then whenever the jQuery onHandler runs a unique value is sent to foo and on to your tags.

On an Activity Registration web page, we have numerous "Add to Cart" buttons depending upon how many activities are available. How can we track clicks w/o adding an onHandler to each individual button?

Tealium Employee
In addition to Clint's statement, usually clients are looking to grab the href or text of the element clicked. this.href will grab the link of what was clicked this.innerHTML will grab any text within the link clicked such as if it reads "Click to learn about xyz" These are just two examples of what you can gather. The "this." refers to the action that is currently in progress. And as Clint describes above you can set a variable such as "click_href" to use "JS Code" with input of "this.href" and then the link href is passed as a parameter in the UDO.

On an Activity Registration web page, we have numerous "Add to Cart" buttons depending upon how many activities are available. How can we track clicks w/o adding an onHandler to each individual button?

Gold Contributor
Gold Contributor
Thanks Clint and Dan. I've been bumped to a different project for now, but will try this when it comes back around.
Public