• Remember to address to the Bug Tracking guidelines and to follow the instructions in the post ticket template.
  • Welcome to the Chevereto User Community!

    Here, users from all over the world come together to learn, share, and collaborate on everything related to Chevereto. It's a place to exchange ideas, ask questions, and help improve the software.

    Please keep in mind:

    • This community is user-driven. Always be polite and respectful to others.
    • Support development by purchasing a Chevereto license, which also gives you priority support.
    • Go further by joining the Community Subscription for even faster response times and to help sustain this space
  • Chevereto Support CLST

    Support response

    Support checklist

    • Got a Something went wrong message? Read this guide and provide the actual error. Do not skip this.
    • Confirm that the server meets the System Requirements
    • Check for any available Hotfix - your issue could be already reported/fixed
    • Read documentation - It will be required to Debug and understand Errors for a faster support response

Confirmed Views are not counted when using the listing viewer

Version
4.4.0
PHP version
8.2
Database driver
MySQL
Database version
8.4
Web browser
Brave

donniewr

Chevereto Member
Image and video views are not counted when the listing viewer is enabled. Views are only incremented when the image link is opened directly.


Unexpected result

Inaccurate views.

This is particularly a problem when your website is not an image host but rather a gallery site. Users, especially on mobile, are unlikely to open the direct link of an image.
 
Last edited:
I have a fix for this bug that involves editing json.php and add a new case, and adding a script in the footer (custom_hooks).
 
## Fix (2 changes)

### 1. Server-side: app/legacy/routes/json.php Copy it in app/legacy/routes/overrides/json.php

A) Add the sessionVar import — find this line near the top:

PHP:
use function Chevereto\Vars\session;

Add this line right after it:

PHP:
use function Chevereto\Vars\sessionVar;

B) Add the view action handler — find this case block:

PHP:
            case 'like':
            case 'dislike':

Add this block directly before case 'like'::

PHP:
            case 'view':
                $viewId = decodeID($REQUEST['view']['id'] ?? '');
                if ($viewId <= 0) {
                    throw new Exception('Invalid request', 403);
                }
                if (! isset(session()['image_view_stock'])) {
                    sessionVar()->put('image_view_stock', []);
                }
                if (! in_array($viewId, session()['image_view_stock'])) {
                    Image::getSingle($viewId, true);
                    $addValue = session()['image_view_stock'];
                    $addValue[] = $viewId;
                    sessionVar()->put('image_view_stock', $addValue);
                }
                $json_array['status_code'] = 200;
                $json_array['success'] = [
                    'message' => 'View tracked',
                    'code' => 200,
                ];

                break;

### 2. Client-side: content/legacy/themes/Peafowl/custom_hooks/footer.php

Create (or overwrite) the file content/legacy/themes/Peafowl/custom_hooks/footer.php
with the following content:

HTML:
<script>
window.addEventListener("load", function() {
    if (typeof CHV === "undefined" || !CHV.fn.listingViewer) return;
    function trackView(id) {
        if (!id) return;
        $.ajax({
            type: "POST",
            data: {
                action: "view",
                view: { id: id }
            }
        });
    }
    var origOpen = CHV.fn.listingViewer.open;
    CHV.fn.listingViewer.open = function($item) {
        origOpen.apply(this, arguments);
        if ($item.exists()) trackView($item.attr("data-id"));
    };
    var origBrowse = CHV.fn.listingViewer.browse;
    CHV.fn.listingViewer.browse = function(direction) {
        origBrowse.apply(this, arguments);
        var $item = this.getItem();
        if ($item && $item.exists()) trackView($item.attr("data-id"));
    };
});
</script>

## How it works

- The JS monkey-patches listingViewer.open (initial click) and listingViewer.browse
(next/prev) to send a POST request to /json with action=view.
- The PHP handler decodes the image ID, checks the session to avoid duplicate counting
(same logic as the single image page route), and calls Image::getSingle($id, true)
which increments image_views and updates stats.
- Each session only counts one view per image (via image_view_stock session array).
 
Back
Top