Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions Application/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ apply from: "../artifacts.gradle"
repositories {
// Uncomment when using CrashlyticsComponent
//maven { url 'https://maven.fabric.io/public' }

// Uncomment when using TealiumAnalyticsComponent
// maven { url "http://maven.tealiumiq.com/android/releases/" }
}

buildscript {
Expand Down Expand Up @@ -83,10 +86,10 @@ dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile 'junit:junit:4.12'
androidTestCompile 'org.mockito:mockito-core:1.9.5'
androidTestCompile ('com.android.support.test:rules:0.5') {
androidTestCompile('com.android.support.test:rules:0.5') {
exclude group: 'com.android.support', module: 'support-annotations'
}
androidTestCompile ('com.android.support.test:runner:0.5') {
androidTestCompile('com.android.support.test:runner:0.5') {
exclude group: 'com.android.support', module: 'support-annotations'
}
androidTestCompile 'com.google.dexmaker:dexmaker:1.2'
Expand All @@ -100,4 +103,6 @@ dependencies {
compile project(':PassThroughAdsComponent')
compile project(':PassThroughLoginComponent')
compile project(':LoggerAnalyticsComponent')
// Uncomment when using TealiumAnalyticsComponent
// compile project(':TealiumAnalyticsComponent')
}
6 changes: 5 additions & 1 deletion Application/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ include ':app',
':DataLoader',
':Utils',
// Uncomment when using ComScore Analytics
//':comscore',
// ':comscore',
/* Interfaces */
':PurchaseInterface',
':AuthInterface',
Expand All @@ -36,6 +36,8 @@ include ':app',
':AMZNMediaPlayerComponent',
':PassThroughLoginComponent',
':LoggerAnalyticsComponent'
// Uncomment when using Tealium Analytics
// ':TealiumAnalyticsComponent'

/* Frameworks */
project(':TVUIComponent').projectDir = new File(rootProject.projectDir, '../TVUIComponent/lib')
Expand Down Expand Up @@ -63,3 +65,5 @@ project(':PassThroughLoginComponent').projectDir = new File(rootProject.projectD
project(':LoggerAnalyticsComponent').projectDir = new File(rootProject.projectDir, '../LoggerAnalyticsComponent')
// Uncomment when using ComScore Analytics
//project(':comscore').projectDir = new File(rootProject.projectDir, '../ComScoreAnalyticsComponent/libs/comscore')
// Uncomment when using Tealium Analytics
//project(':TealiumAnalyticsComponent').projectDir = new File(rootProject.projectDir, '../TealiumAnalyticsComponent')
60 changes: 60 additions & 0 deletions TealiumAnalyticsComponent/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
apply plugin: 'com.android.library'

repositories {
mavenCentral()

maven {
url "http://maven.tealiumiq.com/android/releases/"
}
}

android {
compileSdkVersion 28
buildToolsVersion "28.0.0"


defaultConfig {
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':ModuleInterface')
compile project(':AnalyticsInterface')

testCompile('org.robolectric:robolectric:3.0') {
exclude group: 'commons-logging', module: 'commons-logging'
exclude group: 'org.apache.httpcomponents', module: 'httpclient'
}

compile 'com.tealium:library:5.5.1'
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:1.10.19'
testCompile 'org.powermock:powermock:1.6.6'
testCompile 'org.powermock:powermock-module-junit4:1.6.6'
testCompile 'org.powermock:powermock-module-junit4-rule:1.6.6'
testCompile 'org.powermock:powermock-api-mockito:1.6.6'
testCompile 'org.powermock:powermock-classloading-xstream:1.6.6'

androidTestCompile 'junit:junit:4.12'
androidTestCompile 'com.android.support.test:rules:0.5'
androidTestCompile('com.android.support.test:runner:0.5') {
exclude module: 'support-annotations'
}

}
11 changes: 11 additions & 0 deletions TealiumAnalyticsComponent/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.amazon.analytics.tealium">
<application
android:allowBackup="true"
android:supportsRtl="true">

<meta-data android:name="AMZNAP@TealiumAnalytics"
android:value="IAnalytics@com.amazon.analytics.tealium.TealiumAnalyticsImplCreator" />

</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
package com.amazon.analytics.tealium;

import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.util.Log;

import com.amazon.analytics.AnalyticsTags;
import com.amazon.analytics.CustomAnalyticsTags;
import com.amazon.analytics.IAnalytics;
import com.tealium.library.Tealium;

import java.util.HashMap;
import java.util.concurrent.TimeUnit;

import static com.tealium.library.DataSources.Key.VIDEO_ID;
import static com.tealium.library.DataSources.Key.VIDEO_LENGTH;
import static com.tealium.library.DataSources.Key.VIDEO_MILESTONE;
import static com.tealium.library.DataSources.Key.VIDEO_NAME;
import static com.tealium.library.DataSources.Key.VIDEO_PLAYHEAD;

public class TealiumAnalytics implements IAnalytics {

private static final String TAG = TealiumAnalytics.class.getSimpleName();
private Tealium mTealium;
private CustomAnalyticsTags mCustomAnalyticsTags = new CustomAnalyticsTags();

/**
* {@inheritDoc}
*/
@Override
public void configure(Context context) {
Application application = (Application) context.getApplicationContext();
Tealium.Config config = Tealium.Config.create(application, "<account-name>", "<profile-name>", "<environment>");
mTealium = Tealium.createInstance("<instance-name>", config);

Log.d(TAG, "Tealium Analytics initialized");
}

/**
* {@inheritDoc}
*/
@Override
public void collectLifeCycleData(Activity activity, boolean active) {
Log.d(TAG, "Lifecycle is not supported for this platform.");
}

/**
* {@inheritDoc}
*
* @param data Map of Strings to Objects that represent data that is necessary for the tracked
*/
@Override
public void trackAction(HashMap<String, Object> data) {
HashMap<String, Object> contextData = new HashMap<>();

// Get the action name
String action = String.valueOf(data.get(AnalyticsTags.ACTION_NAME));
contextData.put(AnalyticsTags.ACTION_NAME, action);

// Get the attributes map
HashMap<String, Object> contextDataObjectMap = (HashMap<String, Object>) data.get(AnalyticsTags.ATTRIBUTES);

if (action != null && contextDataObjectMap != null) {
for (String key : contextDataObjectMap.keySet()) {
String value = String.valueOf(contextDataObjectMap.get(key));
Long videoDuration;

switch (key) {
case AnalyticsTags.ATTRIBUTE_VIDEO_CURRENT_POSITION:
contextData.put(VIDEO_PLAYHEAD, value);
break;
case AnalyticsTags.ATTRIBUTE_VIDEO_ID:
contextData.put(VIDEO_ID, value);
break;
case AnalyticsTags.ATTRIBUTE_VIDEO_DURATION:
videoDuration = (Long) contextDataObjectMap.get(AnalyticsTags.ATTRIBUTE_VIDEO_DURATION);
contextData.put(VIDEO_LENGTH, getVideoDuration(videoDuration));
break;
case AnalyticsTags.ATTRIBUTE_VIDEO_SECONDS_WATCHED:
videoDuration = (Long) contextDataObjectMap.get(AnalyticsTags.ATTRIBUTE_VIDEO_DURATION);
if (videoDuration != null) {
contextData.put(VIDEO_MILESTONE, getMilestone(videoDuration, Long.valueOf(value)));
}
break;
case AnalyticsTags.ATTRIBUTE_TITLE:
contextData.put(VIDEO_NAME, value);
break;
default:
contextData.put(key, value);
break;
}
}

mTealium.trackEvent(mCustomAnalyticsTags.getCustomTag(action),
mCustomAnalyticsTags.getCustomTags(contextData));
Log.d(TAG, "Track action " + action + "with attributes " + contextData);
}
}

@Override
public void trackState(String screen) {
mTealium.trackView(screen, null);
Log.d(TAG, "Track screen: " + screen);
}

@Override
public void trackCaughtError(String errorMessage, Throwable t) {
mTealium.trackEvent(errorMessage, null);
Log.d(TAG, "Tracking caught error: " + errorMessage);
}

private String getVideoDuration(Long videoDuration) {
return String.valueOf(TimeUnit.MILLISECONDS.toSeconds(videoDuration));
}

private String getMilestone(Long videoDuration, Long secondsWatched) {
int percentage = (int) ((double) secondsWatched / videoDuration * 100);
return String.valueOf(percentage);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.amazon.analytics.tealium;

import com.amazon.analytics.IAnalytics;
import com.amazon.android.module.IImplCreator;

public class TealiumAnalyticsImplCreator implements IImplCreator<IAnalytics> {

/**
* {@inheritDoc}
*/
@Override
public IAnalytics createImpl() {
return new TealiumAnalytics();
}
}
2 changes: 2 additions & 0 deletions TealiumAnalyticsComponent/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<resources>
</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.amazon.analytics.tealium;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;

import static org.junit.Assert.assertTrue;

/**
* Tests the {@link TealiumAnalyticsImplCreator} class
*/
@RunWith(RobolectricTestRunner.class)
public class TealiumAnalyticsImplCreatorTest {

private TealiumAnalyticsImplCreator mTealiumAnalyticsImplCreator;

@Before
public void setUp() {
mTealiumAnalyticsImplCreator = new TealiumAnalyticsImplCreator();
}

@After
public void tearDown() {
mTealiumAnalyticsImplCreator = null;
}

@Test
public void createImpl() {
assertTrue("createImpl() should create a TealiumAnalyticsObject", mTealiumAnalyticsImplCreator.createImpl() instanceof TealiumAnalytics);
}
}
Loading