diff --git a/apple/OmnivoreKit/Sources/App/Views/LinkItemDetailView.swift b/apple/OmnivoreKit/Sources/App/Views/LinkItemDetailView.swift index ec06cdbfb..6230a4cfb 100644 --- a/apple/OmnivoreKit/Sources/App/Views/LinkItemDetailView.swift +++ b/apple/OmnivoreKit/Sources/App/Views/LinkItemDetailView.swift @@ -67,6 +67,16 @@ enum PDFProvider { } } + func trackReadEvent() { + EventTracker.track( + .linkRead( + linkID: item.unwrappedID, + slug: item.unwrappedSlug, + originalArticleURL: item.unwrappedPageURLString + ) + ) + } + private func createWebAppWrapperViewModel(username: String, dataService: DataService, rawAuthCookie: String?) { let baseURL = dataService.appEnvironment.webAppBaseURL @@ -130,11 +140,14 @@ struct LinkItemDetailView: View { #if os(iOS) if viewModel.item.isPDF { fixedNavBarReader + .task { viewModel.trackReadEvent() } } else { WebReaderContainerView(item: viewModel.item, homeFeedViewModel: viewModel.homeFeedViewModel) + .task { viewModel.trackReadEvent() } } #else fixedNavBarReader + .task { viewModel.trackReadEvent() } #endif } diff --git a/apple/OmnivoreKit/Sources/App/Views/RootView/RootViewModel.swift b/apple/OmnivoreKit/Sources/App/Views/RootView/RootViewModel.swift index 213c8469a..3ed6b0654 100644 --- a/apple/OmnivoreKit/Sources/App/Views/RootView/RootViewModel.swift +++ b/apple/OmnivoreKit/Sources/App/Views/RootView/RootViewModel.swift @@ -31,7 +31,6 @@ public final class RootViewModel: ObservableObject { } func configurePDFProvider(pdfViewerProvider: @escaping (URL, PDFViewerViewModel) -> AnyView) { - EventTracker.track(TestEvent.testEventTwo(extraData: "invoked #configurePDFprovider function")) guard PDFProvider.pdfViewerProvider == nil else { return } PDFProvider.pdfViewerProvider = { [weak self] url, linkedItem in diff --git a/apple/OmnivoreKit/Sources/Models/DataModels/UserProfile.swift b/apple/OmnivoreKit/Sources/Models/DataModels/UserProfile.swift index 2c478a27e..18e0a3da1 100644 --- a/apple/OmnivoreKit/Sources/Models/DataModels/UserProfile.swift +++ b/apple/OmnivoreKit/Sources/Models/DataModels/UserProfile.swift @@ -46,11 +46,7 @@ public extension UserProfile { } public extension Viewer { - var unwrappedUsername: String { - username ?? "" - } - - var unwrappedName: String { - name ?? "" - } + var unwrappedUsername: String { username ?? "" } + var unwrappedName: String { name ?? "" } + var unwrappedUserID: String { userID ?? "" } } diff --git a/apple/OmnivoreKit/Sources/Services/DataService/Queries/ViewerFetcher.swift b/apple/OmnivoreKit/Sources/Services/DataService/Queries/ViewerFetcher.swift index bde4237dc..45215938f 100644 --- a/apple/OmnivoreKit/Sources/Services/DataService/Queries/ViewerFetcher.swift +++ b/apple/OmnivoreKit/Sources/Services/DataService/Queries/ViewerFetcher.swift @@ -69,6 +69,7 @@ private struct ViewerInternal { try context.save() logger.debug("Viewer saved succesfully") objectID = viewer.objectID + EventTracker.registerUser(userID: viewer.unwrappedUserID) } catch { context.rollback() logger.debug("Failed to save Viewer: \(error.localizedDescription)") diff --git a/apple/OmnivoreKit/Sources/Utils/EventTracking/EventTracker.swift b/apple/OmnivoreKit/Sources/Utils/EventTracking/EventTracker.swift index 4a130addc..57544845b 100644 --- a/apple/OmnivoreKit/Sources/Utils/EventTracking/EventTracker.swift +++ b/apple/OmnivoreKit/Sources/Utils/EventTracking/EventTracker.swift @@ -34,8 +34,3 @@ private let segment: Analytics? = { return Analytics(configuration: config) }() - -public protocol TrackableEvent { - var name: String { get } - var properties: [String: String]? { get } -} diff --git a/apple/OmnivoreKit/Sources/Utils/EventTracking/TrackableEvents.swift b/apple/OmnivoreKit/Sources/Utils/EventTracking/TrackableEvents.swift index b9b7cd708..b9f019961 100644 --- a/apple/OmnivoreKit/Sources/Utils/EventTracking/TrackableEvents.swift +++ b/apple/OmnivoreKit/Sources/Utils/EventTracking/TrackableEvents.swift @@ -1,26 +1,25 @@ import Foundation -public enum TestEvent { - case testEventOne - case testEventTwo(extraData: String) +public enum TrackableEvent { + case linkRead(linkID: String, slug: String, originalArticleURL: String) } -extension TestEvent: TrackableEvent { - public var name: String { +public extension TrackableEvent { + var name: String { switch self { - case .testEventOne: - return "testEventOne" - case .testEventTwo: - return "testEventTwo" + case .linkRead: + return "link_read" } } - public var properties: [String: String]? { + var properties: [String: String]? { switch self { - case .testEventOne: - return nil - case let .testEventTwo(extraData: extraData): - return ["extraData": extraData] + case let .linkRead(linkID: linkID, slug: slug, originalArticleURL: originalArticleURL): + return [ + "link": linkID, + "slug": slug, + "url": originalArticleURL + ] } } }