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 SmartNTT virtual prefs and condition matchers #26284

Merged
merged 10 commits into from
Oct 30, 2024
Merged

Conversation

tmancey
Copy link
Collaborator

@tmancey tmancey commented Oct 29, 2024

Resolves brave/brave-browser#41927

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:

Adds support for the following virtual pref condition matchers:

{
   "[virtual]:browser": {
      "build_channel": "nightly",
      "version": "131.1.73.0"
   },
   "[virtual]:operating_system": {
      "locale": {
         "language": "en",
         "region": "KY"
      },
      "name": "Mac OS X"
   },
   "[virtual]:search_engine": {
      "default_name": "Brave"
   },
   "[virtual]:skus": {
      "production": {
         "talk.brave.com": {
            "created_at": "2023-05-05T12:26:57",
            "expires_at": "2024-05-04T13:44:55",
            "last_paid_at": "2024-04-05T13:44:55",
            "status": "paid"
         },
         "vpn.brave.com": {
            "created_at": "2023-02-23T21:49:34",
            "expires_at": "2024-09-24T21:49:57",
            "last_paid_at": "2024-08-25T21:49:57",
            "status": "canceled"
         }
      }
   }
}

where operating_system.name can be "Windows", "Mac OS X", "Linux", "Android", "iOS", or "Unknown".

where SKUs status can be either beta, trial, paid, or canceled.

Example to match if running on a desktop operating system:

"conditionMatchers": [
  {
    "condition": "^(Windows|Mac OS X|Linux)$",
    "prefPath": "[virtual]:operating_system|name"
  }
]

Example to match if a VPN premium subscription is canceled and expired 30 or more days ago:

"conditionMatchers": [
  {
    "condition": "[T]≥30",
    "prefPath": "[virtual]:skus|production|vpn.brave.com|expires_at"
  },
  {
    "condition": "canceled",
    "prefPath": "[virtual]:skus|production|vpn.brave.com|status"
  }
]

--

[numerical operator]:number condition matcher which supports the following operators:

  • 'R=': Equal
  • 'R≠': Not equal
  • 'R>': Greater than
  • 'R≥': Greater than or equal to
  • 'R<': Less than
  • 'R≤': Less than or equal to

This matcher triggers an ad based on when a real number (integers or fractions) stored at "prefPath". For instance, the example below will serve an ad only if the value stored at "foo.bar" is not equal to 3:

"conditionMatchers": [
  {
    "condition": "[R≠]:3",
    "prefPath": "foo.bar"
  }
]

Also, changes epoch condition matchers from [?]:* to [T?]:*. Epoch condition matchers now support IOS 8601 date and time stored as string values at the pref path, i.e. 2024-09-30T19:00:00T, 30 Sept 2024 19:00:00 EST etc.

@tmancey tmancey force-pushed the issues/41927 branch 7 times, most recently from 2c363fd to 91ae0d6 Compare October 29, 2024 16:00
browser/brave_ads/ads_service_delegate.cc Outdated Show resolved Hide resolved
Copy link
Contributor

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

Description

This PR introduces significant changes to the Brave Ads targeting and condition matching system. It refactors and expands the existing condition matcher functionality, improving its flexibility and capabilities. The changes include new types of condition matchers, reorganization of the code structure, and updates to related components.

Changes

Changes

  1. components/brave_ads/core/internal/serving/:

    • Removed new_tab_page_ad_serving_condition_matcher_util.cc and new_tab_page_ad_serving_condition_matcher_util_internal.cc.
    • Added new directory structure under targeting/condition_matcher/ with new files for different types of matchers and utility functions.
  2. components/brave_ads/core/public/serving/:

    • Renamed and moved new_tab_page_ad_serving_condition_matcher_util.h to targeting/condition_matcher/condition_matcher_util.h.
    • Updated the header file with more comprehensive documentation and new matcher types.
  3. components/brave_ads/core/internal/common/test/:

    • Moved and renamed some test utility files.
  4. components/ntp_background_images/browser/:

    • Updated view_counter_service.cc and view_counter_service.h to use the new ConditionMatcherMap instead of NewTabPageAdConditionMatchers.
  5. Various files:

    • Updated imports and namespaces to reflect the new file structure.
    • Renamed NewTabPageAdConditionMatchers to ConditionMatcherMap.
  6. Added new condition matcher types:

    • Epoch operator matcher
    • Numerical operator matcher
    • Regex matcher
    • Pattern matcher
  7. Updated the documentation in condition_matcher_util.h to explain the new matchers and provide examples.

  8. Added new virtual preferences for browser version, operating system information, and SKUs.

  9. Various test files have been added or updated to cover the new functionality.

Possible Issues

  • The extensive refactoring might require updates in other parts of the codebase that are not visible in this diff.
  • There might be a need for migration of existing condition matchers to the new format.

Security Hotspots

No significant security issues are apparent in this change. However, careful testing should be done to ensure that the new condition matching system doesn't unintentionally expose sensitive information or allow for unintended ad targeting.

@tmancey tmancey merged commit f98f048 into master Oct 30, 2024
17 checks passed
@tmancey tmancey deleted the issues/41927 branch October 30, 2024 00:13
@github-actions github-actions bot added this to the 1.73.x - Nightly milestone Oct 30, 2024
@brave-builds
Copy link
Collaborator

Released in v1.73.59

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] Add SmartNTT virtual prefs and condition matchers
3 participants