Skip to content

Commit 0c6425d

Browse files
Merge pull request #38 from newrelic/set-user-id-in-ads
fix: Added set user id for ads and handle skipped Ad
2 parents fe3e16d + a786ead commit 0c6425d

File tree

9 files changed

+30
-41
lines changed

9 files changed

+30
-41
lines changed

NRExoPlayerTracker/build.gradle

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,16 @@ plugins {
22
id 'com.android.library'
33
id 'maven-publish'
44
}
5-
65
android {
76
compileSdkVersion 33
8-
97
defaultConfig {
108
minSdkVersion 16
119
targetSdkVersion 33
1210
versionCode 6
13-
versionName "3.0.0"
11+
versionName "3.0.1"
1412
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1513
consumerProguardFiles "consumer-rules.pro"
1614
}
17-
1815
buildTypes {
1916
debug {
2017
minifyEnabled false
@@ -35,9 +32,7 @@ android {
3532
}
3633
namespace 'com.newrelic.videoagent.exoplayer'
3734
}
38-
3935
dependencies {
40-
4136
implementation 'androidx.appcompat:appcompat:1.2.0'
4237
implementation 'com.google.android.material:material:1.2.1'
4338
implementation project(path: ':NewRelicVideoCore')
@@ -46,7 +41,6 @@ dependencies {
4641
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
4742
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
4843
}
49-
5044
afterEvaluate {
5145
publishing {
5246
publications {

NRIMATracker/build.gradle

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,16 @@ plugins {
22
id 'com.android.library'
33
id 'maven-publish'
44
}
5-
65
android {
76
compileSdkVersion 33
8-
97
defaultConfig {
108
minSdkVersion 16
119
targetSdkVersion 33
1210
versionCode 6
13-
versionName "3.0.0"
11+
versionName "3.0.1"
1412
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1513
consumerProguardFiles "consumer-rules.pro"
1614
}
17-
1815
buildTypes {
1916
debug {
2017
minifyEnabled false
@@ -35,9 +32,7 @@ android {
3532
}
3633
namespace 'com.newrelic.videoagent.ima'
3734
}
38-
3935
dependencies {
40-
4136
implementation 'androidx.appcompat:appcompat:1.2.0'
4237
implementation 'com.google.android.material:material:1.3.0'
4338
implementation project(path: ':NewRelicVideoCore')
@@ -46,7 +41,6 @@ dependencies {
4641
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
4742
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
4843
}
49-
5044
afterEvaluate {
5145
publishing {
5246
publications {

NRIMATracker/src/main/java/com/newrelic/videoagent/ima/tracker/NRTrackerIMA.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public void onAdEvent(AdEvent adEvent) {
5050
sendStart();
5151
break;
5252
case COMPLETED:
53+
case SKIPPED:
5354
sendEnd();
5455
quartile = null;
5556
break;

NewRelicVideoCore/build.gradle

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@ android {
88
minSdkVersion 16
99
targetSdkVersion 33
1010
versionCode 9
11-
versionName "3.0.0"
12-
11+
versionName "3.0.1"
1312
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1413
consumerProguardFiles "consumer-rules.pro"
1514
}
16-
1715
buildTypes {
1816
debug {
1917
minifyEnabled false
@@ -34,11 +32,10 @@ android {
3432
}
3533
namespace 'com.newrelic.videoagent.core'
3634
}
37-
3835
dependencies {
3936
implementation 'androidx.appcompat:appcompat:1.1.0'
4037
implementation 'com.google.android.material:material:1.1.0'
41-
implementation 'com.newrelic.agent.android:android-agent:7.0.0'
38+
implementation 'com.newrelic.agent.android:android-agent:7.6.3'
4239
testImplementation 'junit:junit:4.+'
4340
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
4441
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

NewRelicVideoCore/src/main/java/com/newrelic/videoagent/core/NewRelicVideoAgent.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,23 @@ public NRTracker getAdTracker(Integer trackerId) {
136136
return null;
137137
}
138138
}
139+
140+
/**
141+
* Set userId.
142+
*
143+
* @param userId User Id.
144+
*/
145+
public void setUserId(String userId) {
146+
for (Integer trackerId : trackerPairs.keySet()) {
147+
NRTrackerPair pair = trackerPairs.get(trackerId);
148+
if (pair.getFirst() != null) {
149+
pair.getFirst().setAttribute("enduser.id", userId);
150+
}
151+
if (pair.getSecond() != null) {
152+
pair.getSecond().setAttribute("enduser.id", userId);
153+
}
154+
}
155+
}
156+
157+
139158
}

NewRelicVideoCore/src/main/java/com/newrelic/videoagent/core/model/NREventAttributes.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
public class NREventAttributes {
1111

1212
private Map<String, Map<String, Object>> attributeBuckets;
13-
private String userId;
1413

1514
/**
1615
* Ïnit a new event attributes model.
@@ -40,16 +39,6 @@ public void setAttribute(String key, Object value, String filter) {
4039
attributeBuckets.get(filter).put(key, value);
4140
}
4241

43-
/**
44-
* Set userId.
45-
*
46-
* @param userId User Id.
47-
*/
48-
public void setUserId(String userId) {
49-
this.userId = userId;
50-
setAttribute("enduser.id", userId, null);
51-
}
52-
5342
/**
5443
* Generate list of attributes for a given action.
5544
*

NewRelicVideoCore/src/main/java/com/newrelic/videoagent/core/tracker/NRTracker.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,6 @@ public void trackerReady() {
3939
sendVideoEvent(TRACKER_READY);
4040
}
4141

42-
/**
43-
* Set userId.
44-
*
45-
* @param userId User Id.
46-
*/
47-
public void setUserId(String userId) {
48-
eventAttributes.setUserId(userId);
49-
}
50-
5142
/**
5243
* Set custom attribute for all events.
5344
*

app/src/main/java/com/newrelic/nrvideoproject/VideoPlayer.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,12 @@ private void playVideo(String videoUrl) {
6565
tracker.setAttribute("contentTitle", "This is my test title", "CONTENT_START");
6666
tracker.setAttribute("contentIsLive", true, "CONTENT_START");
6767
tracker.setAttribute("myCustomAttr", "any value", "CONTENT_START");
68-
// Uncomment below to set userId
69-
tracker.setUserId("myUserId");
7068

7169
trackerId = NewRelicVideoAgent.getInstance().start(tracker);
7270

71+
// Set the user ID
72+
NewRelicVideoAgent.getInstance().setUserId("your_user_id");
73+
7374
Map<String, Object> attr = new HashMap<>();
7475
attr.put("myAttrStr", "Hello");
7576
attr.put("myAttrInt", 101);

app/src/main/java/com/newrelic/nrvideoproject/VideoPlayerAds.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ private void playVideo(String videoUrl) {
8989
playerView.setPlayer(player);
9090
adsLoader.setPlayer(player);
9191

92+
// Set the user ID
93+
NewRelicVideoAgent.getInstance().setUserId("your_user_id");
94+
9295
// Pass the player to the content tracker
9396
tracker.setPlayer(player);
9497

0 commit comments

Comments
 (0)