Skip to content

Commit

Permalink
Added dispatchHits function
Browse files Browse the repository at this point in the history
  • Loading branch information
cmackay committed Jan 28, 2017
1 parent 2d1e624 commit bcac2e9
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 0 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ cordova plugin add com.cmackay.plugins.googleanalytics
* [.getAppOptOut([success])](#module_analytics.getAppOptOut)
* [.setAppOptOut([enabled], [success], [error])](#module_analytics.setAppOptOut)
* [.setLogLevel(logLevel, [success], [error])](#module_analytics.setLogLevel)
* [.dispatchHits([success], [error])](#module_analytics.dispatchHits)
* [.get(key, success, [error])](#module_analytics.get)
* [.set(key, value, [success], [error])](#module_analytics.set)
* [.send(params, [success], [error])](#module_analytics.send)
Expand Down Expand Up @@ -172,6 +173,18 @@ Sets the log level
| [success] | <code>function</code> | the success callback |
| [error] | <code>function</code> | the error callback |

<a name="module_analytics.dispatchHits"></a>

### analytics.dispatchHits([success], [error])
Manually dispatches hits

**Kind**: static method of <code>[analytics](#module_analytics)</code>

| Param | Type | Description |
| --- | --- | --- |
| [success] | <code>function</code> | the success callback |
| [error] | <code>function</code> | the error callback |

<a name="module_analytics.get"></a>

### analytics.get(key, success, [error])
Expand Down
9 changes: 9 additions & 0 deletions android/GoogleAnalyticsPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ public boolean execute(String action, String rawArgs, CallbackContext callback)
setTrackingId(rawArgs, callback);
return true;

} else if ("dispatchHits".equals(action)) {
dispatchHits(rawArgs, callback);
return true;

} else if ("setDispatchInterval".equals(action)) {
setDispatchInterval(rawArgs, callback);
return true;
Expand Down Expand Up @@ -130,6 +134,11 @@ private void setTrackingId(String rawArgs, CallbackContext callback) {
}
}

private void dispatchHits(String rawArgs, CallbackContext callback) {
ga.dispatchLocalHits();
callback.success();
}

private void setDispatchInterval(String rawArgs, CallbackContext callback) {
try {
ga.setLocalDispatchPeriod(new JSONArray(rawArgs).getInt(0));
Expand Down
1 change: 1 addition & 0 deletions ios/GoogleAnalyticsPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

- (void) setTrackingId: (CDVInvokedUrlCommand*)command;
- (void) setMultipleTrackingIds: (CDVInvokedUrlCommand*)command;
- (void) dispatchHits: (CDVInvokedUrlCommand*)command;
- (void) setDispatchInterval: (CDVInvokedUrlCommand*)command;
- (void) setLogLevel: (CDVInvokedUrlCommand*)command;
- (void) get: (CDVInvokedUrlCommand*)command;
Expand Down
10 changes: 10 additions & 0 deletions ios/GoogleAnalyticsPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@ - (void) setMultipleTrackingIds: (CDVInvokedUrlCommand*)command
[self.commandDelegate sendPluginResult:result callbackId:[command callbackId]];
}

- (void) dispatchHits: (CDVInvokedUrlCommand*)command
{
CDVPluginResult* result = nil;

[[GAI sharedInstance] dispatch];
result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];

[self.commandDelegate sendPluginResult:result callbackId:[command callbackId]];
}

- (void) setDispatchInterval: (CDVInvokedUrlCommand*)command
{
CDVPluginResult* result = nil;
Expand Down
11 changes: 11 additions & 0 deletions www/analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,17 @@ module.exports = {
exec(success, error, 'GoogleAnalytics', 'setIDFAEnabled', []);
},

/**
* Manually dispatches hits
*
* @param {function} [success] - the success callback
* @param {function} [error] - the error callback
*/
dispatchHits: function (success, error) {
argscheck.checkArgs('FF', 'analytics.dispatchHits', arguments);
exec(success, error, 'GoogleAnalytics', 'dispatchHits', []);
},

/**
* Gets a field value. Returned as argument to success callback.
* If multiple trackers are being used, this returns an array of trackerId and
Expand Down

0 comments on commit bcac2e9

Please sign in to comment.