File tree Expand file tree Collapse file tree 1 file changed +26
-1
lines changed
WooCommerce/Classes/Analytics Expand file tree Collapse file tree 1 file changed +26
-1
lines changed Original file line number Diff line number Diff line change 11import Foundation
22import UIKit
33import WordPressShared
4+ import WidgetKit
45
56public 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
You can’t perform that action at this time.
0 commit comments