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

Commit

Permalink
Add docs for dispatch functions
Browse files Browse the repository at this point in the history
  • Loading branch information
cbrevik committed Jan 24, 2018
1 parent def44c8 commit 0e9a90d
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,28 @@ Sets tracker currency property, see [Currency Codes](https://developers.google.c
tracker.setCurrency('EUR');
```

### dispatch()

This function lets you manually dispatch all hits which are queued.
Use this function sparingly, as it will normally happen automatically as a batch.

* returns Promise

```javascript
tracker.dispatch().then((done) => console.log("Dispatch is done: ", done));
```

### dispatchWithTimeout()

* **timeout (optional):** Number, in ms

The same as `dispatch()`, but also gives you the ability to time out the Promise in case dispatch takes too long.

* returns Promise

```javascript
tracker.dispatchWithTimeout(10000).then((done) => console.log("Dispatch is done: ", done));
```
## GoogleAnalyticsSettings API

Settings are applied across all trackers.
Expand Down
16 changes: 16 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,22 @@ declare module "react-native-google-analytics-bridge" {
* @param {String} screenName The current screen which the session started on
*/
createNewSession(screenName: string): void

/**
* This function lets you manually dispatch all hits which are queued.
* Use this function sparingly, as it will normally happen automatically
* as a batch.
* @returns {Promise<boolean>} Returns when done
*/
dispatch(): Promise<boolean>

/**
* The same as dispatch(), but also gives you the ability to time out
* the Promise in case dispatch takes too long.
* @param {Number} timeout The timeout. Default value is 15 sec.
* @returns {Promise<boolean>} Returns when done or timed out
*/
dispatchWithTimeout(timeout: number = -1): Promise<boolean>
}

/**
Expand Down
12 changes: 12 additions & 0 deletions src/GoogleAnalyticsTracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,22 @@ export class GoogleAnalyticsTracker {
GoogleAnalyticsBridge.createNewSession(this.id, screenName);
}

/**
* This function lets you manually dispatch all hits which are queued.
* Use this function sparingly, as it will normally happen automatically
* as a batch.
* @returns {Promise<boolean>} Returns when done
*/
dispatch() {
return GoogleAnalyticsBridge.dispatch();
}

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

0 comments on commit 0e9a90d

Please sign in to comment.