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 357 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
357 commits
Select commit Hold shift + click to select a range
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
b6b2025
MOB-9745 - Update mobile SDKs to support fetching a new JWT to use fo…
megha-iterable 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
d2be9ea
Merge branch 'feature/itbl-track-anon-user' into feature/MOB-9745-Use…
evantk91 Oct 24, 2024
949694f
removes GenerateJWTSucess callback and introduces new function for th…
Oct 28, 2024
6d3cb0d
updates null check for email
Oct 28, 2024
642f59a
adds check for auth handler
Oct 28, 2024
b9b8bde
addresses check
Oct 28, 2024
c8a0c36
updates auth handler check flow
Oct 28, 2024
307dadd
addresses check
Oct 28, 2024
527acc4
restores anonymous user clearing for setEmail
Oct 29, 2024
3062d52
removes sync events call from anonymous user manager
Oct 29, 2024
f1910d4
adds check for merge since return statement added
Oct 29, 2024
c6df5e5
Merge pull request #821 from Iterable/feature/MOB-9745-Use-destinatio…
evantk91 Oct 29, 2024
9027e94
renaming
Oct 30, 2024
dbe6471
Merge pull request #825 from Iterable/evan/MOB-10088-rename-setVisito…
evantk91 Oct 30, 2024
a818e81
renames config to enableAnonActivation
Oct 31, 2024
75f4f21
renames references to config
Oct 31, 2024
cee003c
Merge pull request #826 from Iterable/evan/MOB-10092-rename-config-to…
evantk91 Oct 31, 2024
9bd4618
moves clearing of anon user id
Nov 1, 2024
62bbef3
updates user update parsing
Nov 4, 2024
7782470
minor edit
Nov 4, 2024
2944287
Merge pull request #828 from Iterable/evan/MOB-10098
evantk91 Nov 4, 2024
6662883
removes update user change
Nov 4, 2024
3fa6de3
updates user update processing
Nov 5, 2024
96991ce
minor edits
Nov 5, 2024
3188724
removes return statement in syncEvents
Nov 5, 2024
8d090d2
stashed changes
Nov 5, 2024
592aa7b
removes markdown files
Nov 5, 2024
53fa126
Merge pull request #834 from Iterable/evan/MOB-10119
evantk91 Nov 5, 2024
889b1ac
removes assertion for testing event list
Nov 6, 2024
38d715f
Merge branch 'feature/itbl-track-anon-user' into evan/MOB-10094
evantk91 Nov 6, 2024
dd21046
Merge pull request #827 from Iterable/evan/MOB-10094
evantk91 Nov 6, 2024
a917955
updates testCriteriaMetEmailDefault test
Nov 6, 2024
da62844
updates unit test
Nov 6, 2024
26309f0
renaming
Nov 6, 2024
8df7f13
Merge branch 'feature/itbl-track-anon-user' into evan/MOB-10125
evantk91 Nov 6, 2024
27c9d19
Merge pull request #835 from Iterable/evan/MOB-10125
evantk91 Nov 6, 2024
1e855e3
unit test update
Nov 7, 2024
fbc9e3d
update unit tests
Nov 7, 2024
19883fd
Merge branch 'feature/itbl-track-anon-user' into evan/MOB-10098
evantk91 Nov 7, 2024
3f51428
reverts change
Nov 7, 2024
98cccbc
clears locally stored data when replay is false
Nov 7, 2024
2d858f3
testing
Nov 7, 2024
8fa32bb
testing
Nov 7, 2024
59b1603
updates user data passed to session
Nov 7, 2024
3a1f41a
Merge pull request #836 from Iterable/evan/MOB-10098
evantk91 Nov 7, 2024
2a22ebd
Merge branch 'feature/itbl-track-anon-user' into evan/MOB-10137
evantk91 Nov 7, 2024
f7cce92
Merge pull request #837 from Iterable/evan/MOB-10137
evantk91 Nov 7, 2024
1d39def
fixes update user bug
Nov 7, 2024
4d0091e
updates unit tests
Nov 7, 2024
b28e3d8
updating testCriteriaMetEmailDefault
Nov 7, 2024
d02980f
fixed assertions
Nov 7, 2024
83a807f
reverts unit tests
Nov 7, 2024
10c25ae
Merge pull request #838 from Iterable/evan/MOB-10109-update-merge-tests
evantk91 Nov 8, 2024
5f56098
updates testCriteriaMetEmailDefault
Nov 8, 2024
e6248c2
prepares for 3.6.0-beta release
Nov 8, 2024
2993980
updates unit test
Nov 8, 2024
e4b9657
updates testCriteriaNotMetUserIdDefault
Nov 8, 2024
6614413
updates unit test
Nov 8, 2024
fff2575
updates unit test
Nov 8, 2024
2e73a6b
updates unit test
Nov 8, 2024
3698ba3
updates unit test
Nov 8, 2024
65ca7df
updates unit test
Nov 8, 2024
4e5c6b0
updates unit tests for user id criteria not met
Nov 9, 2024
c3ed8bb
updates unit tests for user id paths
Nov 9, 2024
eab14b1
updates remaining email unit tests
Nov 9, 2024
ff711b7
updates pointers
Nov 11, 2024
5aed92b
updates identity resolution parameters
Nov 11, 2024
6ca540c
Merge pull request #839 from Iterable/evan/MOB-10109
evantk91 Nov 11, 2024
dca9271
Merge branch 'feature/itbl-track-anon-user' into evan/MOB-10116-3.6.0…
evantk91 Nov 11, 2024
3b87dec
Merge pull request #840 from Iterable/evan/MOB-10116-3.6.0-beta
evantk91 Nov 11, 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.
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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
package com.iterable.androidsdk;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.widget.EditText;
import com.iterable.iterableapi.CommerceItem;
import com.iterable.iterableapi.IterableApi;
import com.iterable.iterableapi.IterableConfig;
import com.iterable.iterableapi.IterableConstants;
import com.iterable.iterableapi.testapp.R;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;

public class AnonTrackingTestActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);

IterableConfig iterableConfig = new IterableConfig.Builder().setEnableAnonTracking(true).build();

// clear data for testing
SharedPreferences sharedPref = getSharedPreferences(IterableConstants.SHARED_PREFS_FILE, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPref.edit();
editor.putString(IterableConstants.SHARED_PREFS_ANON_SESSIONS, "");
editor.putString(IterableConstants.SHARED_PREFS_EVENT_LIST_KEY, "");
editor.apply();

new Handler().postDelayed(() -> {
IterableApi.initialize(getBaseContext(), "18845050c4774b7c9dc48beece2f6d8b", iterableConfig);
IterableApi.getInstance().setUserId(null);
IterableApi.getInstance().setEmail(null);

}, 1000);

findViewById(R.id.updateCart).setOnClickListener(view -> {
EditText updateCart_edit = findViewById(R.id.updateCart_edit);
if(updateCart_edit == null) return;
Log.d("TEST_USER", String.valueOf(updateCart_edit.getText()));
try {
JSONArray cartJSOnItems = new JSONArray(String.valueOf(updateCart_edit.getText()));
List<CommerceItem> items = new ArrayList<>();
for(int i = 0; i < cartJSOnItems.length(); i++) {
final JSONObject item = cartJSOnItems.getJSONObject(i);
items.add(new CommerceItem(item.getString("id"), item.getString("name"), item.getDouble("price"), item.getInt("quantity")));
}
IterableApi.getInstance().updateCart(items);
} catch (JSONException e) {
throw new RuntimeException(e);
}
});
findViewById(R.id.trackPurchase).setOnClickListener(view -> {
EditText purchase_items = findViewById(R.id.trackPurchase_edit);
if(purchase_items == null) return;
Log.d("TEST_USER", String.valueOf(purchase_items.getText()));

int total;

try {
JSONObject jsonData = new JSONObject(String.valueOf(purchase_items.getText()));
total = (int) jsonData.get("total");
JSONArray items_array = jsonData.getJSONArray("items");
List<CommerceItem> items = new ArrayList<>();
for(int i = 0; i < items_array.length(); i++) {
final JSONObject item = items_array.getJSONObject(i);
items.add(new CommerceItem(item.getString("id"), item.getString("name"), item.getDouble("price"), item.getInt("quantity")));
}
IterableApi.getInstance().trackPurchase(total, items);
} catch (JSONException e) {
throw new RuntimeException(e);
}
});
findViewById(R.id.customEvent).setOnClickListener(view -> {
EditText customEvent_edit = findViewById(R.id.customEvent_edit);
if(customEvent_edit == null) return;
Log.d("TEST_USER", String.valueOf(customEvent_edit.getText()));

try {
JSONObject customEventItem = new JSONObject(String.valueOf(customEvent_edit.getText()));
JSONObject items = new JSONObject(customEventItem.get("dataFields").toString());
if(customEventItem.has("eventName")) {
items.put("eventName", customEventItem.getString("eventName"));
}
IterableApi.getInstance().track("customEvent", 0, 0, items);
} catch (JSONException e) {
throw new RuntimeException(e);
}
});
findViewById(R.id.updateUser).setOnClickListener(view -> {
EditText updateUser_edit = findViewById(R.id.updateUser_edit);
if(updateUser_edit == null) return;
Log.d("TEST_USER", String.valueOf(updateUser_edit.getText()));

try {
JSONObject updateUserItem = new JSONObject(String.valueOf(updateUser_edit.getText()));
IterableApi.getInstance().updateUser(updateUserItem);

} catch (JSONException e) {
throw new RuntimeException(e);
}
});
findViewById(R.id.setUser).setOnClickListener(view -> {
EditText setUser_edit = findViewById(R.id.setUser_edit);
if(setUser_edit == null) return;

IterableApi.getInstance().setUserId(String.valueOf(setUser_edit.getText()));
});
findViewById(R.id.setEmail).setOnClickListener(view -> {
EditText setEmail_edit = findViewById(R.id.setEmail_edit);
if(setEmail_edit == null) return;

IterableApi.getInstance().setEmail(String.valueOf(setEmail_edit.getText()));
});

findViewById(R.id.btn_logout).setOnClickListener(view -> {
IterableApi.getInstance().setUserId(null);
});

}
}
Loading
Loading