Hello, I am new to Wix Velo and would like to create a view counter for a dynamic page.
Your question is to general to give the right answer.
There are many ways of how to code a “view-counter” and it also depends on which elements you are using in your project.
-Do you use DATASETS?
-Do you use REPEATERS or TABLES or DYNAMIC-PAGES ?
Yes I am using dataset and dynamic page, and I would like the counter to count the number of people going to the dynamic page.
Hello just a quick reply, without testing. This could be the way how to do it…
$w.onReady(()=>{
$w("#dynamicDataset").onReady(()=>{
$w('#myButton').onClick(()=>{
let currentItem = $w("#dynamicDataset").getCurrentItem();
let viewCount = currentItem.views + 1;
$w("#dynamicDataset").setFieldValue("views",viewCount);
$w('#dynamicDataset').save()
});
});
});
You will have to improve the code.
Or even like this…
$w.onReady(()=>{
$w("#dynamicDataset").onReady(()=>{
let currentItem = $w("#dynamicDataset").getCurrentItem();
let viewCount = currentItem.views + 1;
$w("#dynamicDataset").setFieldValue("views",viewCount);
$w('#dynamicDataset').save()
});
});
—> “views” is a column in your DB where you will store all the views for every of dynamic pages.
@russian-dima is possible to make this for unique viewers and not total?
@michaelstrauss307 For unique viewer, use wix-storage → local to store the user entry to prevent duplicates. OR by user IP (there are Velo examples to get user IP)
you have Code please? I have o plan with Wix Code. Thank you
@michaelstrauss307 We recommend checking out some velo examples and learn code.
If you have no idea with code, please visit Wix marketplace to hire a developer.