Skip to content

Commit

Permalink
Add missing file after PR merge
Browse files Browse the repository at this point in the history
  • Loading branch information
hani-iterable committed Dec 27, 2023
1 parent 0ebe2d1 commit 594b83c
Show file tree
Hide file tree
Showing 15 changed files with 842 additions and 214 deletions.
19 changes: 13 additions & 6 deletions AnonymousUserEventTracking.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

## Class Introduction

The `AnonymousUserManager` class is responsible for managing anonymous user sessions and tracking events.
It includes methods for updating sessions, tracking events (i.e regular, update cart and purchase) and create a user if criterias are met.
The `AnonymousUserManager` class is responsible for managing anonymous user sessions and tracking events.
The `AnonymousUserManager+Functions` class is contains util functions and `CriteriaCompletionChecker` struct which contains criteria checking logic.
It includes methods for updating sessions, tracking events (i.e custom event, update cart, update user and purchase) and create a user if criterias are met.
We call track methods of this class internally to make sure we have tracked the events even when user is NOT logged in and after certain criterias are met we create a user and logs them automatically and sync events through Iterable API.

## Class Structure
Expand All @@ -14,6 +15,7 @@ The `AnonymousUserManager` class includes the following key components:
- `updateAnonSession()`: Updates the anonymous user session.
- `trackAnonEvent(name: String, dataFields: [AnyHashable: Any]?)`: Tracks an anonymous event and store it locally.
- `trackAnonPurchaseEvent(total: NSNumber, items: [CommerceItem], dataFields: [AnyHashable: Any]?)`: Tracks an anonymous purchase event and store it locally.
- `trackAnonUpdateUser(_ dataFields: [AnyHashable: Any])`: Tracks an anonymous update user event and store it locally.
- `trackAnonUpdateCart(items: [CommerceItem])`: Tracks an anonymous cart event and store it locally.
- `trackAnonTokenRegistration(token: String)`: Tracks an anonymous token registration event and store it locally.
- `getAnonCriteria()`: Gets the anonymous criteria.
Expand All @@ -26,10 +28,7 @@ The `AnonymousUserManager` class includes the following key components:
- `syncNonSyncedEvents()`: Syncs unsynced data which might have failed to sync when calling syncEvents for the first time after criterias met.
- `convertCommerceItems(from dictionaries: [[AnyHashable: Any]]) -> [CommerceItem]`: Convert to commerce items from dictionaries.
- `convertCommerceItemsToDictionary(_ items: [CommerceItem]) -> [[AnyHashable:Any]]`: Convert commerce items to dictionaries.
- `filterEvents(byType type: String) -> [[AnyHashable: Any]]?`: Filter events by type.
- `filterEvents(byType type: String, andName name: String?) -> [[AnyHashable: Any]]?`: Filter events by type and name.
- `getUTCDateTime()`: Converts UTC Datetime from current time.
- `filterEvents(excludingTimestamps excludedTimestamps: [Int]) -> [[AnyHashable: Any]]?`: Filter non-synced data.


## Methods Description
Expand Down Expand Up @@ -59,6 +58,14 @@ This method tracks an anonymous purchase event. It does the following:
* Stores the purchase event data in local storage.
* Checks criteria completion and creates a known user if criteria are met.

### `trackAnonUpdateUser(dataFields: [AnyHashable: Any]?)`

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

* Creates a dictionary object with event details, including the event name, timestamp, data fields, and tracking type.
* Stores the event data in local storage, and if data of this event already exists it replaces the data.
* Checks criteria completion and creates a known user if criteria are met.

### `trackAnonUpdateCart(items: [CommerceItem])`

This method tracks an anonymous cart update. It does the following:
Expand All @@ -78,7 +85,7 @@ This method is responsible for fetching criteria data. It simulates calling an A

### `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.
This private method checks if criteria for creating a known user are met. It compares stored event data with predefined criteria and returns `criteriaId` if any of the criteria is matched.

### `createKnownUser()`

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
objects = {

/* Begin PBXBuildFile section */
37088F332B3C38250000B218 /* IterableAppExtensions in Frameworks */ = {isa = PBXBuildFile; productRef = 37088F322B3C38250000B218 /* IterableAppExtensions */; };
37088F352B3C38250000B218 /* IterableSDK in Frameworks */ = {isa = PBXBuildFile; productRef = 37088F342B3C38250000B218 /* IterableSDK */; };
551A5FF1251AB1950004C9A0 /* IterableSDK in Frameworks */ = {isa = PBXBuildFile; productRef = 551A5FF0251AB1950004C9A0 /* IterableSDK */; };
551A5FF3251AB19B0004C9A0 /* IterableAppExtensions in Frameworks */ = {isa = PBXBuildFile; productRef = 551A5FF2251AB19B0004C9A0 /* IterableAppExtensions */; };
AC1BDF5820E304BC000010CA /* CoffeeListTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = AC5ECD9E20E304000081E1DA /* CoffeeListTableViewController.swift */; };
Expand Down Expand Up @@ -73,13 +75,15 @@
buildActionMask = 2147483647;
files = (
551A5FF1251AB1950004C9A0 /* IterableSDK in Frameworks */,
37088F352B3C38250000B218 /* IterableSDK in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
ACA3A14B20E2F83D00FEF74F /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
37088F332B3C38250000B218 /* IterableAppExtensions in Frameworks */,
551A5FF3251AB19B0004C9A0 /* IterableAppExtensions in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -202,6 +206,7 @@
name = "swift-sample-app";
packageProductDependencies = (
551A5FF0251AB1950004C9A0 /* IterableSDK */,
37088F342B3C38250000B218 /* IterableSDK */,
);
productName = "swift-sample-app";
productReference = ACA3A13520E2F6AF00FEF74F /* swift-sample-app.app */;
Expand All @@ -222,6 +227,7 @@
name = "swift-sample-app-notification-extension";
packageProductDependencies = (
551A5FF2251AB19B0004C9A0 /* IterableAppExtensions */,
37088F322B3C38250000B218 /* IterableAppExtensions */,
);
productName = "swift-sample-app-notification-extension";
productReference = ACA3A14E20E2F83D00FEF74F /* swift-sample-app-notification-extension.appex */;
Expand Down Expand Up @@ -264,6 +270,8 @@
Base,
);
mainGroup = ACA3A12C20E2F6AF00FEF74F;
packageReferences = (
);
productRefGroup = ACA3A13620E2F6AF00FEF74F /* Products */;
projectDirPath = "";
projectRoot = "";
Expand Down Expand Up @@ -572,6 +580,14 @@
/* End XCConfigurationList section */

/* Begin XCSwiftPackageProductDependency section */
37088F322B3C38250000B218 /* IterableAppExtensions */ = {
isa = XCSwiftPackageProductDependency;
productName = IterableAppExtensions;
};
37088F342B3C38250000B218 /* IterableSDK */ = {
isa = XCSwiftPackageProductDependency;
productName = IterableSDK;
};
551A5FF0251AB1950004C9A0 /* IterableSDK */ = {
isa = XCSwiftPackageProductDependency;
productName = IterableSDK;
Expand Down
7 changes: 4 additions & 3 deletions swift-sdk/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ enum Endpoint {
}

enum EventType {
static let track = "track"
static let trackPurchase = "trackPurchase"
static let customEvent = "customEvent"
static let purchase = "purchase"
static let updateUser = "updateUser"
static let cartUpdate = "cartUpdate"
static let anonSession = "anonSession"
static let tokenRegistration = "tokenRegistration"
Expand Down Expand Up @@ -187,7 +188,7 @@ enum JsonKey {
static let contentType = "Content-Type"

static let createNewFields = "createNewFields"
static let eventType = "eventType"
static let eventType = "dataType"
static let eventTimeStamp = "eventTimeStamp"

enum ActionButton {
Expand Down
Loading

0 comments on commit 594b83c

Please sign in to comment.