I'm following this tutorial trying to add tracking to a download button in a repeater dataset. I can't figure out why I'm getting this error on the bottom line getCurrentItem(). Any help would be appreciated.
import wixWindow from 'wix-window'; export function downloadButton_click(event) { wixWindow.trackEvent("CustomEvent", { "event": "Document Download", "eventCategory": "Downloads", "eventAction": "Download", "eventLabel": $w('#DownloadWPButton').getCurrentItem().title } ); }
Screenshot:
Here is my code now which appears to work. Thank you for the long explanation. Very helpful! I do have a dynamic dataset, it's literally called dynamicDataset. I was confused by the tutorial I was following thinking that because the button is linked to a dataset it would work to use DownloadWPButton, but that button is already linked to the dataset so by simply changing it to dynamicDataset it's collecting what is linked to that button. Again, thank you for the schooling. Very clear! @Jarod Dykstra @Velo-Ninja
import wixWindow from 'wix-window'; export function downloadButton_click(event) { wixWindow.trackEvent("Whitepaper Download", { "event": "Document Download", "eventCategory": "Downloads", "eventAction": "Download", "eventLabel": $w('#dynamicDataset').getCurrentItem().title } ); }
The getCurrentItem() only works on a Dataset element on the page.
https://www.wix.com/velo/reference/wix-dataset/dataset/getcurrentitem
Also is this button in a repeater? If so this would have to be done with the onItemReady for the repeater and then set the eventLabel to itemData.title.
https://www.wix.com/velo/reference/$w/repeater/onitemready