Skip to content

How Video Count Works

Daniel Neto edited this page Aug 19, 2023 · 10 revisions

Video Platform View Mechanism

Our video platform classifies videos into two main types:

  • Embedded Videos: Videos sourced from other platforms but displayed within our ecosystem.
  • Native Videos: Videos that are uploaded, stored, and played directly from our server.

Native Videos

For Native Videos, the viewing metric is pretty straightforward - a view is counted each time the play button is pressed.

Embedded Videos

For Embedded Videos, it's a bit more complex. Since we don't control the play button directly, we count a view each time a page containing the embedded video is loaded.

How We Count Views

Every 30 seconds, our system pings back to log a view. To avoid duplicated views, each ping checks:

  1. User's ID.
  2. Session ID (This doesn't work in iframes).
  3. Client's IP address.

If the video has already been accessed before, instead of logging a new view, we update how much of the video has been viewed.

How to Troubleshot

To see if this mechanism is working, inspect your browser's console log. You should be looking for a request to:

https://yoursite.com/objects/videoAddViewCount.json.php

A successful response will resemble:

{
    "seconds_watching_video": 12,
    "status": true,
    "count": 38,
    "videos_id": 42217,
    "countHTML": "38",
    "resp": 436090,
    "users_id": 1,
    "session_id": "211f9b7fb59300c08195e02f8296deac"
}

Expected Response Image

If your response looks different, there might be a hiccup in the view count mechanism.

External Requests

Payload Example:

URL to send request to:

https://yoursite.com/objects/videoAddViewCount.json.php?id=4416&currentTime=0&seconds_watching_video=0&PHPSESSID=ea0ga3uh3ej0hdlplbs706nva3

Payload parameters:

  • PHPSESSID: ea0ga3uh3ej0hdlplbs706nva3
  • id: 4416
  • currentTime: Your current position in the video in seconds.
  • seconds_watching_video: Duration of video playback since the last request.

For PHPSESSID, fetch it from the last request's response. For currentTime and seconds_watching_video, update as per your requirements.

JS code example

    var seconds_watching_video_to_send = seconds_watching_video;
    seconds_watching_video = 0; // reset the seconds_watching_video
    $.ajax({
        url: 'https://yoursite.com/objects/videoAddViewCount.json.php',
        method: 'POST',
        data: {
            id: videos_id,
            currentTime: currentTime,
            seconds_watching_video: seconds_watching_video_to_send
        },
        success: function(response) {
            PHPSESSID = response.session_id;
        }
    });

Clone this wiki locally