jQuery onHandler return split of value

Gold Contributor
Gold Contributor
I am using an onHandler set from the web companion to get the value for a button - and it returns "window.open("https://url/link.asp?sku=123-4567-ABC890&version=Z28");". I really only want to see the SKU value returned. Is there a way I can do this with Tealium?
2 REPLIES 2

jQuery onHandler return split of value

Moderator
Moderator
Hi Annah, In the jQuery onHandler extension, select "JS Code" from the drop down when setting your data source, and do something like this: {code:javascript} jQuery(this).attr("href").match(/(?:sku\=)(.*)(?:&)/)[1]; {code} To explain each part of the expression in detail: This bit is a regular expression that will match the SKU value: {code:javascript} /(?:sku\=)(.*)(?:&)/ {code} ... but we want only the captured SKU, so we need to address the second part of the match array (index 1), hence: {code:javascript} (/(?:sku\=)(.*)(?:&)/)[1] // [1] will return the 2nd match from the regex {code} {code:javascript} jQuery(this).attr("href") {code} ...will return the URL of the item you clicked on, which I'm assuming is where the string you posted originally came from. I hope this helps - it's a bit tricky to explain without getting too verbose. Let me know if you have any questions! Craig.
Check out our new Swift integration library for iOS, macOS, tvOS and watchOS: https://github.com/Tealium/tealium-swift with updated
documentation https://community.tealiumiq.com/t5/Swift/tkb-p/swift.

jQuery onHandler return split of value

Gold Contributor
Gold Contributor
There isn't actually a href in the code - but I modified it to jQuery(this).attr("onclick").match and it works great. Thank you!!!
Public