I have a dynamic page connected to a dataset.
The dynamic page having a bottom to download a file.
I want to count the numbers of clicks (store the number of clicks in the dataset and updated based on the clicks).
I almost tried everything … I can’t save the clicks, it’s reset after refreshing the page!
Please help me with a code (simple and easy to use) that gives the ability to my dataset to store and retrieve the number of clicks.
Thank you
I used the below code but the counting won’t save the clicks in the required column. Any help/suggestion, please.
Also, can you suggest to me a website provider (Not Wix) who provides such simple tools to the user so I can get rid of this Wix!
import wixData from ‘wix-data’ ;
import {session} from ‘wix-storage’ ;
$w.onReady( function () {
//if there is a value saved in the session set the text to it
if (session.getItem( “click” )){
$w( ‘#text92’ ).text = session.getItem( ‘click’ )
}
});
export function button1_click(event) {
//to add one to the original value
let count = parseInt($w( ‘#text92’ ).text, 10 ) + 1
$w( ‘#text92’ ).text = count.toString()
//to inset it in the collectin
let toInsert = {
“click” : count
};
// insert to collection
wixData.insert( “Items” , toInsert)
// update session value
session.setItem( “click” , count)
}
Hello, you should perhaps better use SAVE instead of INSERT.
https://www.wix.com/corvid/reference/wix-data/save
Thank you russian-dima.
I still have the same problem when using the Save option (the counted clicks still adding new rows in the dataset!)
This is the counting system of my page here…
https://russian-dima.wixsite.com/meinewebsite
function viewCounter (parameter) {
let visitCounter = $w('#dataset1').getCurrentItem().views
if (visitCounter ===0) {visitCounter = 1}
else {visitCounter = visitCounter+1}
$w("#dataset1").setFieldValue("views", visitCounter)
$w("#dataset1").save()
console.log(visitCounter)
}
export function BTNgo_click(event) {console.log($w('#dataset1').getCurrentItem().contentLink1)
storeLocal()
viewCounter()
wixLocation.to($w('#dataset1').getCurrentItem().contentLink1)
}
Based on a dynamic page.
Perhaps you can use it too.
Hello! Was this code helpful?
I don’t understand this code
Please help out
Please open your own post and describe your issue.
You can link this post to your own if it has similarity with your own post.