Skip to content

Commit

Permalink
fix(analytics): Don't call sendBeacon when not supported (aws-amplify…
Browse files Browse the repository at this point in the history
…#4246)

* fix(analytics): Don't call sendBeacon when not supported

* Formatting
  • Loading branch information
iartemiev authored Oct 24, 2019
1 parent e12a9a4 commit 4846968
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/analytics/src/Providers/AWSPinpointProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ const logger = new Logger('AWSPinpointProvider');
const RETRYABLE_CODES = [429, 500];
const ACCEPTED_CODES = [202];
const MOBILE_SERVICE_NAME = 'mobiletargeting';
const BEACON_SUPPORTED =
navigator && typeof navigator.sendBeacon === 'function';

// events buffer
const BUFFER_SIZE = 1000;
Expand Down Expand Up @@ -323,6 +325,11 @@ export default class AWSPinpointProvider implements AnalyticsProvider {
}

private _pinpointSendStopSession(params, handlers): Promise<string> {
if (!BEACON_SUPPORTED) {
this._record(params, handlers);
return;
}

const eventParams = this._generateBatchItemContext(params);

const { region } = this._config;
Expand Down Expand Up @@ -370,7 +377,9 @@ export default class AWSPinpointProvider implements AnalyticsProvider {
typeof params.resendLimit === 'number' ? params.resendLimit : resendLimit;
if (params.resendLimit-- > 0) {
logger.debug(
`resending event ${params.eventName} with ${params.resendLimit} retry times left`
`resending event ${params.eventName} with ${
params.resendLimit
} retry times left`
);
this._putToBuffer(params, handlers);
} else {
Expand Down

0 comments on commit 4846968

Please sign in to comment.