Permalink
Browse files

[Analytics Android] update for phonegap 2.0

  • Loading branch information...
1 parent 034727b commit a518cf4a43c4a0e70601b48e6e3e6c5fce81bdcb @broderix broderix committed Aug 14, 2012
@@ -10,25 +10,25 @@ A simple use case would be:
## Adding the Plugin to your project ##
-Using this plugin requires [Android PhoneGap](http://github.com/phonegap/phonegap-android).
+Using this plugin requires [PhoneGap Cordova library for Android](http://phonegap.com/download) version 1.9 or above.
-1. To install the plugin, move www/analytics.js to your project's www folder and include a reference to it in your html file after phonegap.js.
+1. To install the plugin, move www/analytics.js to your project's www folder and include a reference to it in your html file after cordova.js.
- &lt;script type="text/javascript" charset="utf-8" src="phonegap.js"&gt;&lt;/script&gt;<br/>
+ &lt;script type="text/javascript" charset="utf-8" src="cordova.js"&gt;&lt;/script&gt;<br/>
&lt;script type="text/javascript" charset="utf-8" src="analytics.js"&gt;&lt;/script&gt;
2. Create a directory within your project called "src/com/phonegap/plugins/analytics" and copy src/com/phonegap/plugins/analytics/GoogleAnalyticsTracker.java into it.
-3. Add the following activity to your AndroidManifest.xml file. It should be added inside the &lt;application&gt; tag.
+3. Add the following activity to your AndroidManifest.xml file if it not already there. It should be added inside the &lt;application&gt; tag.
&lt;activity android:name="com.phonegap.DroidGap" android:label="@string/app_name"&gt;<br/>
&lt;intent-filter&gt;<br/>
&lt;/intent-filter&gt;<br/>
&lt;/activity&gt;
-4. Copy "lib/libGoogleAnalytics.jar" into the libs directory within your project. You will also need to right click on this file in eclipse and add the jar to the build path.
+4. Download [GoogleAnalytics](https://developers.google.com/analytics/devguides/collection/android/resources) library (tested with 1.4.2) and copy "lib/libGoogleAnalytics.jar" into the libs directory within your project. You will also need to right click on this file in eclipse and add the jar to the build path.
-5. In your res/xml/plugins.xml file add the following line:
+5. In your res/xml/config.xml file add the following line:
<plugin name="GoogleAnalyticsTracker" value="com.phonegap.plugins.analytics.GoogleAnalyticsTracker" />
@@ -85,14 +85,18 @@ Sample use:
Sample use:
- window.plugins.analytics.trackPageView("category", "action", "event", 1, function(){alert("Track: success");}, function(){alert("Track: failure");});
+ window.plugins.analytics.trackEvent("category", "action", "event", 1, function(){alert("Track: success");}, function(){alert("Track: failure");});
Please keep in mind that these methods, as in any other plugin, are ready to be invoked only after '[deviceready](http://docs.phonegap.com/phonegap_events_events.md.html#deviceready)' event has been fired
## RELEASE NOTES ##
+### AUG, 14, 2012 ###
+
+* Added suppport for Cordova 1.9 and above
+
### AUG, 10, 2011 ###
* Added event tracking
@@ -3,7 +3,7 @@
id = "http://phonegap.com/plugins/Analytics"
version = "1.0"
platform = "Android"
- min = "1.6"
+ min = "1.9"
max = "">
<name short="Analytics 1.0">
Binary file not shown.
@@ -7,15 +7,14 @@
package com.phonegap.plugins.analytics;
+import org.apache.cordova.api.Plugin;
+import org.apache.cordova.api.PluginResult;
+import org.apache.cordova.api.PluginResult.Status;
import org.json.JSONArray;
import org.json.JSONException;
import android.util.Log;
-import com.phonegap.api.Plugin;
-import com.phonegap.api.PluginResult;
-import com.phonegap.api.PluginResult.Status;
-
public class GoogleAnalyticsTracker extends Plugin {
public static final String START = "start";
public static final String TRACK_PAGE_VIEW = "trackPageView";
@@ -38,7 +37,7 @@ public PluginResult execute(String action, JSONArray data, String callbackId) {
result = new PluginResult(Status.OK);
} catch (JSONException e) {
result = new PluginResult(Status.JSON_EXCEPTION);
- }
+ }
} else if (TRACK_PAGE_VIEW.equals(action)) {
try {
trackPageView(data.getString(0));
@@ -61,12 +60,12 @@ public PluginResult execute(String action, JSONArray data, String callbackId) {
}
} else {
result = new PluginResult(Status.INVALID_ACTION);
- }
+ }
return result;
}
private void start(String accountId) {
- tracker.start(accountId, DISPATCH_INTERVAL, this.ctx);
+ tracker.startNewSession(accountId, DISPATCH_INTERVAL, this.cordova.getActivity());
}
private void trackPageView(String key) {
@@ -9,7 +9,7 @@
/**
* Constructor
*/
-function Analytics() {
+var Analytics = function () {
}
/**
@@ -20,7 +20,7 @@ function Analytics() {
* @param failureCallback The error callback
*/
Analytics.prototype.start = function(accountId, successCallback, failureCallback) {
- return PhoneGap.exec(
+ return cordova.exec(
successCallback,
failureCallback,
'GoogleAnalyticsTracker',
@@ -36,7 +36,7 @@ Analytics.prototype.start = function(accountId, successCallback, failureCallback
* @param failureCallback The error callback
*/
Analytics.prototype.trackPageView = function(key, successCallback, failureCallback) {
- return PhoneGap.exec(
+ return cordova.exec(
successCallback,
failureCallback,
'GoogleAnalyticsTracker',
@@ -56,7 +56,7 @@ Analytics.prototype.trackPageView = function(key, successCallback, failureCallba
*/
Analytics.prototype.trackEvent = function(category, action, label, value, successCallback, failureCallback){
- return PhoneGap.exec(
+ return cordova.exec(
successCallback,
failureCallback,
'GoogleAnalyticsTracker',
@@ -70,7 +70,7 @@ Analytics.prototype.trackEvent = function(category, action, label, value, succes
};
Analytics.prototype.setCustomVar = function(index, label, value, scope, successCallback, failureCallback){
- return PhoneGap.exec(
+ return cordova.exec(
successCallback,
failureCallback,
'GoogleAnalyticsTracker',
@@ -86,10 +86,11 @@ Analytics.prototype.setCustomVar = function(index, label, value, scope, successC
/**
* Load Analytics
*/
-PhoneGap.addConstructor(function() {
- PhoneGap.addPlugin('analytics', new Analytics());
-
-// @deprecated: No longer needed in PhoneGap 1.0. Uncomment the addService code for earlier
-// PhoneGap releases.
-// PluginManager.addService("GoogleAnalyticsTracker", "com.phonegap.plugins.analytics.GoogleAnalyticsTracker");
-});
+
+if(!window.plugins) {
+ window.plugins = {};
+}
+
+if (!window.plugins.analytics) {
+ window.plugins.analytics = new Analytics();
+}

0 comments on commit a518cf4

Please sign in to comment.