Skip to content

How Video Count Works

Daniel Neto edited this page Aug 19, 2023 · 9 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.

Once we find it in the database we will call it a Session and then we can identify the user

Adding the View

  • If a user hasn't viewed the video before (in the current session), a view is added.
  • If they've already viewed it, the system simply updates the time they last viewed the video.

Why is My Video View Not Added?

  1. Bot Access: If the system identifies a bot trying to access, it won't count as a view.

  2. No Video ID: If there isn't a valid video ID provided in the request, no view is added.

  3. Cookies Disabled: Our system relies on cookies to track views. If cookies are disabled, it won't register a view.

  4. Repeated Views in a Session: If a user has already viewed the video in their current session, it might not add another view. Instead, it may just update the last viewed time.

How to Troubleshoot

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