Skip to content

Commit

Permalink
Merge pull request #3 from ebaschiera/feature/piwik-tracking
Browse files Browse the repository at this point in the history
Feature/piwik tracking
  • Loading branch information
ebaschiera committed Jul 19, 2015
2 parents 77b8d70 + 845f11b commit f9e9b2e
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 8 deletions.
3 changes: 2 additions & 1 deletion app/app.iml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="TripleCamel" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<module external.linked.project.id=":app" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="TripleCamel" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="android-gradle" name="Android-Gradle">
<configuration>
Expand Down Expand Up @@ -87,6 +87,7 @@
<orderEntry type="jdk" jdkName="Android API 21 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="appcompat-v7-21.0.3" level="project" />
<orderEntry type="library" exported="" name="PiwikAndroidSdk" level="project" />
<orderEntry type="library" exported="" name="support-v4-21.0.3" level="project" />
<orderEntry type="library" exported="" name="support-annotations-21.0.3" level="project" />
</component>
Expand Down
7 changes: 4 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "com.ebaschiera.triplecamel"
minSdkVersion 10
targetSdkVersion 21
versionCode 2
versionName "1.0.1"
versionCode 4
versionName "1.0.3"
}
buildTypes {
release {
Expand All @@ -20,7 +20,8 @@ android {
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.android.support:support-v4:21.0.3'
compile files('libs/PiwikAndroidSdk.jar')
}
Binary file added app/libs/PiwikAndroidSdk.jar
Binary file not shown.
7 changes: 5 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ebaschiera.triplecamel"
android:versionCode="2"
android:versionName="1.0.1">
android:versionCode="4"
android:versionName="1.0.3">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

<application
android:name="TripleCamelApp"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public class MainActivity extends ActionBarActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
((TripleCamelApp) getApplication()).getTracker()
.trackScreenView("/info_screen", "Info screen");
}

/**
Expand Down
10 changes: 8 additions & 2 deletions app/src/main/java/com/ebaschiera/triplecamel/ShareActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import android.content.Intent;
import android.content.Context;
import android.net.Uri;
import android.util.Log;
import android.content.pm.*;
import android.widget.Toast;
import java.util.regex.*;
Expand All @@ -21,6 +20,9 @@ public class ShareActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

((TripleCamelApp) getApplication()).getTracker()
.trackScreenView("/share", "Share intent");

// Get the intent that started this activity
Intent intent = getIntent();
Uri data = intent.getData();
Expand All @@ -37,6 +39,7 @@ protected void onCreate(Bundle savedInstanceState) {
}
if (amazon_share_url == "") {
//return a warning and stop the intent
((TripleCamelApp) getApplication()).getTracker().trackEvent("share", "failed", "label", 1);
Context context = getApplicationContext();
String text = getResources().getString(R.string.amazon_link_not_matching);
int duration = Toast.LENGTH_LONG;
Expand All @@ -55,11 +58,13 @@ protected void onCreate(Bundle savedInstanceState) {
List<ResolveInfo> activities = packageManager.queryIntentActivities(webIntent, 0);
boolean isIntentSafe = activities.size() > 0;

// Start an activity if it's safe
// Start an activity if it's safe
if (isIntentSafe) {
((TripleCamelApp) getApplication()).getTracker().trackEvent("share", "successful", "label", 1);
startActivity(webIntent);
finish();
} else {
((TripleCamelApp) getApplication()).getTracker().trackEvent("share", "failed", "label", 1);
Context context = getApplicationContext();
String text = getResources().getString(R.string.no_web_browser);
int duration = Toast.LENGTH_LONG;
Expand All @@ -69,6 +74,7 @@ protected void onCreate(Bundle savedInstanceState) {
}
} else {
//return a warning and stop the intent
((TripleCamelApp) getApplication()).getTracker().trackEvent("share", "failed", "label", 1);
Context context = getApplicationContext();
String text = getResources().getString(R.string.amazon_link_not_matching);
int duration = Toast.LENGTH_LONG;
Expand Down
20 changes: 20 additions & 0 deletions app/src/main/java/com/ebaschiera/triplecamel/TripleCamelApp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.ebaschiera.triplecamel;

import org.piwik.sdk.PiwikApplication;

/**
* Created by ebaschiera on 19/07/15.
*/
public class TripleCamelApp extends PiwikApplication {

@Override
public String getTrackerUrl() {
return "http://ebaschiera.com/piwik/piwik.php";
}

@Override
public Integer getSiteId() {
return 1;
}

}

0 comments on commit f9e9b2e

Please sign in to comment.