Skip to content

fix: Bug with logEvent callbacks not being called when unsent events are dropped - #342

Merged
jooohhn merged 7 commits into
masterfrom
fix-logevent-callback-on-fail
Jan 8, 2021
Merged

jooohhn merged 7 commits into
masterfrom
fix-logevent-callback-on-fail

Conversation

@jooohhn

@jooohhn jooohhn commented Jan 7, 2021 •

Copy link
Copy Markdown
Contributor

Summary

  • Failed events (e.g. offline user or content blocker) are stored in local storage to be resent at a later time
  • When the number of saved events in local storage exceeds maxSavedCount, the oldest events will be dropped but the associated callback won't be called. This PR fixes this
  • Fixes #142
  • Closes fix: logEvent callback on content block #329

Checklist

  • Does your PR title have the correct title format?
  • Does your PR have a breaking change?: NO

@jooohhn
jooohhn requested review from kelsonpw and kelvin-lu January 7, 2021 18:15
@jooohhn jooohhn mentioned this pull request Jan 7, 2021
1 task done
@kelvin-lu
kelvin-lu requested a review from theoschao January 7, 2021 21:13
Comment thread src/amplitude-client.js
AmplitudeClient.prototype._limitEventsQueued = function _limitEventsQueued(queue) {
if (queue.length > this.options.savedMaxCount) {
queue.splice(0, queue.length - this.options.savedMaxCount);
const deletedEvents = queue.splice(0, queue.length - this.options.savedMaxCount);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this.options.savedMaxCount guaranteed to be set?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, the default config for it is 1000

Comment thread src/amplitude-client.js
// }
} catch (e) {
// utils.log('failed upload');
// utils.log.error('failed upload');

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's this line for if commented out?

@jooohhn jooohhn Jan 8, 2021 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was commented out before, didn't want to touch it 😂

I just made a change to uncomment it

@kelvin-lu kelvin-lu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm! one nit and one conversation but overall makes sense.

Comment thread src/amplitude-client.js Outdated
if (queue.length > this.options.savedMaxCount) {
queue.splice(0, queue.length - this.options.savedMaxCount);
const deletedEvents = queue.splice(0, queue.length - this.options.savedMaxCount);
deletedEvents.forEach((e) => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: no single letter variable

Comment thread src/amplitude-client.js
deletedEvents.forEach((e) => {
if (type(e.callback) === 'function') {
e.callback(0, 'No request sent', {
reason: 'Event dropped because options.savedMaxCount exceeded. User may be offline or have a content blocker',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this is relatively long compared to our other reason strings. I appreciate the helpful direction though. How would you feel if this was in the util logs instead?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(not necessarily saying it should be in the util logs since I don't know how visible that might be) - and leaving this as-is might be a good idea as well.

@jooohhn jooohhn Jan 8, 2021 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that if it's only in the util logs, users won't be able to have failed upload event handling via callback

@jooohhn
jooohhn merged commit f243a92 into master Jan 8, 2021
@jooohhn
jooohhn deleted the fix-logevent-callback-on-fail branch January 8, 2021 19:04
github-actions Bot pushed a commit that referenced this pull request Jan 11, 2021
## [7.4.1](v7.4.0...v7.4.1) (2021-01-11)

### Bug Fixes

* Bug with logEvent callbacks not being called when unsent events are dropped  ([#342](#342)) ([f243a92](f243a92)), closes [#142](https://github.com/amplitude/amplitude-javascript/issues/142)
@jooohhn jooohhn mentioned this pull request Feb 22, 2021
1 task done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Amplitude callback isn't fired if a user enables adblock

4 participants