Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

[ads] Trigger search result ad viewed event #8758

Closed
wants to merge 1 commit into from

Conversation

aseren
Copy link
Collaborator

@aseren aseren commented Feb 9, 2024

Summary of Changes

Corresponding brave-core change: brave/brave-core#21974

This pull request fixes brave/brave-browser#33469

Submitter Checklist:

  • Unit Tests are updated to cover new or changed functionality
  • User-facing strings use NSLocalizableString()
  • New or updated UI has been tested across:
    • Light & dark mode
    • Different size classes (iPhone, landscape, iPad)
    • Different dynamic type sizes

Test Plan:

  • Enable ShouldAlwaysRunBraveAdsService feature
  • Make sure that Brave Ads service is started
  • Trigger search result ad on search.brave.com
  • Check that search result ad served event was triggered in ads service. There should be [ads] Served search result ad with placement id log message
  • Check that search result ad viewed event was triggered in ads service. There should be [ads] Viewed search result ad with placement id log message

Screenshots:

Reviewer Checklist:

  • Issues include necessary QA labels:
    • QA/(Yes|No)
    • bug / enhancement
  • Necessary security reviews have taken place.
  • Adequate unit test coverage exists to prevent regressions.
  • Adequate test plan exists for QA to validate (if applicable).
  • Issue and pull request is assigned to a milestone (should happen at merge time).

@aseren aseren requested a review from a team as a code owner February 9, 2024 00:51
@aseren aseren requested a review from tmancey February 9, 2024 01:16
domainForMainFrame.isShieldExpected(.AdblockAndTp, considerAllShieldsOption: true)
domainForMainFrame.isShieldExpected(.AdblockAndTp, considerAllShieldsOption: true),

// Add Brave search result ads processing script.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be great to change this comment like the above comment, i.e., // This script will ...

self.rewards = rewards
}

func triggerSearchResultAdEvent(_ searchResultAdInfo: BraveAds.SearchResultAdInfo) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: triggerSearchResultAdViewedEvent

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.clicked event is missing

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed to triggerSearchResultAdViewedEvent. Clicked event support will be added as a follow-up

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes because we will not enable the feature via Griffin until click support is added. Perfect!

@@ -324,6 +329,8 @@ extension BrowserViewController: WKNavigationDelegate {
return (.cancel, preferences)
}

tab?.braveSearchResultAdManager = BraveSearchResultAdManager(url: requestURL, rewards: rewards, isPrivateBrowsing: isPrivateBrowsing)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if tab?.loadRequest(modifiedRequest) is called on line 328. I know that BraveSearchResultAdManager returns nil for Brave Rewards users, however it may not be clear to others in the future if/when these events are sent when ads are enabled.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if tab?.loadRequest(modifiedRequest) is called, then we will run this code again but with X-Brave-Ads-Enabled header. tab?.braveSearchResultAdManager will be nil because rewards are enabled. Seems like this works as expected.

var conversionInfo: BraveAds.ConversionInfo?
if let conversionUrlPatternValue = ad.conversionUrlPatternValue,
let conversionObservationWindowValue = ad.conversionObservationWindowValue {
let timeInterval = TimeInterval(conversionObservationWindowValue * 24 * 60 * 60)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe define 24 * 60 * 60 as a constant

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added private static secondsInDay = 24 * 60 * 60;

return
}

var conversionInfo: BraveAds.ConversionInfo?
Copy link
Collaborator

@tmancey tmancey Feb 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: var conversion: BraveAds.ConversionInfo

for ad in searchResultAds.creatives {
guard let rewardsValue = Double(ad.rewardsValue)
else {
Logger.module.error("Failed to process Brave search result ads")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ad not ads as this failure appears to be on a single ad

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe Failed to process search result ads JSON-LD

let messageData = try? JSONSerialization.data(withJSONObject: message.body, options: []),
let searchResultAds = try? JSONDecoder().decode(SearchResultAdResponse.self, from: messageData)
else {
Logger.module.error("Failed to process Brave search result ads")
Copy link
Collaborator

@tmancey tmancey Feb 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe Failed to pars search result ads response

)
}

let searchResultAdInfo: BraveAds.SearchResultAdInfo = .init(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: let searchResultAd...

Copy link
Collaborator

@tmancey tmancey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see comments. Thanks

Copy link
Contributor

@iccub iccub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move the pull request to brave-browser repo

@aseren
Copy link
Collaborator Author

aseren commented Feb 12, 2024

PR has been moved to brave/brave-core#21974

@aseren aseren closed this Feb 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ads] Unify iOS search result attribution
3 participants