diff --git a/Wikipedia/Code/AppInteractionFunnel.swift b/Wikipedia/Code/AppInteractionFunnel.swift index fe244682cb9..81065e6ccd1 100644 --- a/Wikipedia/Code/AppInteractionFunnel.swift +++ b/Wikipedia/Code/AppInteractionFunnel.swift @@ -90,8 +90,15 @@ import WMF logEvent(activeInterface: .setting, action: .donateStartClick) } - func logFundraisingCampaignModalImpression(project: WikimediaProject) { - logEvent(activeInterface: .articleBanner, action: .impression, project: project) + func logFundraisingCampaignModalImpression(project: WikimediaProject, campaignID: String?) { + + var actionData: [String: String]? + if let campaignID { + actionData = [:] + actionData?["campaign_id"] = campaignID + } + + logEvent(activeInterface: .articleBanner, action: .impression, actionData: actionData, project: project) } func logFundraisingCampaignModalDidTapClose(project: WikimediaProject) { diff --git a/Wikipedia/Code/ArticleViewController+Announcements.swift b/Wikipedia/Code/ArticleViewController+Announcements.swift index 2e50216f244..7283cdd2987 100644 --- a/Wikipedia/Code/ArticleViewController+Announcements.swift +++ b/Wikipedia/Code/ArticleViewController+Announcements.swift @@ -80,7 +80,7 @@ extension ArticleViewController { private func showNewDonateExperienceCampaignModal(asset: WKFundraisingCampaignConfig.WKAsset, project: WikimediaProject) { - AppInteractionFunnel.shared.logFundraisingCampaignModalImpression(project: project) + AppInteractionFunnel.shared.logFundraisingCampaignModalImpression(project: project, campaignID: asset.utmSource) let dataController = WKFundraisingCampaignDataController() @@ -126,15 +126,7 @@ extension ArticleViewController { let firstAction = asset.actions[0] let donateURL = firstAction.url - var utmSource: String? = nil - if let donateURL = firstAction.url, - let queryItems = URLComponents(url: donateURL, resolvingAgainstBaseURL: false)?.queryItems { - for queryItem in queryItems { - if queryItem.name == "utm_source" { - utmSource = queryItem.value - } - } - } + let utmSource = asset.utmSource let appVersion = Bundle.main.wmf_debugVersion() @@ -278,3 +270,26 @@ extension ArticleViewController: WKDonateLoggingDelegate { } + +extension WKFundraisingCampaignConfig.WKAsset { + + var utmSource: String? { + + guard actions.count > 0 else { + return nil + } + + let firstAction = actions[0] + var utmSource: String? = nil + if let donateURL = firstAction.url, + let queryItems = URLComponents(url: donateURL, resolvingAgainstBaseURL: false)?.queryItems { + for queryItem in queryItems { + if queryItem.name == "utm_source" { + utmSource = queryItem.value + } + } + } + + return utmSource + } +}