Views counter

Hello everyone,
I need to create a view counter for my dynamic pages. How can i do that? the wix counter app can’t see that this is a dynamic page.
and if so, is there a chance to count it with unique views per day (1 ip = 1 view, per day)
even views counter services will work for me. thanks.

1 Like

Hi,
You can achieve that with code, in the site code’s onReady function check if the browser already viewed the site today (you can do that with wix-storage ), if he haven’t viewed (the current date doesn’t exist in the local storage) save in the local storage the date and update the number of views in a database.

Good luck :slight_smile:

It there any code that i can put?
I don’t really familiar with the wix code system.
Thank you.

Could I achieve this with Videos?

@roce45 @james-rondon-jr

Here is the code you want to use :slight_smile:

import wixLocation from ‘wix-location’;

export function btnSubmit_click(event) {
$w(“#yourdataset”).setFieldValue(“views”, 0);

$w("#yourdataset").save()   
  .then( (item) => { 
    wixLocation.to(`/home`); 
} );   

}

function laggedEvents() {

const currentItem = $w(“#yourdataset”).getCurrentItem();
let viewCount = currentItem.views + 1; // iterate the view counter by one
$w(“#yourdataset”).setFieldValue(“views”,viewCount); // set ‘views’ to the new value
$w(‘#yourdataset’).save(); // make sure dataset is set to read and write

}

$w.onReady( function () {

$w("#yourdataset").onReady( () => { 

    setTimeout(laggedEvents,1000); 

}); 

});

@profhaaae

import wixLocation from ‘wix-location’;

export function btnSubmit_click(event) {
$w(“#yourdataset”).setFieldValue(“views”, 0);

$w("#yourdataset").save()   
  .then( (item) => { 
    wixLocation.to(`/home`); 
} );   

}

function laggedEvents() {

const currentItem = $w(“#yourdataset”).getCurrentItem();
let viewCount = currentItem.views + 1; // iterate the view counter by one
$w(“#yourdataset”).setFieldValue(“views”,viewCount); // set ‘views’ to the new value
$w(‘#yourdataset’).save(); // make sure dataset is set to read and write

}

$w.onReady( function () {

$w("#yourdataset").onReady( () => { 

    setTimeout(laggedEvents,1000); 

}); 

});

Hi James, I replied to you with the code you want to use. I am personally doing this for videos on my dynamic page. It doesn’t matter what content it is for, the view counts for the page. Hope I was helpful :slight_smile:

@danyminko Good News is I have got it to work, but I want to add it to each video on the same Dynamic Page and have the View Counts on each of them be different from the other view counts, I’ll give you an example: If I go into my video 1, then it adds from 0 Views to 1 View for Video 1, the only problem is when I go into another Video of mine video 2, it takes that 1 View and carries it over while adding another View, so now instead of 1 View for the specific video, it says 2 Views now for Video 2, I don’t want the same number of views on all of my videos, I want Unique Views.

@james-rondon-jr Hmmm. My videos on my page didn’t seem to have that problem as far as I can remember. Is it possible that you have two videos on one page?

I have to be honest I didn’t come up with this code. I believe I got it from here . You can contact the team to help you, hopefully it all works out. Best of luck.

@notDany thanks for helping me anyway, I‘ve contacted them and I will see what they can do for me, hope you have a good one, also no I didn’t add two videos on one page, they have their own dynamic url

@Or is there any way you can write out the code with that example for us, I tried the other one and it didn’t work for me quite well.

Thank you very much i been looking every where for this feature even youtube google and all but wanks really happy
:relieved: