Skip to content

[Feature] Unknown User Activation #730

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

Open
wants to merge 446 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
446 commits
Select commit Hold shift + click to select a range
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
3cf5e6d
sets up disableForegroundCriteriaFetching config value
Jan 15, 2025
5da3e52
adds missing comments to config file
Jan 15, 2025
6ac0049
Merge branch 'master' into feature/itbl-track-anon-user
Jan 16, 2025
7a02d68
Merge branch 'feature/itbl-track-anon-user' into evan/MOB-10615-impro…
evantk91 Jan 16, 2025
6c81086
cleanup
Jan 16, 2025
2ae35c8
adds anon user id to keychain and migrator
Jan 21, 2025
3a0859f
remove duplicate encryption handler
Jan 21, 2025
3e16143
removes anon user id migrator
Jan 22, 2025
026a784
addresses check
Jan 22, 2025
6ead82d
cleanup
Jan 22, 2025
ce342d0
resolves check
Jan 22, 2025
1e3e28d
Revert "resolves check"
Jan 22, 2025
f3d1bce
resolves check
Jan 22, 2025
7e659d8
resolves check
Jan 22, 2025
cc5eae9
addresses check
Jan 22, 2025
12f0cc4
Merge pull request #868 from Iterable/evan/MOB-10624-add-anonymous-us…
evantk91 Jan 23, 2025
edd365e
Merge branch 'feature/itbl-track-anon-user' into evan/MOB-10615-impro…
evantk91 Jan 23, 2025
3ef4fe5
updates naming
Jan 23, 2025
f76f3ee
adds criteria fetching on foregrounding
Jan 23, 2025
94ec39b
adds cooldown timer
Jan 23, 2025
9bac4e9
adds gating for disabling foreground criteria fetching
Jan 23, 2025
6ef4030
adds unit tests
Jan 27, 2025
7afe25f
addresses checks
Jan 27, 2025
94618c9
separates unit tests into new file
Jan 28, 2025
2b39e20
resolves check
Jan 28, 2025
41f2857
unit test fixes
Jan 28, 2025
f3471bd
addresses check
Jan 28, 2025
6f9a014
updates unit tests
Jan 28, 2025
f0ef193
added constant for criteria cooldown
Jan 28, 2025
ebead63
addresses comments
Jan 28, 2025
4593db8
minor corrections
Jan 28, 2025
3595432
updates config naming
Jan 28, 2025
720313b
sets up app state callback on AnonymousUserManager
Jan 28, 2025
44609c2
update unit tests
Jan 28, 2025
4ac4a81
minor updates
Jan 29, 2025
5a0b8dd
Merge pull request #863 from Iterable/evan/MOB-10615-improve-criteria…
evantk91 Jan 29, 2025
7aabcb2
Fix AUT issue where multiple users are created
megha-iterable Feb 4, 2025
60d30dc
adds unit test
Feb 14, 2025
eabab8b
Merge pull request #880 from Iterable/bugfix/AUT_issue_multiple_users…
evantk91 Feb 14, 2025
1d4c3bc
Merge branch 'master' into feature/itbl-track-anon-user
Jun 25, 2025
be522cc
renaming on config
Jul 7, 2025
3b8c1a7
updates anon user manager to unknown user manager
Jul 7, 2025
7d1674e
updates naming for UnknownUserMerge
Jul 7, 2025
1c273c3
renaming in IterableApi
Jul 7, 2025
2417c63
reverts endpoint renaming
Jul 7, 2025
4244fa9
continued renaming
Jul 7, 2025
4e99755
addresses check
Jul 7, 2025
c6540e4
addresses check
Jul 7, 2025
2ca491e
addresses check
Jul 7, 2025
5940b70
Merge pull request #919 from Iterable/evan/MOB-11686-renaming
evantk91 Jul 7, 2025
75b67c3
[MOB-10806] - Part 1. Fixes track calls with JWT in place
Jul 8, 2025
e54733e
adds timestamp to shared preferences
Jul 9, 2025
50c7881
removes unused imports
Jul 9, 2025
ca7d2a6
removes redundant function
Jul 9, 2025
f385a3e
Merge pull request #922 from Iterable/evan/MOB-11705
evantk91 Jul 10, 2025
c1560d8
adds track consent calls
Jul 14, 2025
b36d5a3
[MOB-10806 - 2] Part 2 fix
Jul 10, 2025
9791dc7
Merge branch 'feature/itbl-track-anon-user' into JWT-fix
evantk91 Jul 14, 2025
cb6f8d0
Merge branch 'JWT-fix' into merge-when-jwt
evantk91 Jul 15, 2025
267c0e5
minor edits
Jul 15, 2025
575e845
Merge branch 'feature/itbl-track-anon-user' into evan/MOB-11677-conse…
evantk91 Jul 15, 2025
1892e3f
minor logic cleanup
Jul 16, 2025
d5e7b0d
Merge pull request #923 from Iterable/merge-when-jwt
Ayyanchira Jul 16, 2025
a58b905
adds unit tests
Jul 16, 2025
4a60628
stashed changes
Jul 16, 2025
77515f7
updates consent logging call
Jul 16, 2025
8fd5392
removes fetching of time of consent
Jul 16, 2025
be85493
Merge pull request #920 from Iterable/JWT-fix
Ayyanchira Jul 17, 2025
a8ab8db
Merge branch 'feature/itbl-track-anon-user' into evan/MOB-11677-conse…
evantk91 Jul 17, 2025
525da5f
sets event replay and consent logging to occur once
Jul 17, 2025
59b1127
updates unit tests
Jul 17, 2025
34e2079
addresses checks
Jul 17, 2025
937242c
updates endpoints, payloads, and changelog
Jul 18, 2025
a80dee0
updates endpoint naming in unit tests
Jul 18, 2025
2ef7954
address checkstyle errors
Jul 18, 2025
12a4e92
addresses check
Jul 18, 2025
494a5d2
clears consent timestamp if consent is revoked
Jul 21, 2025
d570bcc
addresses check
Jul 21, 2025
86775bb
Merge pull request #926 from Iterable/evan/MOB-11686-renaming-endpoints
evantk91 Jul 21, 2025
4d87b3e
Merge branch 'master' into feature/itbl-track-anon-user
evantk91 Jul 21, 2025
31e8721
addresses comments and removes unnecessary flag
Jul 21, 2025
27e5c56
Merge branch 'feature/itbl-track-anon-user' into evan/MOB-11677-conse…
evantk91 Jul 21, 2025
0fe1d47
addresses check
Jul 21, 2025
db478b1
updates unit tests
Jul 22, 2025
ae8d983
addresses checks
Jul 22, 2025
4e69dd1
Merge pull request #924 from Iterable/evan/MOB-11677-consent-logging
evantk91 Jul 23, 2025
0c82456
[MOB-11814] - Prepare for Beta 3.6.0-beta3
Jul 30, 2025
1278edf
Merge pull request #932 from Iterable/Prepare-for-3.6.0-beta3
Ayyanchira Jul 30, 2025
a4d81fa
Merge branch 'master' into feature/itbl-track-anon-user
Jul 30, 2025
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