Permalink
Browse files

Merge pull request #874 from definitionstudio/master

Android/Analytics: add missing return value for setCustomVar, document method
  • Loading branch information...
2 parents 4dd4216 + cab0260 commit 4cb9f70fea136f30a349df58f914c0410adc1c2d @devgeeks devgeeks committed Nov 26, 2012
@@ -30,7 +30,7 @@ Using this plugin requires [PhoneGap Cordova library for Android](http://phonega
5. In your res/xml/config.xml file add the following line:
-<plugin name="GoogleAnalyticsTracker" value="com.phonegap.plugins.analytics.GoogleAnalyticsTracker" />
+ &lt;plugin name=&quot;GoogleAnalyticsTracker&quot; value=&quot;com.phonegap.plugins.analytics.GoogleAnalyticsTracker&quot; /&gt;
## Using the plugin ##
@@ -86,7 +86,25 @@ Sample use:
Sample use:
window.plugins.analytics.trackEvent("category", "action", "event", 1, function(){alert("Track: success");}, function(){alert("Track: failure");});
+
+<pre>
+/**
+ * Set a custom variable on Google Analytics
+ * @param index The slot for the custom variable
+ * @param label The name for the custom variable
+ * @param value The value for the custom variable
+ * @param scope The scope for the custom variable (optional)
+
+ * @param successCallback The success callback
+ * @param failureCallback The error callback
+ */
+
+ setCustomVar(index, label, value, scope, successCallback, failureCallback);
+</pre>
+
+Sample use:
+ window.plugins.analytics.setCustomVar(1, "type", "android", null, function(){alert("SetVar: success");}, function(){alert("SetVar: 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
Good practice will be manual dispatch and stop session. Add this code to your main activity:
@@ -55,6 +55,7 @@ public PluginResult execute(String action, JSONArray data, String callbackId) {
} else if (SET_CUSTOM_VARIABLE.equals(action)){
try {
setCustomVar(data.getInt(0), data.getString(1), data.getString(2), data.getInt(3));
+ result = new PluginResult(Status.OK);
} catch (JSONException e) {
result = new PluginResult(Status.JSON_EXCEPTION);
}
@@ -77,6 +78,7 @@ private void trackEvent(String category, String action, String label, int value)
}
private void setCustomVar(int index, String label, String value, int scope) {
- tracker.setCustomVar(index, label, value, scope);
+ if(scope > 0) tracker.setCustomVar(index, label, value, scope);
+ else tracker.setCustomVar(index, label, value);
}
}
@@ -68,6 +68,17 @@ Analytics.prototype.trackEvent = function(category, action, label, value, succes
]);
};
+/**
+ * Set a custom variable on Google Analytics
+ * @param index The slot for the custom variable
+ * @param label The name for the custom variable
+ * @param value The value for the custom variable
+ * @param scope The scope for the custom variable (optional)
+
+ * @param successCallback The success callback
+ * @param failureCallback The error callback
+ */
+
Analytics.prototype.setCustomVar = function(index, label, value, scope, successCallback, failureCallback){
return cordova.exec(
successCallback,

0 comments on commit 4cb9f70

Please sign in to comment.