Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ads] Add search result ad right button click handling #25786

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

aseren
Copy link
Collaborator

@aseren aseren commented Oct 2, 2024

Resolves brave/brave-browser#40785

Submitter Checklist:

  • I confirm that no security/privacy review is needed and no other type of reviews are needed, or that I have requested them
  • There is a ticket for my issue
  • Used Github auto-closing keywords in the PR description above
  • Wrote a good PR/commit description
  • Squashed any review feedback or "fixup" commits before merge, so that history is a record of what happened in the repo, not your PR
  • Added appropriate labels (QA/Yes or QA/No; release-notes/include or release-notes/exclude; OS/...) to the associated issue
  • Checked the PR locally:
    • npm run test -- brave_browser_tests, npm run test -- brave_unit_tests wiki
    • npm run presubmit wiki, npm run gn_check, npm run tslint
  • Ran git rebase master (if needed)

Reviewer Checklist:

  • A security review is not needed, or a link to one is included in the PR description
  • New files have MPL-2.0 license header
  • Adequate test coverage exists to prevent regressions
  • Major classes, functions and non-trivial code blocks are well-commented
  • Changes in component dependencies are properly reflected in gn
  • Code follows the style guide
  • Test plan is specified in PR before merging

After-merge Checklist:

Test Plan:

Test case 1

  • Start the Browser
  • Do not join Brave Rewards
  • Open search.brave.software
  • Search with giraffe keyword
  • Make sure that search result ad was shown
    • EXPECTATION: Search result ad viewed event is NOT triggered. There should be Brave Ads log:
      Search result ad: Not allowed to fire event
      Failed to fire search result ad kServedImpression event for placement_id %%% and creative instance id %%%
  • Click on the search result ad
    • EXPECTATION: Search result ad clicked event is triggered. There should be Brave Ads log:
      Clicked search result ad with placement id %%% and creative instance id %%%
      Successfully saved creative set conversions
  • Open conversion URL https://brave.com/vertical-tabs/ in a new tab:
    • EXPECTATION: Search result ad click conversion event is triggered. There should be Brave Ads log:
      Converted click conversion for kSearchResultAd with creative instance id %%%, creative set id d81220f2-b7c6-4f3e-b3fa-5e0f579407a5, campaign id %%% and advertiser id %%%

Test case 2

  • Start the Browser
  • Do not join Brave Rewards
  • Open search.brave.software
  • Search with giraffe keyword
  • Make sure that search result ad was shown
    • EXPECTATION: Search result ad viewed event is NOT triggered. There should be Brave Ads log:
      Search result ad: Not allowed to fire event
      Failed to fire search result ad kServedImpression event for placement_id %%% and creative instance id %%%
  • Do a CMD+RIGHT click to the search result ad to open it in a new tab in a background
    • EXPECTATION: Search result ad clicked event is triggered. There should be Brave Ads log:
      Clicked search result ad with placement id %%% and creative instance id %%%
  • Open conversion URL https://brave.com/vertical-tabs/ in a new tab:
    • EXPECTATION: Search result ad click conversion event is triggered. There should be Brave Ads log:
      Converted click conversion for kSearchResultAd with creative instance id %%%, creative set id d81220f2-b7c6-4f3e-b3fa-5e0f579407a5, campaign id %%% and advertiser id %%%

Test case 3

  • Start the Browser
  • Do not join Brave Rewards
  • Open search.brave.software
  • Search with giraffe keyword
  • Make sure that search result ad was shown
    • EXPECTATION: Search result ad viewed event is NOT triggered. There should be Brave Ads log:
      Search result ad: Not allowed to fire event
      Failed to fire search result ad kServedImpression event for placement_id %%% and creative instance id %%%
  • Open the search result ad in a new window (Open Link in New Window from context menu)
    • EXPECTATION: Search result ad clicked event is triggered. There should be Brave Ads log:
      Clicked search result ad with placement id %%% and creative instance id %%%
  • Open conversion URL https://brave.com/vertical-tabs/ in a new tab:
    • EXPECTATION: Search result ad click conversion event is triggered. There should be Brave Ads log:
      Converted click conversion for kSearchResultAd with creative instance id %%%, creative set id d81220f2-b7c6-4f3e-b3fa-5e0f579407a5, campaign id %%% and advertiser id %%%

Test case 4

  • Start the Browser
  • Join Brave Rewards
  • Open search.brave.software
  • Search with giraffe keyword
  • Make sure that search result ad was shown
    • EXPECTATION: Search result ad viewed event is triggered. There should be Brave Ads log:
      Viewed search result ad impression with placement id %%% and creative instance id %%%
  • Click on the search result ad
    • EXPECTATION: Search result ad clicked and landed events are triggered. There should be Brave Ads log:
      Clicked search result ad with placement id %%% and creative instance id %%%
      Successfully saved creative set conversions
      Maybe land on page for https://brave.com/brave-ads/?no_key_param= in 5 s
      Landed on page for https://brave.com/brave-ads/?no_key_param= on tab id %%%
  • Open conversion URL https://brave.com/vertical-tabs/ in a new tab:
    • EXPECTATION: Search result ad click conversion event is triggered. There should be Brave Ads log:
      Converted click conversion for kSearchResultAd with creative instance id %%%, creative set id d81220f2-b7c6-4f3e-b3fa-5e0f579407a5, campaign id %%% and advertiser id %%%

Test case 5

  • Start the Browser
  • Join Brave Rewards
  • Open search.brave.software
  • Search with giraffe keyword
  • Make sure that search result ad was shown
    • EXPECTATION: Search result ad viewed event is triggered. There should be Brave Ads log:
      Viewed search result ad impression with placement id %%% and creative instance id %%%
  • Open conversion URL https://brave.com/vertical-tabs/ in a new tab:
    • EXPECTATION: Search result ad view conversion event is triggered. There should be Brave Ads log:
      Converted view conversion for kSearchResultAd with creative instance id %%%, creative set id d81220f2-b7c6-4f3e-b3fa-5e0f579407a5, campaign id %%% and advertiser id %%%

Test case 6

  • Start the Browser
  • Join Brave Rewards
  • Open search.brave.software
  • Search with giraffe keyword
  • Make sure that search result ad was shown
    • EXPECTATION: Search result ad viewed event is triggered. There should be Brave Ads log:
      Viewed search result ad impression with placement id %%% and creative instance id %%%
  • Do a CMD+RIGHT click to the search result ad to open it in a new tab in a background
    • EXPECTATION: Search result ad clicked event is triggered. There should be Brave Ads log:
      Clicked search result ad with placement id %%% and creative instance id %%%
      Successfully saved creative set conversions
      Maybe land on page for https://brave.com/brave-ads/?no_key_param= in 5 s
      Suspended page landing on tab id 511936837 with 5 s remaining
  • Switch to the opened tab with ad
    • EXPECTATION: Search result ad landed event is triggered. There should be Brave Ads log:
      Landed on page for https://brave.com/brave-ads/?no_key_param= on tab id %%%
  • Open conversion URL https://brave.com/vertical-tabs/ in a new tab:
    • EXPECTATION: Search result ad click conversion event is triggered. There should be Brave Ads log:
      Converted click conversion for kSearchResultAd with creative instance id %%%, creative set id d81220f2-b7c6-4f3e-b3fa-5e0f579407a5, campaign id %%% and advertiser id %%%

Test case 7

  • Start the Browser
  • Join Brave Rewards
  • Open search.brave.software
  • Search with giraffe keyword
  • Make sure that search result ad was shown
    • EXPECTATION: Search result ad viewed event is triggered. There should be Brave Ads log:
      Viewed search result ad impression with placement id %%% and creative instance id %%%
  • Open the search result ad in a new window (Open Link in New Window from context menu)
    • EXPECTATION: Search result ad clicked and landed event is triggered. There should be Brave Ads log:
      Clicked search result ad with placement id %%% and creative instance id %%%
      Successfully saved creative set conversions
      Maybe land on page for https://brave.com/brave-ads/?no_key_param= in 5 s
      Landed on page for https://brave.com/brave-ads/?no_key_param= on tab id %%%
  • Open conversion URL https://brave.com/vertical-tabs/ in a new tab:
    • EXPECTATION: Search result ad click conversion event is triggered. There should be Brave Ads log:
      Converted click conversion for kSearchResultAd with creative instance id %%%, creative set id d81220f2-b7c6-4f3e-b3fa-5e0f579407a5, campaign id %%% and advertiser id %%%

Test case 8

  • Start the Browser
  • Do not join Brave Rewards
  • Open search.brave.software
  • Search with giraffe keyword
  • Make sure that search result ad was shown
  • Open the search result ad in a new Private window (Open Link in Private Window from context menu)
    • EXPECTATION: Search result ad clicked event NOT triggered. There should NOT be Brave Ads log:
      Clicked search result ad with placement id %%% and creative instance id %%%

@aseren aseren requested a review from a team as a code owner October 2, 2024 21:50
@github-actions github-actions bot added the chromium-version-mismatch The Chromium version on the PR branch does not match the version on the target branch label Oct 7, 2024
@aseren aseren requested a review from a team as a code owner October 16, 2024 16:25
@github-actions github-actions bot removed the chromium-version-mismatch The Chromium version on the PR branch does not match the version on the target branch label Oct 16, 2024
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.

LGTM++

Copy link
Contributor

[puLL-Merge] - brave/brave-core@25786

Here's my review of the pull request:

Description

This PR updates the handling of Brave Search Result Ads, primarily focusing on improving the management of ad events and caching mechanisms. The changes aim to enhance the efficiency and reliability of ad tracking, particularly for viewed and clicked events.

Changes

Changes

  1. browser/brave_ads/creatives/search_result_ad/creative_search_result_ad_tab_helper.cc/.h:

    • Refactored handling of creative ad viewed and clicked events.
    • Introduced a new method MaybeGetSearchResultAd to retrieve ad information.
    • Updated event triggering logic to use the new caching mechanism.
  2. components/brave_ads/core/internal/ad_units/creative_ad_cache.cc/.h:

    • Added a new CreativeAdCache class to manage caching of creative ads.
    • Implemented methods to add, retrieve, and purge ad information from the cache.
  3. components/brave_ads/core/internal/ads_impl.cc/.h:

    • Added MaybeGetSearchResultAd method to support retrieval of cached ad information.
  4. components/services/bat_ads/bat_ads_impl.cc/.h:

    • Updated to include the new MaybeGetSearchResultAd method.
  5. ios/brave-ios/Sources/Brave/Frontend/Browser/Search/BraveSearchResultAdManager.swift:

    • Refactored to use static methods for handling search result ad events.
    • Improved logic for determining when to trigger ad events.
  6. ios/browser/api/ads/brave_ads.h/.mm:

    • Added a new method triggerSearchResultAdClickedEvent to handle clicked events for search result ads.

Possible Issues

  1. The caching mechanism introduces a new layer of complexity. Ensure that the cache is properly cleared when tabs are closed or when ads become irrelevant to prevent memory leaks or stale data.

  2. The iOS changes involve a significant refactor of the BraveSearchResultAdManager. Thorough testing should be done to ensure that all ad events are still triggered correctly on iOS devices.

Security Hotspots

No major security concerns were identified in this change. However, careful handling of user data and ad information should always be maintained, especially when implementing new caching mechanisms.

Overall, this PR appears to improve the management of Brave Search Result Ads by introducing more efficient caching and event handling. The changes seem well-structured and should enhance the performance and reliability of ad-related features in Brave browser.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ads] Clicks, conversions, and site visits do not work if a search result ad was opened in a new tab or window
3 participants