top of page

Our blog / post

Writer's pictureVKL

How Add View Counter on WIX Dynamic Page

To add a view on a Wix dynamic page, you can follow these steps

How Add View Counter on WIX Dynamic Page
See code below

First, you will need to create a new database collection in Wix.


  • Go to your site editor, click on the "Database" button in the left-hand menu, and then click on "Create a Collection".

  • Give your collection a name, such as "Page Views", and add a field for "Page URL" and a field for "Views" (both as text fields).

  1. Next, go to the page where you want to add the view counter and click on "Add" in the left-hand menu. Select "Database" and then choose the collection you just created. Drag and drop a "Repeater" onto the page.

  2. In the "Repeater Settings" panel, select "Connect a Dataset" and choose the collection you just created. Then, select the fields you want to display (in this case, "Page URL" and "Views").

  3. In the page code, add the following code snippet to increment the view count whenever the page is visited:



This code uses Wix's built-in wixData API to query the "Page Views" collection and increment the view count for the current page's URL. If the page has not been visited before, a new record will be added to the collection with a view count of 1.


How to Add View Counter on WIX Dynamic Page
View counter on lawyer library dynamic page

  1. Finally, preview your site and visit the page where you added the view counter. You should see the view count increment each time you refresh the page.

  2. If you want to display the view count on your page, you can add a text element to the repeater and connect it to the "Views" field. This will display the current view count for each page in the collection.

  3. You can also customize the view counter to fit the design of your site. For example, you can change the color or font of the text element, or add an icon next to it.

  4. Keep in mind that the view counter will only work for dynamic pages that are connected to the "Page Views" collection. If you have multiple dynamic pages on your site, you will need to repeat the steps above for each page.

  5. Finally, you may want to consider adding a limit to the view count to prevent users from artificially inflating the count. For example, you can set a limit of one view per user per day, or use a more sophisticated system based on IP addresses or cookies.

  6. Another option to consider is adding a view count to pages that are not dynamic. For example, you can add a view count to a blog post or a product page by using a similar approach to the one outlined above. Instead of using the "Page URL" field, you would use a unique identifier for each post or product (such as an ID or slug).

  7. You can also use the view count data to create custom analytics reports or to track the popularity of your content over time. For example, you can create a chart that shows the total number of views for each page in your "Page Views" collection, or you can calculate the average time spent on each page based on the view count and the duration of the user's session.

  8. If you want to make the view count more prominent on your site, you can consider adding a widget or badge that displays the total number of views for your site or for specific pages. Wix offers several third-party integrations that allow you to add custom widgets and badges to your site, or you can create your own using HTML and JavaScript.


171 views

Related Posts

See All

Comentarios

Obtuvo 0 de 5 estrellas.
Aún no hay calificaciones

Agrega una calificación
bottom of page