Skip to content

Commit 92d5f45

Browse files
[Tracks] Send site related properties in application level tracking events (#15173)
2 parents b610727 + 33080c4 commit 92d5f45

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

WooCommerce/Classes/Analytics/WooAnalyticsStat.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,14 +1316,11 @@ extension WooAnalyticsStat {
13161316
/// Indicates if site information should be included with this event when it's sent to the tracks server.
13171317
/// Returns `true` if it should be included, `false` otherwise.
13181318
///
1319-
/// Note: Currently all application-level and authentication events will return false. If you wish
1319+
/// Note: Currently all authentication events will return false. If you wish
13201320
/// to include additional no-site-info events, please add them here.
13211321
///
13221322
var shouldSendSiteProperties: Bool {
13231323
switch self {
1324-
// Application events
1325-
case .applicationClosed, .applicationOpened, .applicationUpgraded, .applicationInstalled, .watchAppOpened:
1326-
return false
13271324
// Authentication Events
13281325
case .signedIn, .logout, .openedLogin, .loginFailed,
13291326
.loginAutoFillCredentialsFilled, .loginAutoFillCredentialsUpdated, .loginEmailFormViewed, .loginMagicLinkOpenEmailClientViewed,

WooCommerce/Classes/Yosemite/DefaultStoresManager.swift

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,26 @@ private extension DefaultStoresManager {
534534
dispatch(action)
535535
}
536536

537+
/// Implements a retry logic for fetching the store information i.e. `store_id` to reduce the chances of it being missing.
538+
/// We use three attempts with an exponential backoff.
539+
///
540+
@MainActor
541+
func fetchSystemInformationAndRetryIfFails(siteID: Int64,
542+
retryCount: Int = 0) async -> SystemInformation? {
543+
guard retryCount <= 3 else {
544+
return nil
545+
}
546+
547+
let waitTime = Int(pow(Double(2), Double(retryCount)))
548+
try? await Task.sleep(for: .seconds(waitTime))
549+
550+
if let info = await synchronizeSystemInformation(siteID: siteID) {
551+
return info
552+
} else {
553+
return await fetchSystemInformationAndRetryIfFails(siteID: siteID, retryCount: retryCount + 1)
554+
}
555+
}
556+
537557
/// Synchronizes all system information for the store with specified ID.
538558
/// When finished, loads the store uuid into the session.
539559
///
@@ -646,7 +666,7 @@ private extension DefaultStoresManager {
646666
Task { @MainActor in
647667
// Order statuses and system plugins syncing are required outside of snapshot tracking.
648668
async let orderStatuses = retrieveOrderStatus(with: siteID)
649-
async let systemInformation = synchronizeSystemInformation(siteID: siteID)
669+
async let systemInformation = fetchSystemInformationAndRetryIfFails(siteID: siteID)
650670

651671
trackSnapshotIfNeeded(siteID: siteID, orderStatuses: await orderStatuses, systemPlugins: await systemInformation?.systemPlugins)
652672
}

0 commit comments

Comments
 (0)