Skip to content
This repository was archived by the owner on May 21, 2019. It is now read-only.

Commit 0e9a90d

Browse files
committed
Add docs for dispatch functions
1 parent def44c8 commit 0e9a90d

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

README.md

+22
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,28 @@ Sets tracker currency property, see [Currency Codes](https://developers.google.c
408408
tracker.setCurrency('EUR');
409409
```
410410

411+
### dispatch()
412+
413+
This function lets you manually dispatch all hits which are queued.
414+
Use this function sparingly, as it will normally happen automatically as a batch.
415+
416+
* returns Promise
417+
418+
```javascript
419+
tracker.dispatch().then((done) => console.log("Dispatch is done: ", done));
420+
```
421+
422+
### dispatchWithTimeout()
423+
424+
* **timeout (optional):** Number, in ms
425+
426+
The same as `dispatch()`, but also gives you the ability to time out the Promise in case dispatch takes too long.
427+
428+
* returns Promise
429+
430+
```javascript
431+
tracker.dispatchWithTimeout(10000).then((done) => console.log("Dispatch is done: ", done));
432+
```
411433
## GoogleAnalyticsSettings API
412434

413435
Settings are applied across all trackers.

index.d.ts

+16
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,22 @@ declare module "react-native-google-analytics-bridge" {
260260
* @param {String} screenName The current screen which the session started on
261261
*/
262262
createNewSession(screenName: string): void
263+
264+
/**
265+
* This function lets you manually dispatch all hits which are queued.
266+
* Use this function sparingly, as it will normally happen automatically
267+
* as a batch.
268+
* @returns {Promise<boolean>} Returns when done
269+
*/
270+
dispatch(): Promise<boolean>
271+
272+
/**
273+
* The same as dispatch(), but also gives you the ability to time out
274+
* the Promise in case dispatch takes too long.
275+
* @param {Number} timeout The timeout. Default value is 15 sec.
276+
* @returns {Promise<boolean>} Returns when done or timed out
277+
*/
278+
dispatchWithTimeout(timeout: number = -1): Promise<boolean>
263279
}
264280

265281
/**

src/GoogleAnalyticsTracker.js

+12
Original file line numberDiff line numberDiff line change
@@ -251,10 +251,22 @@ export class GoogleAnalyticsTracker {
251251
GoogleAnalyticsBridge.createNewSession(this.id, screenName);
252252
}
253253

254+
/**
255+
* This function lets you manually dispatch all hits which are queued.
256+
* Use this function sparingly, as it will normally happen automatically
257+
* as a batch.
258+
* @returns {Promise<boolean>} Returns when done
259+
*/
254260
dispatch() {
255261
return GoogleAnalyticsBridge.dispatch();
256262
}
257263

264+
/**
265+
* The same as dispatch(), but also gives you the ability to time out
266+
* the Promise in case dispatch takes too long.
267+
* @param {Number} timeout The timeout. Default value is 15 sec.
268+
* @returns {Promise<boolean>} Returns when done or timed out
269+
*/
258270
dispatchWithTimeout(timeout = -1) {
259271
if (timeout < 0) {
260272
return GoogleAnalyticsBridge.dispatch();

0 commit comments

Comments
 (0)