Count Button Clicks

hi tony.
Make a database named “EbookDownloads”
add a row to it named “totalDownloads”
on your button click

In onClick function :

 let toInsert =  await{
 "totalDownloads" : 1
};

await wixData.insert("EbookDownloads", toInsert)
    .catch( (err) => {
 let errorMsg = err;
    } );
 

if you click on your database and add hook add a beforeinsert hook.
this will create a function named Edownloads_beforeInsert() in
backend/data.js
change the code to this code:

 export async function EbookDownloads_beforeInsert(item, context) {
let incrementalNr;
 await wixData.query("EbookDownloads")
    .descending("totalDownloads")
    .find()
    .then((result) => {
 let r = result.items;
 if (r[0] === undifined)
 {
 //do nothing, number 1 will be added as said in the page code
 }
 else {
 
incrementalNr = r[0].totalDownloads; // adds the founded //number to incrementalNr
 item.totalDownloads = incrementalNr + 1 //adds 1 to it.
 
        }
 
    })
 //console.log(incrementalNr)
 //TODO: write your code here...
 return item;
 }