Skip to content

Commit 4cb9f70

Browse files
committed
Merge pull request phonegap#874 from definitionstudio/master
Android/Analytics: add missing return value for setCustomVar, document method
2 parents 4dd4216 + cab0260 commit 4cb9f70

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

Android/Analytics/2.0/README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Using this plugin requires [PhoneGap Cordova library for Android](http://phonega
3030

3131
5. In your res/xml/config.xml file add the following line:
3232

33-
<plugin name="GoogleAnalyticsTracker" value="com.phonegap.plugins.analytics.GoogleAnalyticsTracker" />
33+
&lt;plugin name=&quot;GoogleAnalyticsTracker&quot; value=&quot;com.phonegap.plugins.analytics.GoogleAnalyticsTracker&quot; /&gt;
3434

3535
## Using the plugin ##
3636

@@ -86,7 +86,25 @@ Sample use:
8686
Sample use:
8787

8888
window.plugins.analytics.trackEvent("category", "action", "event", 1, function(){alert("Track: success");}, function(){alert("Track: failure");});
89+
90+
<pre>
91+
/**
92+
* Set a custom variable on Google Analytics
93+
* @param index The slot for the custom variable
94+
* @param label The name for the custom variable
95+
* @param value The value for the custom variable
96+
* @param scope The scope for the custom variable (optional)
97+
98+
* @param successCallback The success callback
99+
* @param failureCallback The error callback
100+
*/
101+
102+
setCustomVar(index, label, value, scope, successCallback, failureCallback);
103+
</pre>
104+
105+
Sample use:
89106

107+
window.plugins.analytics.setCustomVar(1, "type", "android", null, function(){alert("SetVar: success");}, function(){alert("SetVar: failure");});
90108

91109
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
92110
Good practice will be manual dispatch and stop session. Add this code to your main activity:

Android/Analytics/2.0/src/com/phonegap/plugins/analytics/GoogleAnalyticsTracker.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public PluginResult execute(String action, JSONArray data, String callbackId) {
5555
} else if (SET_CUSTOM_VARIABLE.equals(action)){
5656
try {
5757
setCustomVar(data.getInt(0), data.getString(1), data.getString(2), data.getInt(3));
58+
result = new PluginResult(Status.OK);
5859
} catch (JSONException e) {
5960
result = new PluginResult(Status.JSON_EXCEPTION);
6061
}
@@ -77,6 +78,7 @@ private void trackEvent(String category, String action, String label, int value)
7778
}
7879

7980
private void setCustomVar(int index, String label, String value, int scope) {
80-
tracker.setCustomVar(index, label, value, scope);
81+
if(scope > 0) tracker.setCustomVar(index, label, value, scope);
82+
else tracker.setCustomVar(index, label, value);
8183
}
8284
}

Android/Analytics/2.0/www/analytics.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,17 @@ Analytics.prototype.trackEvent = function(category, action, label, value, succes
6868
]);
6969
};
7070

71+
/**
72+
* Set a custom variable on Google Analytics
73+
* @param index The slot for the custom variable
74+
* @param label The name for the custom variable
75+
* @param value The value for the custom variable
76+
* @param scope The scope for the custom variable (optional)
77+
78+
* @param successCallback The success callback
79+
* @param failureCallback The error callback
80+
*/
81+
7182
Analytics.prototype.setCustomVar = function(index, label, value, scope, successCallback, failureCallback){
7283
return cordova.exec(
7384
successCallback,

0 commit comments

Comments
 (0)