@daniel3614
Like Jarod already mentioned → getCurrentItem only works on DATASETS!
You are doing it on a → BUTTON! ← That will not work!
"eventLabel":$w('#DownloadWPButton').getCurrentItem().title
Comparing the code from the tutorial:
import wixWindow from 'wix-window';
export function downloadButton_click(event) {
wixWindow.trackEvent("CustomEvent", {
"event": "Document Download",
"eventCategory": "Downloads",
"eventAction": "Download",
"eventLabel": $w('#dataset1').getCurrentItem().title
} );
}
With your code → you surely recognize the difference:
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
} );
}
Delete you event-connection of your button in the property-panel & try this one…
import wixWindow from 'wix-window';
$w.onReady(async function() {console.log("Page is ready!");
$w('#dataset1').onReady(()=>{console.log("Dataset is ready!");
$w('#downloadButton').onClick((event)=>{
console.log("Button " + event.target.id + " clicked!");
start_Tracking();
});
});
});
function start_Tracking() {
wixWindow.trackEvent("CustomEvent", {
"event": "Document Download",
"eventCategory": "Downloads",
"eventAction": "Download",
"eventLabel": $w('#dataset1').getCurrentItem().title
});
}
But even, with this correction, it seems that still is somwthing not right or missing!
We have here a normal → DATASET ← and we are using → getCurrentItem().
Normaly getCurrentItem-methods are used on → DYNAMIC-DATASETS.
In This case your REPEATER must be connected in the property-panel with the DATASET, if getCurrentItem() shall work like expected.
Another version would be to go the CODING way → using REPEATERS → onItemReady
import wixWindow from 'wix-window';
$w.onReady(async function() {console.log("Page is ready!");
$w('#REPEATER').onItemReady(($item, itemData, index)=>{
$w('#downloadButton').onClick((event)=>{
console.log("Button " + event.target.id + " clicked!");
wixWindow.trackEvent("CustomEvent", {
"event": "Document Download",
"eventCategory": "Downloads",
"eventAction": "Download",
"eventLabel": itemData.title
});
});
});
});
This was also mentioned by Jarod already.
@Jarod Dykstra → to your question…
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.
I think you will already know the answer → Because no → DYNAMIC-DATASET exists, the button must be inside REPEATER, else this would not work at all.
There multiple possible scenarios…
- Using dynamic dataset.
- Using a repeater.
- Using a table.
- Using a gallary.
--------------------------------------------- not sure-----------------------------------------------------------------
- Even the usage of Multi-State-Boxes & Slide-Shows would be possible…but this for you may would have to use the next provided function → getItems().
--------------------------------------------- not sure-----------------------------------------------------------------
Another possible solution could also be the usage of this one…