-
Notifications
You must be signed in to change notification settings - Fork 1k
How Video Count Works
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.
For Native Videos, the viewing metric is pretty straightforward - a view is counted each time the play button is pressed.
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.
Every 30 seconds, our system pings back to log a view. To avoid duplicated views, each ping checks:
- User's ID.
- Session ID (This doesn't work in iframes).
- Client's IP address.
Once we find it in the database we will call it a Session and then we can identify the user
- 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.
-
Bot Access: If the system detects that the request comes from a bot, the view will not be counted.
-
Missing Video ID: A valid video ID must be included in the request. Without it, the system cannot register the view.
-
Cookies Blocked or Disabled: Our system relies on cookies to track views. If cookies are disabled in the browser, or if the video is embedded on a different domain where cross-site cookies are blocked by the browser, the view may not be registered.
-
Repeated Views in the Same Session: If a user already watched the video during their current session, the system may not add another view. Instead, it may only update the last viewed timestamp.
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"
}
If your response looks different, there might be a hiccup in the view count mechanism.
URL to send request to:
https://yoursite.com/objects/videoAddViewCount.json.php?id=4416¤tTime=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.
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;
}
});