Skip to content

Commit 662eec6

Browse files
author
John Hunt
committed
Flurry provider implementation
1 parent 70476ce commit 662eec6

File tree

9 files changed

+630
-2
lines changed

9 files changed

+630
-2
lines changed

analyticskit/src/main/java/com/busybusy/analyticskit_android/AnalyticsKit.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public void logEvent(AnalyticsEvent event)
113113
* Marks the end of a timed event
114114
* @param eventName the unique name of the event that has finished
115115
*/
116-
public void endTimedEvent(@NonNull String eventName)
116+
public void endTimedEvent(@NonNull String eventName) throws IllegalStateException
117117
{
118118
if (this.timedEvents != null)
119119
{

answers-provider/src/main/java/com/busybusy/answers_provider/AnswersProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ private void ensureTimeTrackingMaps()
126126
* @see AnalyticsKitProvider
127127
*/
128128
@Override
129-
public void endTimedEvent(@NonNull AnalyticsEvent timedEvent)
129+
public void endTimedEvent(@NonNull AnalyticsEvent timedEvent) throws IllegalStateException
130130
{
131131
ensureTimeTrackingMaps();
132132

flurry-provier/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

flurry-provier/build.gradle

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
* Copyright 2016 Busy, LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
apply plugin: 'com.android.library'
18+
apply plugin: 'com.github.dcendents.android-maven'
19+
20+
android {
21+
compileSdkVersion rootProject.ext.compileSdkVersion
22+
buildToolsVersion rootProject.ext.buildToolsVersion
23+
24+
defaultConfig {
25+
minSdkVersion rootProject.ext.minSdkVersion
26+
targetSdkVersion rootProject.ext.targetSdkVersion
27+
versionCode 1
28+
versionName "0.1.0"
29+
}
30+
buildTypes {
31+
release {
32+
debuggable false
33+
minifyEnabled false
34+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
35+
}
36+
debug {
37+
debuggable true
38+
minifyEnabled false
39+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
40+
}
41+
}
42+
43+
testOptions {
44+
unitTests.returnDefaultValues = true
45+
}
46+
}
47+
48+
dependencies {
49+
compile fileTree(dir: 'libs', include: ['*.jar'])
50+
provided project(':analyticskit')
51+
compile 'com.android.support:support-annotations:23.2.1'
52+
compile 'com.flurry.android:analytics:6.2.0'
53+
54+
testCompile 'junit:junit:4.12'
55+
testCompile 'org.assertj:assertj-core:1.7.1'
56+
testCompile "org.robolectric:robolectric:3.0"
57+
testCompile "org.mockito:mockito-core:1.10.19"
58+
59+
testCompile "org.powermock:powermock-api-mockito:1.6.4"
60+
testCompile "org.powermock:powermock-module-junit4:1.6.4"
61+
}
62+
63+
task sourcesJar(type: Jar) {
64+
from android.sourceSets.main.java.srcDirs
65+
classifier = 'sources'
66+
}
67+
68+
task javadoc(type: Javadoc) {
69+
failOnError false
70+
source = android.sourceSets.main.java.sourceFiles
71+
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
72+
}
73+
74+
task javadocJar(type: Jar, dependsOn: javadoc) {
75+
classifier = 'javadoc'
76+
from javadoc.destinationDir
77+
}
78+
79+
artifacts {
80+
archives sourcesJar
81+
archives javadocJar
82+
}

flurry-provier/flurry-provier.iml

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module external.linked.project.id=":flurry-provier" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="AnalyticsKit-Android" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
3+
<component name="FacetManager">
4+
<facet type="android-gradle" name="Android-Gradle">
5+
<configuration>
6+
<option name="GRADLE_PROJECT_PATH" value=":flurry-provier" />
7+
</configuration>
8+
</facet>
9+
<facet type="android" name="Android">
10+
<configuration>
11+
<option name="SELECTED_BUILD_VARIANT" value="debug" />
12+
<option name="SELECTED_TEST_ARTIFACT" value="_android_test_" />
13+
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
14+
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
15+
<afterSyncTasks>
16+
<task>generateDebugSources</task>
17+
</afterSyncTasks>
18+
<option name="ALLOW_USER_CONFIGURATION" value="false" />
19+
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
20+
<option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
21+
<option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/src/main/res" />
22+
<option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
23+
<option name="LIBRARY_PROJECT" value="true" />
24+
</configuration>
25+
</facet>
26+
</component>
27+
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="false">
28+
<output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
29+
<output-test url="file://$MODULE_DIR$/build/intermediates/classes/test/debug" />
30+
<exclude-output />
31+
<content url="file://$MODULE_DIR$">
32+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
33+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/debug" isTestSource="false" generated="true" />
34+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
35+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
36+
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
37+
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/debug" type="java-resource" />
38+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/androidTest/debug" isTestSource="true" generated="true" />
39+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/androidTest/debug" isTestSource="true" generated="true" />
40+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/androidTest/debug" isTestSource="true" generated="true" />
41+
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/androidTest/debug" isTestSource="true" generated="true" />
42+
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/androidTest/debug" type="java-test-resource" />
43+
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/androidTest/debug" type="java-test-resource" />
44+
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
45+
<sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
46+
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
47+
<sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
48+
<sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
49+
<sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
50+
<sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
51+
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/res" type="java-test-resource" />
52+
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/resources" type="java-test-resource" />
53+
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/assets" type="java-test-resource" />
54+
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/aidl" isTestSource="true" />
55+
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/java" isTestSource="true" />
56+
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/jni" isTestSource="true" />
57+
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/rs" isTestSource="true" />
58+
<sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
59+
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
60+
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
61+
<sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
62+
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
63+
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
64+
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
65+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
66+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
67+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
68+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
69+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
70+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
71+
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
72+
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
73+
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
74+
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
75+
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
76+
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
77+
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
78+
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
79+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/animated-vector-drawable/23.2.1/jars" />
80+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/appcompat-v7/23.2.1/jars" />
81+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/23.2.1/jars" />
82+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-vector-drawable/23.2.1/jars" />
83+
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
84+
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
85+
</content>
86+
<orderEntry type="jdk" jdkName="Android API 23 Platform" jdkType="Android SDK" />
87+
<orderEntry type="sourceFolder" forTests="false" />
88+
<orderEntry type="library" exported="" name="animated-vector-drawable-23.2.1" level="project" />
89+
<orderEntry type="library" exported="" name="support-v4-23.2.1" level="project" />
90+
<orderEntry type="library" exported="" name="support-annotations-23.2.1" level="project" />
91+
<orderEntry type="library" exported="" name="support-vector-drawable-23.2.1" level="project" />
92+
<orderEntry type="library" exported="" name="appcompat-v7-23.2.1" level="project" />
93+
<orderEntry type="library" exported="" scope="TEST" name="hamcrest-core-1.3" level="project" />
94+
<orderEntry type="library" exported="" scope="TEST" name="junit-4.12" level="project" />
95+
</component>
96+
</module>

flurry-provier/proguard-rules.pro

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in /Sources/android_sdk_mac_x86/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# Add any project specific keep options here:
11+
12+
# If your project uses WebView with JS, uncomment the following
13+
# and specify the fully qualified class name to the JavaScript interface
14+
# class:
15+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16+
# public *;
17+
#}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!--
2+
~ Copyright 2016 Busy, LLC
3+
~
4+
~ Licensed under the Apache License, Version 2.0 (the "License");
5+
~ you may not use this file except in compliance with the License.
6+
~ You may obtain a copy of the License at
7+
~
8+
~ http://www.apache.org/licenses/LICENSE-2.0
9+
~
10+
~ Unless required by applicable law or agreed to in writing, software
11+
~ distributed under the License is distributed on an "AS IS" BASIS,
12+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
~ See the License for the specific language governing permissions and
14+
~ limitations under the License.
15+
-->
16+
17+
<manifest package = "com.busybusy.flurry_provider" />
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
/*
2+
* Copyright 2016 Busy, LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.busybusy.flurry_provider;
18+
19+
import android.support.annotation.NonNull;
20+
import android.support.annotation.Nullable;
21+
22+
import com.busybusy.analyticskit_android.AnalyticsEvent;
23+
import com.busybusy.analyticskit_android.AnalyticsKitProvider;
24+
import com.busybusy.analyticskit_android.Providers;
25+
import com.flurry.android.FlurryAgent;
26+
27+
import java.util.HashMap;
28+
import java.util.Map;
29+
30+
/**
31+
* Implements Flurry as a provider to use with {@link com.busybusy.analyticskit_android.AnalyticsKit}
32+
* <p/>
33+
* <b>Important</b>: It is a violation of Flurry’s TOS to record personally identifiable information such as a user’s UDID,
34+
* email address, and so on using Flurry. If you have a user login that you wish to associate with your session and
35+
* event data, you should use the SetUserID function. If you do choose to record a user id of any type within a parameter,
36+
* you must anonymize the data using a hashing function such as MD5 or SHA256 prior to calling the method.
37+
* <p/>
38+
* Refer to the Flurry documentation here:
39+
* <a href="https://developer.yahoo.com/flurry/docs/analytics/gettingstarted/events/android/">Flurry Documentation</a>
40+
*
41+
* @author John Hunt on 3/21/16.
42+
*/
43+
public class FlurryProvider implements AnalyticsKitProvider
44+
{
45+
final int ATTRIBUTE_LIMIT = 10;
46+
47+
/**
48+
* @see AnalyticsKitProvider
49+
*/
50+
@Override
51+
public int getType()
52+
{
53+
return Providers.FLURRY;
54+
}
55+
56+
/**
57+
* @see AnalyticsKitProvider
58+
*/
59+
@Override
60+
public void sendEvent(@NonNull AnalyticsEvent event) throws IllegalStateException
61+
{
62+
Map<String, String> eventParams = stringifyParameters(event.getAttributes());
63+
64+
if (event.isTimed())
65+
{
66+
// start the Flurry SDK event timer for the event
67+
if (eventParams != null)
68+
{
69+
FlurryAgent.logEvent(event.name(), eventParams, true);
70+
}
71+
else
72+
{
73+
FlurryAgent.logEvent(event.name(), true);
74+
}
75+
}
76+
else
77+
{
78+
if (eventParams != null)
79+
{
80+
FlurryAgent.logEvent(event.name(), eventParams);
81+
}
82+
else
83+
{
84+
FlurryAgent.logEvent(event.name());
85+
}
86+
}
87+
}
88+
89+
/**
90+
* @see AnalyticsKitProvider
91+
*/
92+
@Override
93+
public void endTimedEvent(@NonNull AnalyticsEvent timedEvent)
94+
{
95+
FlurryAgent.endTimedEvent(timedEvent.name());
96+
}
97+
98+
/**
99+
* Converts a {@code HashMap<String, Object>} to {@code HashMap<String, String>}
100+
* @param attributeMap the map of attributes attached to the event
101+
* @return the String map of parameters. Returns {@code null} if no parameters are attached to the event.
102+
*/
103+
@Nullable
104+
HashMap<String, String> stringifyParameters(HashMap<String, Object> attributeMap) throws IllegalStateException
105+
{
106+
HashMap<String, String> flurryMap = null;
107+
108+
// convert the attributes to to <String, String> to appease the Flurry API
109+
if (attributeMap != null && attributeMap.size() > 0)
110+
{
111+
if (attributeMap.size() > ATTRIBUTE_LIMIT)
112+
{
113+
throw new IllegalStateException("Flurry events are limited to " + ATTRIBUTE_LIMIT + " attributes");
114+
}
115+
116+
flurryMap = new HashMap<>();
117+
for (String key : attributeMap.keySet())
118+
{
119+
flurryMap.put(key, attributeMap.get(key).toString());
120+
}
121+
}
122+
123+
return flurryMap;
124+
}
125+
}

0 commit comments

Comments
 (0)