Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Anonymous User Tracking #730

Open
wants to merge 287 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 250 commits
Commits
Show all changes
287 commits
Select commit Hold shift + click to select a range
017e9df
Merge functionality
hardikmashru Jun 19, 2024
1b03c82
stashed changes
Jun 19, 2024
07719bf
Merge pull request #743 from Iterable/feature/itbl-track-anon-user-up…
evantk91 Jun 20, 2024
3a335df
refactor code
hardikmashru Jun 21, 2024
c98008f
merge unit test temp
hardikmashru Jun 21, 2024
2a66618
bug fixes with double values having trailing zeros
hardikmashru Jun 21, 2024
cbdc0bc
Update CriteriaCompletionChecker.java
hardikmashru Jun 21, 2024
cf39b40
stashed changes
Jun 21, 2024
6a976e7
Merge pull request #744 from Iterable/fixpricewith_trailingzeros
evantk91 Jun 21, 2024
6aaf301
unit tests
hardikmashru Jun 21, 2024
73002f5
unit tests done
hardikmashru Jun 22, 2024
19d3471
Merge branch 'master' into feature/itbl-track-anon-user
evantk91 Jun 24, 2024
3d2414f
temp item fix
hardikmashru Jun 24, 2024
ef8d40d
minor updates
Jun 25, 2024
78c1362
single item matches fix, minMax, unit tests
hardikmashru Jun 25, 2024
5205052
minMax and complexCriteria1 tests
hardikmashru Jun 26, 2024
5d55c17
tests for complex criteria 2 & 3
hardikmashru Jun 27, 2024
5083258
update session fix
hardikmashru Jun 27, 2024
df29b54
temp
hardikmashru Jun 28, 2024
bc6d880
not combinator fix
hardikmashru Jun 28, 2024
6aba7fa
unit tests for complex criteria 4
hardikmashru Jun 28, 2024
d95f486
refactor
hardikmashru Jun 28, 2024
4030491
unit tests fix
hardikmashru Jun 28, 2024
41bf649
fixed checkstyle issues
hardikmashru Jun 28, 2024
fe87057
checkstyle fixes
hardikmashru Jun 28, 2024
079bc49
Merge pull request #745 from Iterable/evan/MOB-8946-set-anonymous-user
evantk91 Jun 28, 2024
df82a95
cleanup
Jun 30, 2024
a8aefc1
resolves checks
Jun 30, 2024
66e003a
resolves check
Jun 30, 2024
7bd2b02
Merge branch 'feature/itbl-track-anon-user' into feature/itbl-track-a…
evantk91 Jun 30, 2024
86c9740
Merge branch 'feature/itbl-track-anon-user-update' into feature/itbl-…
Jun 30, 2024
aaf508f
removes log statements
Jun 30, 2024
b8a38c2
Merge branch 'feature/itbl-track-anon-user' into feature/itbl-track-a…
Jun 30, 2024
c5bdd27
resolves checks
Jun 30, 2024
1e5aa70
Merge pull request #749 from Iterable/feature/itbl-track-anon-user-se…
evantk91 Jun 30, 2024
603e04a
Merge branch 'feature/itbl-track-anon-user' into MOB-8954
evantk91 Jun 30, 2024
b87799d
Merge pull request #748 from Iterable/itbl-track-anon-user-criteria-test
evantk91 Jun 30, 2024
f55499c
Merge branch 'feature/itbl-track-anon-user' into MOB-8954
Jun 30, 2024
412b441
Merge branch 'MOB-8954' of github.com:Iterable/iterable-android-sdk i…
Jun 30, 2024
0ca6032
cleanup
Jul 1, 2024
5813804
formatting
Jul 1, 2024
8d5bd34
Merge pull request #747 from Iterable/MOB-8954
evantk91 Jul 1, 2024
c308e39
purchase fix
hardikmashru Jul 1, 2024
d86b2ce
Merge branch 'feature/itbl-track-anon-user' into feature/itbl-track-a…
evantk91 Jul 1, 2024
474a4fa
unit tests fix
hardikmashru Jul 2, 2024
27f6155
resolve checks
hardikmashru Jul 2, 2024
29e9454
updateCart and customEvent fix , unit tests
hardikmashru Jul 4, 2024
ed7eaab
resolve checks
hardikmashru Jul 4, 2024
58a3c85
remove all println
hardikmashru Jul 5, 2024
9800f1b
remove println statements
hardikmashru Jul 5, 2024
027b33d
test fix
hardikmashru Jul 5, 2024
04de279
doesItemMatchQueries fix
hardikmashru Jul 5, 2024
4888a7e
Merge branch 'feature/itbl-track-anon-user' of https://github.com/Ite…
hardikmashru Jul 5, 2024
2d6505a
temp
hardikmashru Jul 5, 2024
80362d5
formatting
Jul 5, 2024
a225bce
Merge pull request #755 from Iterable/evan/cleanup
evantk91 Jul 5, 2024
ca39487
Merge branch 'feature/itbl-track-anon-user' into feature/itbl-track-a…
Jul 5, 2024
061def5
Merge branch 'feature/itbl-track-anon-user' into itbl-track-anon-user…
evantk91 Jul 8, 2024
9da40ce
Merge pull request #754 from Iterable/itbl-track-anon-user-purchase_u…
evantk91 Jul 8, 2024
02d3811
Merge branch 'feature/itbl-track-anon-user' into feature/itbl-track-a…
evantk91 Jul 8, 2024
aa7f786
resolve errors
hardikmashru Jul 9, 2024
c620bb0
Merge pull request #750 from Iterable/feature/itbl-track-anon-user-up…
evantk91 Jul 9, 2024
9aa2fd8
adds isAnon flag to allow anonymous user id to be set
Jul 9, 2024
8d4b690
resolves check
Jul 9, 2024
058924b
Merge branch 'master' into feature/itbl-track-anon-user
Jul 9, 2024
8a52ce0
Merge branch 'master' into feature/itbl-track-anon-user
evantk91 Jul 18, 2024
6b0762a
Merge branch 'feature/itbl-track-anon-user' into evan/isAnon_flag
evantk91 Jul 18, 2024
541f1ba
testing breaking tests
Aug 4, 2024
5454aa0
minor cleanup
Aug 4, 2024
283cff7
testing unit test failures
Aug 4, 2024
70a75c3
resolves check
Aug 4, 2024
1d9e743
minor edit
Aug 4, 2024
1138dcf
adds set user id call when anonymous user is stored
Aug 4, 2024
559b70f
updates some set email unit tests
Aug 4, 2024
8d13131
minor edits
Aug 4, 2024
459fd67
minor edit
Aug 4, 2024
dd099b4
testing unit tests
Aug 4, 2024
0d97539
debugging unit tests
Aug 4, 2024
ebcccf1
updates unit tests
Aug 4, 2024
555de72
adds delay to unit test
Aug 4, 2024
5a0defd
testing testCriteriaMetUserIdDefault
Aug 4, 2024
8ff935b
testing
Aug 5, 2024
f0b02d5
testing
Aug 5, 2024
3410ede
testing
Aug 5, 2024
fd9306f
testing
Aug 5, 2024
3029ade
brings set user logic out of the tryMergeUser callback
Aug 5, 2024
aafc69e
resets unit tests and removes setEmail logic from tryMergeUser callback
Aug 5, 2024
6639154
Merge pull request #758 from Iterable/evan/isAnon_flag
evantk91 Aug 5, 2024
3964297
refactoring
Aug 5, 2024
fe254c8
Merge branch 'feature/itbl-track-anon-user' into evan/set_anonymous_user
evantk91 Aug 5, 2024
99c7b60
Merge pull request #761 from Iterable/evan/set_anonymous_user
evantk91 Aug 5, 2024
064ea2d
removes redundant call
Aug 6, 2024
461a67a
Merge pull request #762 from Iterable/evan/cleanup
evantk91 Aug 6, 2024
fa89d73
- MOB-9138: Resolves DoesNotEqual criteria match issue
megha-iterable Aug 9, 2024
1c34942
- MOB-9314: Written automated unit test cases for different field typ…
megha-iterable Aug 12, 2024
ed195bc
adds AUT enabled flag to set email and set user id
Aug 12, 2024
bdc6e78
refactoring
Aug 12, 2024
f705ea6
addresses checks
Aug 12, 2024
47026a6
Merge branch 'bugfix/MOB-9138-resolves-DoesNotEqual-criteria-match' i…
evantk91 Aug 12, 2024
415f7d3
Merge pull request #763 from Iterable/bugfix/MOB-9138-resolves-DoesNo…
evantk91 Aug 13, 2024
ed38ebd
- MOB-8825: limit the number of stored events and make the number of …
megha-iterable Aug 16, 2024
38a770d
Merge branch 'feature/itbl-track-anon-user' into evan/MOB-9348-disabl…
evantk91 Aug 16, 2024
860ce10
- MOB-9311: Write automated unit tests against Combination logic with…
megha-iterable Aug 20, 2024
53669ee
Merge branch 'feature/itbl-track-anon-user' into bugfix/MOB-9314-auto…
evantk91 Aug 20, 2024
89dd585
Merge pull request #768 from Iterable/feature/MOB-8825-limit-the-numb…
evantk91 Aug 20, 2024
080d5aa
sets event threshold to 50
Aug 21, 2024
f0a087d
Merge pull request #771 from Iterable/evan/update-event-threshold
evantk91 Aug 21, 2024
e24ad1e
updates assertions
Aug 21, 2024
7c85ba8
deletes unused imports
Aug 21, 2024
a812bcd
Merge pull request #764 from Iterable/bugfix/MOB-9314-automated-unit-…
evantk91 Aug 21, 2024
14b0126
Merge pull request #769 from Iterable/bugfix/MOB-9311-automated-unit-…
evantk91 Aug 21, 2024
41e7262
updates event threshold limit
Aug 21, 2024
233baec
Merge branch 'feature/itbl-track-anon-user' into evan/update-event-th…
evantk91 Aug 21, 2024
3d2d121
Merge pull request #772 from Iterable/evan/update-event-threshold-2
evantk91 Aug 21, 2024
23a39c3
testing unit test failures
Aug 22, 2024
23b3943
testing
Aug 22, 2024
8d57625
testing
Aug 22, 2024
af83e06
Merge branch 'feature/itbl-track-anon-user' into evan/MOB-9348-disabl…
evantk91 Aug 22, 2024
1a73c54
Merge pull request #765 from Iterable/evan/MOB-9348-disable-merge-and…
evantk91 Aug 22, 2024
16aca15
fixes attemptAndProcessMerge bug
Aug 26, 2024
cd2b7ff
makes tryMergeUser private
Aug 26, 2024
9766302
Merge pull request #775 from Iterable/evan/MOB-9430-update-attemptAnd…
evantk91 Aug 26, 2024
0b427bf
Merge branch 'feature/itbl-track-anon-user' into evan/MOB-9422-make-t…
evantk91 Aug 26, 2024
88e29fc
testing unit tests
Aug 26, 2024
f505aba
removes merge endpoint assertions for identified email/user id tests
Aug 26, 2024
511904a
removes some unnecessary tests
Aug 26, 2024
3ef448f
updates unit tests
Aug 27, 2024
597dc87
- MOB-9312: Fully support comparison for Array data types
megha-iterable Aug 23, 2024
81373f8
adds additional checks
Aug 28, 2024
6bc63e7
addresses checks
Aug 28, 2024
3e6f51d
reorganizing
Aug 28, 2024
f55bb44
moving checks out of attemptAndProcessMerge
Aug 28, 2024
8df4232
addresses check
Aug 28, 2024
de69cca
renaming
Aug 28, 2024
c7c33eb
Merge pull request #776 from Iterable/evan/MOB-9422-make-tryMergeUser…
evantk91 Aug 28, 2024
2b83ca0
Merge branch 'feature/itbl-track-anon-user' into bugfix/MOB-9312-Full…
evantk91 Aug 28, 2024
63ed3f7
- MOB-9179: Support nested field types
megha-iterable Aug 29, 2024
1b91920
cleanup
Aug 29, 2024
dde773e
Merge pull request #774 from Iterable/bugfix/MOB-9312-Fully-support-c…
evantk91 Aug 29, 2024
9716281
Merge branch 'feature/itbl-track-anon-user' into feature/MOB-9179-Sup…
evantk91 Aug 29, 2024
c85a83e
- Update the logic as per the PR comment
megha-iterable Aug 30, 2024
a8c1670
Merge pull request #778 from Iterable/feature/MOB-9179-Support-nested…
evantk91 Aug 30, 2024
50359e8
- MOB-9386 Support isOneOf and isNotOneOf comparator
megha-iterable Sep 2, 2024
9cded0a
Merge pull request #779 from Iterable/feature/MOB-9386-Support-isOneO…
evantk91 Sep 3, 2024
b836db4
- MOB-9238 Convert millisecond to second
megha-iterable Sep 3, 2024
5131eda
Merge branch 'feature/itbl-track-anon-user' into feature/MOB-9238-Rep…
evantk91 Sep 4, 2024
358995d
Merge pull request #780 from Iterable/feature/MOB-9238-Replayed-event…
evantk91 Sep 4, 2024
2002aee
refactoring sync events
Sep 7, 2024
bc86fc3
refactors sync events
Sep 9, 2024
0e23afe
refactors update anon session
Sep 9, 2024
0222725
refactors storeEventListToLocalStorage
Sep 9, 2024
1d7561f
more refactoring and updating sync events
Sep 9, 2024
5e8b8bd
resolves checks
Sep 9, 2024
cf2644f
addresses check
Sep 9, 2024
ac87091
Merge branch 'master' into feature/itbl-track-anon-user
evantk91 Sep 9, 2024
3c4ef2f
Merge branch 'feature/itbl-track-anon-user' into evan/MOB-9001-refact…
evantk91 Sep 9, 2024
82b66ab
MOB-9448 - update user should not be a separate call
megha-iterable Sep 10, 2024
cf301ff
adds handleUpdateUser
Sep 10, 2024
9109999
Merge pull request #786 from Iterable/evan/MOB-9001-refactoring-anony…
evantk91 Sep 10, 2024
ed9853a
Merge branch 'feature/itbl-track-anon-user' of https://github.com/Ite…
megha-iterable Sep 12, 2024
06d2c41
MOB-9536 - Android: criteria is incorrectly matching on a simple isSe…
megha-iterable Sep 12, 2024
ea59092
Merge pull request #788 from Iterable/bugfix/MOB-9536-Android-criteri…
evantk91 Sep 12, 2024
7490c89
Merge branch 'feature/itbl-track-anon-user' into feature/MOB-9448-upd…
evantk91 Sep 12, 2024
61aeacf
adds some comments for readability
Sep 12, 2024
bf23b00
Merge pull request #787 from Iterable/feature/MOB-9448-update-user-sh…
evantk91 Sep 12, 2024
ee6462c
refactoring
Sep 14, 2024
29caa59
refactors evaluateComparison
Sep 14, 2024
8e6a593
resolves check
Sep 14, 2024
10b2446
refactorign
Sep 14, 2024
5ec4b0d
refactoring
Sep 14, 2024
96152ea
refactors compareValueEquality
Sep 14, 2024
9e24983
Merge pull request #793 from Iterable/evan/MOB-9570-refactor-comparis…
evantk91 Sep 16, 2024
c36b9ee
creates IterableIdentityResolution class and adds it to the Anonymous…
Sep 17, 2024
9cb0fef
adds identity resolution to config
Sep 18, 2024
da30daa
minor edits
Sep 18, 2024
19aefde
reverts change
Sep 18, 2024
7d5f184
updates unit tests
Sep 18, 2024
dd12a2e
Merge branch 'feature/itbl-track-anon-user' into evan/MOB-9559-identi…
evantk91 Sep 18, 2024
cc99f2b
addresses unit test
Sep 18, 2024
4e93a7e
updates criterias to criteriaSets in constant
Sep 18, 2024
65b059d
updates unit tests
Sep 18, 2024
0ef6134
MOB-9203 - Add test to validate object created by custom event api calls
megha-iterable Sep 18, 2024
0a57282
Merge branch 'feature/itbl-track-anon-user' into evan/MOB-9583
evantk91 Sep 19, 2024
2d92211
Merge pull request #803 from Iterable/evan/MOB-9583
evantk91 Sep 19, 2024
ad76527
Merge branch 'feature/itbl-track-anon-user' into feature/MOB-9203-Add…
evantk91 Sep 19, 2024
c56ca27
renaming criterias to criteriaSets
Sep 19, 2024
5ae179c
cleanup
Sep 19, 2024
db86ebd
Merge pull request #801 from Iterable/feature/MOB-9203-Add-test-to-va…
evantk91 Sep 19, 2024
da7c725
addresses misnamed parameter
Sep 21, 2024
7671a6d
Merge branch 'feature/itbl-track-anon-user' into evan/MOB-9559-identi…
evantk91 Sep 21, 2024
cd47083
updates unit test
Sep 21, 2024
b6dd04c
updates replay to false for several unit tests
Sep 21, 2024
8966520
refactors setting of merge and replay parameters
Sep 23, 2024
b170464
sets email or user id before event replay occurs
Sep 23, 2024
0dba934
Merge pull request #804 from Iterable/evan/MOB-9519-fix-event-replay
evantk91 Sep 24, 2024
ed8014f
unit test updates
Sep 24, 2024
47297ef
updates unit tests
Sep 24, 2024
74c3262
updates unit tests
Sep 25, 2024
35d585c
updates unit tests
Sep 25, 2024
4794b30
unit test updates
Sep 25, 2024
f3453cb
removes event replay from merging function
Sep 25, 2024
354753e
adds check for user being logged in
Sep 25, 2024
a3a2a7b
correction
Sep 25, 2024
1a6d1ef
MOB-9651 - Add support to check for nested criteria a.b.c
megha-iterable Sep 26, 2024
38c598c
removes identity resolution from tester app
Sep 26, 2024
e3352e1
resolves comments and cleanup
Sep 26, 2024
e21a0ba
Merge pull request #800 from Iterable/evan/MOB-9559-identity-resolution
evantk91 Sep 26, 2024
38abe65
Merge pull request #806 from Iterable/evan/decouple-replay-from-merge
evantk91 Sep 27, 2024
2487af5
Merge branch 'evan/MOB-9620' into feature/itbl-track-anon-user
Sep 27, 2024
4918ace
fixes unit test
Sep 27, 2024
d78987d
Merge branch 'feature/itbl-track-anon-user' into feature/MOB-9651-Add…
evantk91 Sep 27, 2024
e4d4456
adds comments for readability
Sep 30, 2024
804a3a2
Merge pull request #808 from Iterable/feature/MOB-9651-Add-support-to…
evantk91 Sep 30, 2024
92938d8
MOB-9638 - Add handlers for notifying customer app of a newly created…
megha-iterable Sep 30, 2024
96a2e35
Write automated unit tests against Complex criteria
megha-iterable Sep 30, 2024
ed64a9f
Merge pull request #809 from Iterable/feature/MOB-9638-Add-handlers-f…
evantk91 Sep 30, 2024
f847eca
Merge branch 'feature/itbl-track-anon-user' into feature/MOB-9311-Wri…
evantk91 Sep 30, 2024
55b73ff
MOB-9668 - Add support for Nested JSON with Array Criteria Match
megha-iterable Oct 4, 2024
f0e6bf8
adds comments
Oct 4, 2024
e4297d5
removes changes outside of PR
Oct 4, 2024
4d4bd05
minor changes
Oct 4, 2024
9fb6552
Merge pull request #814 from Iterable/bugfix/MOB-9668-Nested-JSON-wit…
evantk91 Oct 4, 2024
ab6f3c8
Merge branch 'feature/itbl-track-anon-user' into feature/MOB-9311-Wri…
evantk91 Oct 8, 2024
b08a251
updates unit tests
Oct 8, 2024
d342619
adds additional passing case
Oct 8, 2024
2bac136
- remove commas in 'jsonString' for valid json
megha-iterable Oct 9, 2024
948c0e8
MOB-9679 - Keep AUT off until consent to track has been granted
megha-iterable Oct 9, 2024
96f1ef2
Merge pull request #810 from Iterable/feature/MOB-9311-Write-automate…
evantk91 Oct 9, 2024
787f9d8
Merge branch 'feature/itbl-track-anon-user' into feature/MOB-9679-Kee…
evantk91 Oct 9, 2024
85209d1
cleanup
Oct 9, 2024
8f0b3dd
Merge pull request #815 from Iterable/feature/MOB-9679-Keep-AUT-off-u…
evantk91 Oct 9, 2024
f25b8a5
adds AUT enablement check
Oct 14, 2024
13c2693
Merge pull request #816 from Iterable/evan/MOB-9931
evantk91 Oct 15, 2024
74781ce
creates separate local storage for user updates
Oct 17, 2024
820e1ef
removes unused import
Oct 18, 2024
01679cd
updates to clear stored user update object
Oct 18, 2024
ca964fc
stashed changes
Oct 21, 2024
13ad6f6
adds update user call and renamed syncEvents function
Oct 21, 2024
cb59505
addresses comments
Oct 21, 2024
8185129
minor updates
Oct 21, 2024
f0359da
Merge pull request #819 from Iterable/evan/MOB-9997-bug-fix-user-upda…
evantk91 Oct 21, 2024
5908010
clears user update when consent is updated
Oct 22, 2024
77cd595
Merge pull request #820 from Iterable/evan/corrections
evantk91 Oct 23, 2024
0e2af59
updates user update aggregation
Oct 23, 2024
3e6aa4a
Merge pull request #822 from Iterable/evan/MOB-10031-user-update-arra…
evantk91 Oct 23, 2024
0469733
MOB-9716 - single primitive array bug
megha-iterable Oct 24, 2024
cc619ee
renames createAnonymousUser
Oct 24, 2024
1530eb0
Merge pull request #823 from Iterable/bugfix/MOB-9716-single-primitiv…
evantk91 Oct 24, 2024
b3d901e
Merge branch 'feature/itbl-track-anon-user' into evan/MOB-10054
evantk91 Oct 24, 2024
35d7ee0
Merge pull request #824 from Iterable/evan/MOB-10054
evantk91 Oct 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 124 additions & 0 deletions AnonymousUserEventTracking.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
# AnonymousUserManager Class

## Class Introduction

The `AnonymousUserManager` class is responsible for managing anonymous user sessions and tracking events in an Android application.
It includes methods for updating sessions, tracking events, and handling criteria for transitioning to known users.

## Class Structure

The `AnonymousUserManager` class includes the following key components:

- **Fields:**
- `TAG`: A constant String for logging.

- **Methods:**
- `updateAnonSession()`: Updates the anonymous user session.
- `trackAnonEvent(String eventName, JSONObject dataFields)`: Tracks an anonymous event.
- `trackAnonPurchaseEvent(double total, List<CommerceItem> items, JSONObject dataFields)`: Tracks an anonymous purchase event.
- `trackAnonUpdateCart(List<CommerceItem> items)`: Tracks an anonymous cart update.
- `getCriteria()`: Retrieves criteria for user transition.
- `checkCriteriaCompletion()`: Checks if criteria for user transition are met.
- `createKnownUser()`: Creates a known user after criteria are met.
- `syncEvents()`: Syncs tracked events with the server.
- `clearLocallyStoredData()`: Clears locally stored data.
- `storeEventListToLocalStorage(JSONObject newDataObject)`: Stores event data in local storage.
- `getEventListFromLocalStorage()`: Retrieves event data from local storage.
- `getCurrentTime()`: Gets the current time in milliseconds.
- `getCurrentDateTime()`: Gets the current date and time in UTC format.

## Methods Description

### `updateAnonSession()`

This method updates the anonymous user session. It does the following:

* Retrieves the previous session data from SharedPreferences.
* Increments the session number.
* Stores the updated session data in SharedPreferences.

### `trackAnonEvent(eventName, dataFields)`

This method tracks an anonymous event. It does the following:

* Creates a JSON object with event details, including the event name, timestamp, data fields, and tracking type.
* Stores the event data in local storage.
* Checks criteria completion and creates a known user if criteria are met.

### `trackAnonPurchaseEvent(total, items, dataFields)`

This method tracks an anonymous purchase event. It does the following:

* Converts the list of commerce items to JSON.
* Creates a JSON object with purchase event details, including items, total, timestamp, data fields, and tracking type.
* Stores the purchase event data in local storage.
* Checks criteria completion and creates a known user if criteria are met.

### `trackAnonUpdateCart(items)`

This method tracks an anonymous cart update. It does the following:

* Converts the list of commerce items to JSON.
* Creates a JSON object with cart update details, including items, timestamp, and tracking type.
* Stores the cart update data in local storage.
* Checks criteria completion and creates a known user if criteria are met.

### `getCriteria()`

This method is responsible for fetching criteria data. It simulates calling an API and saving data in SharedPreferences.

### `checkCriteriaCompletion()`

This private method checks if criteria for creating a known user are met. It compares stored event data with predefined criteria and returns `true` if criteria are completed.

### `createKnownUser()`

This method is responsible for creating a known user in the Iterable API. It does the following:

* Sets a random user ID using a UUID (Universally Unique Identifier).
* Retrieves user session data from SharedPreferences.
* If user session data exists, it updates the user information in the Iterable API.
* Calls the syncEvents() method to synchronize tracked events.
* Finally, it clears locally stored data using the clearLocallyStoredData() method.

### `syncEvents()`

This method is used to synchronize tracked events stored in local storage with the Iterable API. It performs the following tasks:

* Retrieves the list of tracked events from local storage using the getEventListFromLocalStorage() method.
* Iterates through the list of events and processes each event based on its type.
* Supported event types include regular event tracking, purchase event tracking, and cart update tracking.
* For each event, it extracts relevant data, including event name, data fields, items (for purchase and cart update events), and timestamps.
* It uses the Iterable API to track these events or update the user's cart.
* After processing all events, it calls the clearLocallyStoredData() method to clear locally stored event data.

### `clearLocallyStoredData()`

This method is responsible for clearing locally stored data in SharedPreferences. It removes both the anonymous session data and the event list data, effectively cleaning up after successful synchronization with the Iterable API.

### `storeEventListToLocalStorage(JSONObject newDataObject)`

This method is used to add a new event to the list of events stored in local storage. It takes a JSON object representing the new event data and performs the following steps:

* Retrieves the existing list of events from local storage using the getEventListFromLocalStorage() method.
* Appends the new event data to the list.
* Updates the event list data in SharedPreferences.

### `getEventListFromLocalStorage()`

This method retrieves the list of tracked events from local storage in SharedPreferences. It returns a JSONArray containing the stored event data. If no data is found or an error occurs during retrieval, it returns an empty JSONArray.

### `getCurrentTime()`

This method returns the current timestamp as a long value, representing the number of milliseconds

## Usage

You can use the `AnonymousUserManager` class to manage anonymous user sessions, track events, and determine when to create known users based on predefined criteria.

```java
// Example usage
AnonymousUserManager userManager = new AnonymousUserManager();
userManager.updateAnonSession();
userManager.trackAnonEvent("UserLoggedIn", userData);
userManager.trackAnonPurchaseEvent(100.0, items, otherData);
38 changes: 38 additions & 0 deletions AnonymousUserMerge.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# AnonymousUserMerge Class

## Class Introduction

The `AnonymousUserMerge` class is responsible for merging anonymous user with logged-in one.
It includes methods for merge user by userId and emailId.
We call methods of this class internally to merge user when setUserId or setEmail method call. After merge we sync events through Iterable API.

## Class Structure

The `AnonymousUserMerge` class includes the following key components:

- **Methods:**
- `mergeUserUsingUserId(apiClient: IterableApiClient, destinationUserId: String)`: Merge user using userID if anonymous user exists and sync events
- `mergeUserUsingEmail(apiClient: IterableApiClient, destinationEmail: String)`: Merge user using emailId if anonymous user exists and sync events
- `callMergeApi(apiClient: IterableApiClient, sourceEmail: String, sourceUserId: String, destinationEmail: String, destinationUserId: String)`: Call API to merge user and sync remaining events.

## Methods Description

### `mergeUserUsingUserId(apiClient: IterableApiClient, destinationUserId: String)`

This method merge the anonymous user with the logged-in one. It does the following:

* Check for user exists using userId.
* If user exists then call the merge user API.

### `mergeUserUsingEmail(apiClient: IterableApiClient, destinationEmail: String)`

This method merge the anonymous user with the logged-in one. It does the following:

* Check for user exists using emailId.
* If user exists then call the merge user API.

### `callMergeApi(apiClient: IterableApiClient, sourceEmail: String, sourceUserId: String, destinationEmail: String, destinationUserId: String)`

This method call API to merge user. It does the following:

* Call the Iterable API and sync remaining events.
135 changes: 135 additions & 0 deletions app/.idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ dependencies {
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'androidx.annotation:annotation:1.1.0'
implementation 'androidx.fragment:fragment:1.2.4'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
debugImplementation 'androidx.fragment:fragment-testing:1.2.4'

implementation project(':iterableapi')
Expand Down
9 changes: 8 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-sdk tools:overrideLibrary="androidx.security"/>

<uses-sdk tools:overrideLibrary="androidx.security" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name="com.iterable.androidsdk.AnonTrackingTestActivity"
android:exported="false" />
<activity
android:name="com.iterable.androidsdk.MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
Loading
Loading