# How to make a view counter?

**URL:** <https://forum.wixstudio.com/t/how-to-make-a-view-counter/9250>\
**Category:** Ask the community\
**Tags:** code, question\
**Created:** [March 7, 2021, 9:37am UTC](https://forum.wixstudio.com/t/how-to-make-a-view-counter/9250 "2021-03-07T09:37:21Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![meliauab](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/meliauab/32/16226_2.png) [@meliauab](https://forum.wixstudio.com/u/meliauab)\
**Post date:** [March 7, 2021, 9:37am UTC](https://forum.wixstudio.com/t/how-to-make-a-view-counter/9250/1 "2021-03-07T09:37:21Z")

</div>

Hello, I am new to Wix Velo and would like to create a view counter for a dynamic page.

---

<div class="post-metadata">

**Author:** ![alexobc](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/alexobc/32/26207_2.png) [@alexobc](https://forum.wixstudio.com/u/alexobc)\
**Post date:** [March 8, 2021, 4:42am UTC](https://forum.wixstudio.com/t/how-to-make-a-view-counter/9250/2 "2021-03-08T04:42:50Z")

</div>

See this post: [https://www.wix.com/velo/forum/community-discussion/views-counter](https://www.wix.com/velo/forum/community-discussion/views-counter)

---

<div class="post-metadata">

**Author:** ![CODE-NINJA](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-ninja/32/110588_2.png) [@CODE-NINJA](https://forum.wixstudio.com/u/CODE-NINJA)\
**Post date:** [March 8, 2021, 3:34pm UTC](https://forum.wixstudio.com/t/how-to-make-a-view-counter/9250/3 "2021-03-08T15:34:07Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![meliauab](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/meliauab/32/16226_2.png) [@meliauab](https://forum.wixstudio.com/u/meliauab)\
**Post date:** [March 9, 2021, 8:27am UTC](https://forum.wixstudio.com/t/how-to-make-a-view-counter/9250/4 "2021-03-09T08:27:09Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![CODE-NINJA](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-ninja/32/110588_2.png) [@CODE-NINJA](https://forum.wixstudio.com/u/CODE-NINJA)\
**Post date:** [March 9, 2021, 7:22pm UTC](https://forum.wixstudio.com/t/how-to-make-a-view-counter/9250/5 "2021-03-09T19:22:13Z")

</div>

Hello just a quick reply, without testing. This could be the way how to do it…

```javascript
$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…

```javascript
$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.

---

<div class="post-metadata">

**Author:** ![bilonii](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/bilonii/32/15984_2.png) [@bilonii](https://forum.wixstudio.com/u/bilonii)\
**Post date:** [May 26, 2022, 7:31pm UTC](https://forum.wixstudio.com/t/how-to-make-a-view-counter/9250/6 "2022-05-26T19:31:59Z")

</div>

@russian-dima is possible to make this for unique viewers and not total? 🙂

---

<div class="post-metadata">

**Author:** ![Certified\_Code](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/certified_code/32/80179_2.png) [@Certified\_Code](https://forum.wixstudio.com/u/Certified_Code)\
**Post date:** [May 27, 2022, 12:06am UTC](https://forum.wixstudio.com/t/how-to-make-a-view-counter/9250/7 "2022-05-27T00:06:46Z")

</div>

@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)

---

<div class="post-metadata">

**Author:** ![bilonii](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/bilonii/32/15984_2.png) [@bilonii](https://forum.wixstudio.com/u/bilonii)\
**Post date:** [May 27, 2022, 5:44am UTC](https://forum.wixstudio.com/t/how-to-make-a-view-counter/9250/8 "2022-05-27T05:44:05Z")

</div>

you have Code please? I have o plan with Wix Code. Thank you 🙂

---

<div class="post-metadata">

**Author:** ![Certified\_Code](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/certified_code/32/80179_2.png) [@Certified\_Code](https://forum.wixstudio.com/u/Certified_Code)\
**Post date:** [May 28, 2022, 2:37am UTC](https://forum.wixstudio.com/t/how-to-make-a-view-counter/9250/9 "2022-05-28T02:37:14Z")

</div>

@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.
