-
Notifications
You must be signed in to change notification settings - Fork 976
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 identifies a bot trying to access, it won't count as a view.
-
No Video ID: If there isn't a valid video ID provided in the request, no view is added.
-
Cookies Disabled: Our system relies on cookies to track views. If cookies are disabled, it won't register a view.
-
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.
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;
}
});