Skip to content

Commit

Permalink
Analytics report event added. Will be dispatched every time the corre… (
Browse files Browse the repository at this point in the history
kaltura#193)

* Analytics report event added. Will be dispatched every time the corresponding analytics report sent to backend.

* Report events renamed to REPORT_SENT.
Removed unnecessary LogEvent from analytics
  • Loading branch information
AntonAFA authored Mar 28, 2017
1 parent 792165d commit 70ce186
Show file tree
Hide file tree
Showing 11 changed files with 193 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.kaltura.playkit.plugins;

import com.kaltura.playkit.PKEvent;

/**
* Created by anton.afanasiev on 27/03/2017.
*/

public class KalturaLiveStatsEvent implements PKEvent {

public enum Type {
REPORT_SENT
}

public static class KalturaLiveStatsReport extends KalturaLiveStatsEvent {

private long bufferTime;

public KalturaLiveStatsReport(long bufferTime) {
this.bufferTime = bufferTime;
}

public long getBufferTime() {
return bufferTime;
}
}


@Override
public Enum eventType() {
return Type.REPORT_SENT;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import android.util.Log;

import com.google.gson.JsonObject;
import com.kaltura.playkit.LogEvent;
import com.kaltura.playkit.MessageBus;
import com.kaltura.playkit.PKEvent;
import com.kaltura.playkit.PKLog;
Expand Down Expand Up @@ -207,7 +206,7 @@ private void stopLiveEvents() {
isLive = false;
}

private void sendLiveEvent(long bufferTime) {
private void sendLiveEvent(final long bufferTime) {
String sessionId = pluginConfig.has("sessionId") ? pluginConfig.getAsJsonPrimitive("sessionId").getAsString() : "";
String baseUrl = pluginConfig.has("baseUrl") ? pluginConfig.getAsJsonPrimitive("baseUrl").getAsString() : BASE_URL;
int partnerId = pluginConfig.has("partnerId") ? pluginConfig.getAsJsonPrimitive("partnerId").getAsInt() : 0;
Expand All @@ -222,7 +221,7 @@ private void sendLiveEvent(long bufferTime) {
@Override
public void onComplete(ResponseElement response) {
Log.d(TAG, "onComplete: " + isLive);
messageBus.post(new LogEvent(TAG + " " + isLive));
messageBus.post(new KalturaLiveStatsEvent.KalturaLiveStatsReport(bufferTime));
}
});
requestsExecutor.queue(requestBuilder.build());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.kaltura.playkit.plugins;

import com.kaltura.playkit.PKEvent;

/**
* Created by anton.afanasiev on 27/03/2017.
*/

public class KalturaStatsEvent implements PKEvent{

public enum Type {
REPORT_SENT
}

public static class KalturaStatsReport extends KalturaStatsEvent {

private String reportedEventName;

public KalturaStatsReport(String reportedEventName) {
this.reportedEventName = reportedEventName;
}

public String getReportedEventName() {
return reportedEventName;
}
}


@Override
public Enum eventType() {
return Type.REPORT_SENT;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -416,9 +416,9 @@ private void sendAnalyticsEvent(final KStatsEvent eventType) {
@Override
public void onComplete(ResponseElement response) {
log.d("onComplete send event: " + eventType.toString());
messageBus.post(new KalturaStatsEvent.KalturaStatsReport(eventType.toString()));
}
});
requestsExecutor.queue(requestBuilder.build());
messageBus.post(new LogEvent(TAG + " " + eventType.toString(), requestBuilder.build().getUrl()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.kaltura.playkit.plugins;

import com.kaltura.playkit.PKEvent;

/**
* Created by anton.afanasiev on 27/03/2017.
*/

public class PhoenixAnalyticsEvent implements PKEvent {

public enum Type {
REPORT_SENT
}

public static class PhoenixAnalyticsReport extends PhoenixAnalyticsEvent {

private String reportedEventName;

public PhoenixAnalyticsReport(String reportedEventName) {
this.reportedEventName = reportedEventName;
}

public String getReportedEventName() {
return reportedEventName;
}
}


@Override
public Enum eventType() {
return Type.REPORT_SENT;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import android.content.Context;

import com.google.gson.JsonObject;
import com.kaltura.playkit.LogEvent;
import com.kaltura.playkit.MessageBus;
import com.kaltura.playkit.OttEvent;
import com.kaltura.playkit.PKEvent;
Expand Down Expand Up @@ -195,12 +194,12 @@ protected void sendAnalyticsEvent(final PhoenixActionType eventType){
public void onComplete(ResponseElement response) {
if (response.isSuccess() && response.getError() != null && response.getError().getCode().equals("4001")){
messageBus.post(new OttEvent(OttEvent.OttEventType.Concurrency));
messageBus.post(new PhoenixAnalyticsEvent.PhoenixAnalyticsReport(eventType.toString()));
}
log.d("onComplete send event: ");
}
});
requestsExecutor.queue(requestBuilder.build());
messageBus.post(new LogEvent(TAG + " " + eventType.toString(), requestBuilder.build().getBody()));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import android.content.Context;

import com.google.gson.JsonObject;
import com.kaltura.playkit.LogEvent;
import com.kaltura.playkit.OttEvent;
import com.kaltura.playkit.PKLog;
import com.kaltura.playkit.PKPlugin;
Expand Down Expand Up @@ -62,11 +61,11 @@ protected void sendAnalyticsEvent(final PhoenixActionType eventType){
public void onComplete(ResponseElement response) {
if (response.isSuccess() && response.getResponse().toLowerCase().contains("concurrent")){
messageBus.post(new OttEvent(OttEvent.OttEventType.Concurrency));
messageBus.post(new TVPapiAnalyticsEvent.TVPapiAnalyticsReport(eventType.toString()));
}
log.d("onComplete send event: ");
}
});
requestsExecutor.queue(requestBuilder.build());
messageBus.post(new LogEvent(TAG + " " + eventType.toString(), requestBuilder.build().getBody()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.kaltura.playkit.plugins;

import com.kaltura.playkit.PKEvent;

/**
* Created by anton.afanasiev on 27/03/2017.
*/

public class TVPapiAnalyticsEvent implements PKEvent {

public enum Type {
REPORT_SENT
}

public static class TVPapiAnalyticsReport extends TVPapiAnalyticsEvent {

private String reportedEventName;

public TVPapiAnalyticsReport(String reportedEventName) {
this.reportedEventName = reportedEventName;
}

public String getReportedEventName() {
return reportedEventName;
}
}


@Override
public Enum eventType() {
return Type.REPORT_SENT;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.kaltura.playkit.plugins.Youbora;

import com.kaltura.playkit.LogEvent;
import com.kaltura.playkit.MessageBus;
import com.kaltura.playkit.PKEvent;
import com.kaltura.playkit.PKLog;
Expand Down Expand Up @@ -48,8 +47,7 @@ private void onEvent(PlayerEvent.StateChanged event) {
default:
break;
}
log.d(event.newState.toString());
messageBus.post(new LogEvent(TAG + " " + event.newState.toString()));
sendReportEvent(event);
}

private PKEvent.Listener mEventListener = new PKEvent.Listener() {
Expand Down Expand Up @@ -108,8 +106,7 @@ public void onEvent(PKEvent event) {
case ALL_ADS_COMPLETED:
break;
}
log.d(event.eventType().name());
messageBus.post(new LogEvent(TAG + " " + ((AdEvent) event).type.toString()));
sendReportEvent(event);
} else if (event instanceof PlayerEvent) {
switch (((PlayerEvent) event).type) {
case STATE_CHANGED:
Expand All @@ -119,7 +116,6 @@ public void onEvent(PKEvent event) {
}
};


public void startMonitoring(Object player) {
log.d("startMonitoring");
super.startMonitoring(player);
Expand Down Expand Up @@ -157,4 +153,10 @@ public Double getAdDuration() {
public String getAdPlayerVersion() {
return PlayKitManager.CLIENT_TAG;
}

private void sendReportEvent(PKEvent event) {
String reportedEventName = event.eventType().name();
log.d(reportedEventName);
messageBus.post(new YouboraEvent.YouboraReport(reportedEventName));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.kaltura.playkit.plugins.Youbora;

import com.kaltura.playkit.PKEvent;

/**
* Created by anton.afanasiev on 27/03/2017.
*/

public class YouboraEvent implements PKEvent {

public enum Type {
REPORT_SENT
}

public static class YouboraReport extends YouboraEvent{

private String reportedEventName;

public YouboraReport(String reportedEventName) {
this.reportedEventName = reportedEventName;
}

public String getReportedEventName() {
return reportedEventName;
}
}


@Override
public Enum eventType() {
return Type.REPORT_SENT;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.kaltura.playkit.plugins.Youbora;

import com.kaltura.playkit.LogEvent;
import com.kaltura.playkit.MessageBus;
import com.kaltura.playkit.PKEvent;
import com.kaltura.playkit.PKLog;
Expand Down Expand Up @@ -54,12 +53,11 @@ public YouboraLibraryManager(Map<String, Object> options, MessageBus messageBus,
protected void init() {
super.init();
this.pluginName = PlayKitManager.CLIENT_TAG;
this.pluginVersion = "5.3.0-"+ PlayKitManager.CLIENT_TAG;
this.pluginVersion = "5.3.0-" + PlayKitManager.CLIENT_TAG;
ViewManager.setMonitoringInterval(MONITORING_INTERVAL);
}

private void onEvent(PlayerEvent.StateChanged event) {
log.d(event.newState.toString());
switch (event.newState) {
case READY:
if (isBuffering && !isFirstPlay) {
Expand All @@ -76,8 +74,7 @@ private void onEvent(PlayerEvent.StateChanged event) {
default:
break;
}
log.d(event.newState.toString());
messageBus.post(new LogEvent(TAG + " " + event.newState.toString()));
sendReportEvent(event);
}

private PKEvent.Listener mEventListener = new PKEvent.Listener() {
Expand Down Expand Up @@ -122,7 +119,7 @@ public void onEvent(PKEvent event) {
}
break;
case PLAYING:
if (isFirstPlay){
if (isFirstPlay) {
isFirstPlay = false;
playHandler();
}
Expand All @@ -140,18 +137,16 @@ public void onEvent(PKEvent event) {
default:
break;
}
log.d(event.eventType().name());
if (((PlayerEvent) event).type != STATE_CHANGED){
messageBus.post(new LogEvent(TAG + " " + ((PlayerEvent) event).type.toString()));
if (((PlayerEvent) event).type != STATE_CHANGED) {
sendReportEvent(event);
}
} else if (event instanceof AdEvent){
} else if (event instanceof AdEvent) {
onAdEvent((AdEvent) event);
}
}
};

private void onAdEvent(AdEvent event) {
log.d(event.type.toString());
switch (event.type) {
case STARTED:
ignoringAdHandler();
Expand All @@ -163,10 +158,10 @@ private void onAdEvent(AdEvent event) {
default:
break;
}
log.d(event.type.toString());
messageBus.post(new LogEvent(TAG + " " + event.type.toString()));
sendReportEvent(event);
}


public void startMonitoring(Object player) {
log.d("startMonitoring");
super.startMonitoring(player);
Expand Down Expand Up @@ -199,7 +194,7 @@ public String getPlayerVersion() {
}

public String getResource() {
return this.mediaUrl;
return this.mediaUrl;
}

public Double getPlayhead() {
Expand All @@ -210,4 +205,10 @@ public Boolean getIsLive() {
return mediaConfig != null && (mediaConfig.getMediaEntry().getMediaType() == PKMediaEntry.MediaEntryType.Live);
}

private void sendReportEvent(PKEvent event) {
String reportedEventName = event.eventType().name();
log.d(reportedEventName);
messageBus.post(new YouboraEvent.YouboraReport(reportedEventName));
}

}

0 comments on commit 70ce186

Please sign in to comment.