Skip to content

Commit

Permalink
Merge pull request #4664 from wikimedia/banner-impression-campaign-id
Browse files Browse the repository at this point in the history
Log campaign ID in banner impression event
  • Loading branch information
staykids authored Oct 18, 2023
2 parents b07a3be + e8b33d5 commit 5ac2dab
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
11 changes: 9 additions & 2 deletions Wikipedia/Code/AppInteractionFunnel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
35 changes: 25 additions & 10 deletions Wikipedia/Code/ArticleViewController+Announcements.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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
}
}

0 comments on commit 5ac2dab

Please sign in to comment.