Skip to content

Commit 402273e

Browse files
committed
Update analytics opened event to contains a list of widgets installed
1 parent 0a10e8d commit 402273e

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

WooCommerce/Classes/Analytics/WooAnalytics.swift

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Foundation
22
import UIKit
33
import WordPressShared
4+
import WidgetKit
45

56
public class WooAnalytics: Analytics {
67

@@ -180,7 +181,10 @@ private extension WooAnalytics {
180181
}
181182

182183
@objc func trackApplicationOpened() {
183-
track(.applicationOpened)
184+
WidgetCenter.shared.getCurrentConfigurations { [weak self] configurationResult in
185+
guard let self = self else { return }
186+
self.track(.applicationOpened, withProperties: self.applicationOpenedProperties(configurationResult))
187+
}
184188
applicationOpenedTime = Date()
185189
}
186190

@@ -211,6 +215,27 @@ private extension WooAnalytics {
211215
updatedProperties[PropertyKeys.wpcomStoreKey] = site?.isWordPressStore
212216
return updatedProperties
213217
}
218+
219+
/// Buildes the necesary properties for the `application_opened` event.
220+
///
221+
func applicationOpenedProperties(_ configurationResult: Result<[WidgetInfo], Error>) -> [String: [String]] {
222+
guard let installedWidgets = try? configurationResult.get() else {
223+
return ["widgets": []]
224+
}
225+
226+
// Translate the widget kind into a name recognized by tracks.
227+
let widgetAnalyticNames: [String] = installedWidgets.map { widgetInfo in
228+
switch widgetInfo.kind {
229+
case WooConstants.storeInfoWidgetKind:
230+
return WooAnalyticsEvent.Widgets.Name.todayStats.rawValue
231+
default:
232+
DDLogWarn("⚠️ Make sure the widget: \(widgetInfo.kind), has the correct tracks name.")
233+
return widgetInfo.kind
234+
}
235+
}
236+
237+
return ["widgets": widgetAnalyticNames]
238+
}
214239
}
215240

216241

0 commit comments

Comments
 (0)