Skip to content
This repository has been archived by the owner on Aug 18, 2023. It is now read-only.

fix(analytics-process): fix retrieving events from storage #9

Merged
merged 5 commits into from Dec 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,7 @@
## [1.3.1] - 2020-12-20

- Fixes a bug that caused the stored in memory events when in batch mode to be overwriten by the first events sent, thus being lost. To avoid a breaking change, the temporal solution was to move the process that pulls from memory old stored not sent events from the batch timer process, to happen when the user sends events for the first time. The problem this solution brings is that we need the caller to push new events in order to get the old stored events to be pushed. If the first thing don't happen the second won't either. But this is better than the previous scenario of lost events. For further details you can check [this PR](https://github.com/koa-health/mixpanel_analytics/pull/9)

## [1.3.0] - 2020-08-19

- Added `useIp` property.
Expand Down
103 changes: 34 additions & 69 deletions example/pubspec.lock
@@ -1,69 +1,62 @@
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
archive:
dependency: transitive
description:
name: archive
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.13"
args:
dependency: transitive
description:
name: args
url: "https://pub.dartlang.org"
source: hosted
version: "1.6.0"
async:
dependency: transitive
description:
name: async
url: "https://pub.dartlang.org"
source: hosted
version: "2.4.1"
version: "2.5.0-nullsafety.1"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
charcode:
version: "2.1.0-nullsafety.1"
characters:
dependency: transitive
description:
name: charcode
name: characters
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.3"
collection:
version: "1.1.0-nullsafety.3"
charcode:
dependency: transitive
description:
name: collection
name: charcode
url: "https://pub.dartlang.org"
source: hosted
version: "1.14.12"
convert:
version: "1.2.0-nullsafety.1"
clock:
dependency: transitive
description:
name: convert
name: clock
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.1"
crypto:
version: "1.1.0-nullsafety.1"
collection:
dependency: transitive
description:
name: crypto
name: collection
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.4"
version: "1.15.0-nullsafety.3"
cupertino_icons:
dependency: "direct main"
description:
name: cupertino_icons
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.2"
fake_async:
dependency: transitive
description:
name: fake_async
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0-nullsafety.1"
flutter:
dependency: "direct main"
description: flutter
Expand All @@ -88,62 +81,41 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "3.1.3"
image:
dependency: transitive
description:
name: image
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.12"
matcher:
dependency: transitive
description:
name: matcher
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.6"
version: "0.12.10-nullsafety.1"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.8"
version: "1.3.0-nullsafety.3"
mixpanel_analytics:
dependency: "direct main"
description:
path: ".."
relative: true
source: path
version: "1.2.1"
version: "1.3.1"
path:
dependency: transitive
description:
name: path
url: "https://pub.dartlang.org"
source: hosted
version: "1.6.4"
version: "1.8.0-nullsafety.1"
pedantic:
dependency: transitive
description:
name: pedantic
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0+1"
petitparser:
dependency: transitive
description:
name: petitparser
url: "https://pub.dartlang.org"
source: hosted
version: "2.4.0"
quiver:
dependency: transitive
description:
name: quiver
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.3"
shared_preferences:
dependency: transitive
description:
Expand All @@ -162,63 +134,56 @@ packages:
name: source_span
url: "https://pub.dartlang.org"
source: hosted
version: "1.7.0"
version: "1.8.0-nullsafety.2"
stack_trace:
dependency: transitive
description:
name: stack_trace
url: "https://pub.dartlang.org"
source: hosted
version: "1.9.3"
version: "1.10.0-nullsafety.1"
stream_channel:
dependency: transitive
description:
name: stream_channel
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
version: "2.1.0-nullsafety.1"
string_scanner:
dependency: transitive
description:
name: string_scanner
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.5"
version: "1.1.0-nullsafety.1"
term_glyph:
dependency: transitive
description:
name: term_glyph
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.0"
version: "1.2.0-nullsafety.1"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.15"
version: "0.2.19-nullsafety.2"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.6"
version: "1.3.0-nullsafety.3"
vector_math:
dependency: transitive
description:
name: vector_math
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.8"
xml:
dependency: transitive
description:
name: xml
url: "https://pub.dartlang.org"
source: hosted
version: "3.6.1"
version: "2.1.0-nullsafety.3"
sdks:
dart: ">=2.6.0 <3.0.0"
dart: ">=2.10.0-110 <2.11.0"
flutter: ">=1.5.0 <2.0.0"
28 changes: 22 additions & 6 deletions lib/src/mixpanel_analytics.dart
Expand Up @@ -198,6 +198,14 @@ class MixpanelAnalytics {
event, properties, time ?? DateTime.now(), ip, insertId);

if (isBatchMode) {
// TODO: this should be place within an init() along within the constructor.
// This is not perfect, as we are waiting for the caller to send an event before sending the stored in memory.
// But doing it on an init() would be a breaking change.
// To be executed only the first time user tries to send an event
if (!_isQueuedEventsReadFromStorage) {
await _restoreQueuedEventsFromStorage();
_isQueuedEventsReadFromStorage = true;
}
_trackEvents.add(trackEvent);
return _saveQueuedEventsToLocalStorage();
}
Expand Down Expand Up @@ -233,6 +241,14 @@ class MixpanelAnalytics {
operation, value, time ?? DateTime.now(), ip, ignoreTime, ignoreAlias);

if (isBatchMode) {
// TODO: this should be place within an init() along within the constructor.
// This is not perfect, as we are waiting for the caller to send an event before sending the stored in memory.
// But doing it on an init() would be a breaking change.
// To be executed only the first time user tries to send an event
if (!_isQueuedEventsReadFromStorage) {
await _restoreQueuedEventsFromStorage();
_isQueuedEventsReadFromStorage = true;
}
_engageEvents.add(engageEvent);
return _saveQueuedEventsToLocalStorage();
}
Expand Down Expand Up @@ -266,10 +282,6 @@ class MixpanelAnalytics {
// Tries to send all events pending to be send.
// TODO if error when sending, send events in isolation identify the incorrect message
Future<void> _uploadQueuedEvents() async {
if (!_isQueuedEventsReadFromStorage) {
await _restoreQueuedEventsFromStorage();
_isQueuedEventsReadFromStorage = true;
}
await _uploadEvents(_trackEvents, _sendTrackBatch);
await _uploadEvents(_engageEvents, _sendEngageBatch);
await _saveQueuedEventsToLocalStorage();
Expand Down Expand Up @@ -312,7 +324,9 @@ class MixpanelAnalytics {
'distinct_id': props['distinct_id'] == null
? _userId == null
? 'Unknown'
: _shouldAnonymize ? _anonymize('userId', _userId) : _userId
: _shouldAnonymize
? _anonymize('userId', _userId)
: _userId
: props['distinct_id']
};
if (ip != null) {
Expand Down Expand Up @@ -340,7 +354,9 @@ class MixpanelAnalytics {
'\$distinct_id': value['distinct_id'] == null
? _userId == null
? 'Unknown'
: _shouldAnonymize ? _anonymize('userId', _userId) : _userId
: _shouldAnonymize
? _anonymize('userId', _userId)
: _userId
: value['distinct_id']
};
if (ip != null) {
Expand Down