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

change api #1133

Merged
merged 6 commits into from
Dec 17, 2024
Merged

change api #1133

merged 6 commits into from
Dec 17, 2024

Conversation

SabrinaTardio
Copy link
Contributor

@SabrinaTardio SabrinaTardio commented Dec 16, 2024

Please review the release process for BrowserServicesKit here.

Required:

Task/Issue URL: https://app.asana.com/0/1204186595873227/1208964427775425/f
iOS PR: duckduckgo/iOS#3732
macOS PR: duckduckgo/macos-browser#3670
What kind of version bump will this require?: Minor

Optional:

Tech Design URL:
CC:

Description: Changes the name of the original fireExperimentPixel func and adds a new function where the framework does not manages the counting

Steps to test this PR:

  1. Run the app and check that the following pixel is sent: experiment_enroll_experimenttestaa_control (or treatment) with the expected parameters
  2. Perform 4 searches and foreground the app 4 times check that only one experiment pixel is fired: experiment_metrics_experimenttestaa_blue ["pixelSource": "browser-dmg", "metric": "search", "enrollmentDate": "2024-12-04", "value": "1", "conversionWindowDays": "0”]
  3. Move the system date to the following day and perform 4 searches and 4 foregorunding, only 2 pixels should be fired:
experiment_metrics_experimenttestaa_control ["pixelSource": "browser-dmg", "metric": "search", "enrollmentDate": "2024-12-05", "value": "1", "conversionWindowDays": “1”]
experiment_metrics_experimenttestaa_control ["pixelSource": "browser-dmg", "metric": “ app_use", "enrollmentDate": "2024-12-05", "value": "1", "conversionWindowDays": “1”]
  4. Try the same up to day 4
  5. On day 5 do the same and in this case you should see multiple pixels:
👾[Unique By Name And Parameters-Fired] experiment_metrics_experimenttestaa_control ["conversionWindowDays": "5", "value": "1", "enrollmentDate": "2024-12-04", "metric": "search", "pixelSource": "browser-dmg"]
👾[Unique By Name And Parameters-Fired] experiment_metrics_experimenttestaa_control ["pixelSource": "browser-dmg", "conversionWindowDays": "5-7", "enrollmentDate": "2024-12-04", "value": "1", "metric": "search"]
👾[Unique By Name And Parameters-Fired] experiment_metrics_experimenttestaa_control ["pixelSource": "browser-dmg", "value": "1", "conversionWindowDays": "5", "metric": "app_use", "enrollmentDate": "2024-12-04"]
👾[Unique By Name And Parameters-Fired] experiment_metrics_experimenttestaa_control ["metric": "app_use", "conversionWindowDays": "5-7", "pixelSource": "browser-dmg", "enrollmentDate": "2024-12-04", "value": "1"]
👾[Unique By Name And Parameters-Fired] experiment_metrics_experimenttestaa_control ["value": "4", "pixelSource": "browser-dmg", "conversionWindowDays": "5-7", "metric": "search", "enrollmentDate": "2024-12-04"]
👾[Unique By Name And Parameters-Fired] experiment_metrics_experimenttestaa_control ["value": "4", "enrollmentDate": "2024-12-04", "metric": "app_use", "pixelSource": "browser-dmg", "conversionWindowDays": "5-7”]

test use of new func

  1. In ContinueSetUpModel import PixelExprimentKit, actionCount var and set it to 0 add the following code on line 172 (default browser action)
actionCount += 1
PixelKit.fireExperimentPixel(for: ExperimentTestSubfeatures.experimentTestAA.rawValue, metric: "Provola", conversionWindowDays: 0...10, value: String(actionCount))
  1. Check that every time you click the button you see the experiment pixel sent with every time the updated value

OS Testing:

  • iOS 14
  • iOS 15
  • iOS 16
  • macOS 10.15
  • macOS 11
  • macOS 12

Internal references:

Software Engineering Expectations
Technical Design Template

/// 1. Validates if the experiment is active.
/// 2. Ensures the user is within the specified conversion window.
/// 3. Tracks actions performed and sends the pixel once the target value is reached (if applicable).
public static func fireExperimentPixelWhenReachingNumberOfCalls(for subfeatureID: SubfeatureID,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you have any better name suggestion do let me know!

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we could include "threshold" in the name, e.g:

fireExperimentPixelOnValueThreshold or fireExperimentPixelfThresholdReached

@SabrinaTardio SabrinaTardio marked this pull request as ready for review December 17, 2024 09:02
Copy link
Contributor

@aataraxiaa aataraxiaa left a comment

Choose a reason for hiding this comment

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

~~Thanks for the quick progress on this @SabrinaTardio. Left a few comments and tested this with my branch. The changes allow us to send pixels when the value param has changed. However, the API now also allows us to send the same pixel when the value is unchanged. I believe we still need to track the pixel that was sent so that we can ensure we don't send repeat pixels. ~~

EDIT: Nevermind the above, missed the uniqueness being handled in pixelkit

Comment on lines 97 to 104
// Define event
let event = event(for: subfeatureID, experimentData: experimentData, conversionWindowDays: conversionWindowDays, metric: metric, value: value)

// Send unique by name and parameter pixel if within conversion window
let isInWindow = isUserInConversionWindow(conversionWindowDays, enrollmentDate: experimentData.enrollmentDate)
if isInWindow {
ExperimentConfig.fireFunction(event, .uniqueByNameAndParameters, false)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor: We could avoid the creation of the event and return early by moving the conversion window check up:

Suggested change
// Define event
let event = event(for: subfeatureID, experimentData: experimentData, conversionWindowDays: conversionWindowDays, metric: metric, value: value)
// Send unique by name and parameter pixel if within conversion window
let isInWindow = isUserInConversionWindow(conversionWindowDays, enrollmentDate: experimentData.enrollmentDate)
if isInWindow {
ExperimentConfig.fireFunction(event, .uniqueByNameAndParameters, false)
}
// Check if within conversion window
guard isUserInConversionWindow(conversionWindowDays, enrollmentDate: experimentData.enrollmentDate) else { return }
// Define event
let event = event(for: subfeatureID, experimentData: experimentData, conversionWindowDays: conversionWindowDays, metric: metric, value: value)
ExperimentConfig.fireFunction(event, .uniqueByNameAndParameters, false)

/// 1. Validates if the experiment is active.
/// 2. Ensures the user is within the specified conversion window.
/// 3. Tracks actions performed and sends the pixel once the target value is reached (if applicable).
public static func fireExperimentPixelWhenReachingNumberOfCalls(for subfeatureID: SubfeatureID,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we could include "threshold" in the name, e.g:

fireExperimentPixelOnValueThreshold or fireExperimentPixelfThresholdReached

@@ -82,7 +82,7 @@ extension PixelKit {
/// This function:
/// 1. Validates if the experiment is active.
/// 2. Ensures the user is within the specified conversion window.
/// 3. Tracks actions performed and sends the pixel once the target value is reached (if applicable).
/// 3. Sends the pixel if not sent before (unique by name and parameter)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we not be storing the pixel that was sent in this method so that we can ensure pixels are unique? (i.e not sent again if they were sent before). When the value being sent is unchanged, this method fires the same pixel on subsequent calls.

Copy link
Contributor

Choose a reason for hiding this comment

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

Nevermind the above, missed the uniqueness being handled in pixelkit

Copy link
Contributor

@aataraxiaa aataraxiaa left a comment

Choose a reason for hiding this comment

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

Thanks @SabrinaTardio, works great! 🥳

@SabrinaTardio SabrinaTardio merged commit b71ed70 into main Dec 17, 2024
7 checks passed
@SabrinaTardio SabrinaTardio deleted the sabrina/change-experiment-api branch December 17, 2024 11:47
samsymons added a commit that referenced this pull request Dec 19, 2024
* main: (24 commits)
  change api (#1133)
  Ensure authToken is present before calling refreshAuthTokenIfNeeded
  Add 'locale' to report broken site params
  Add 'locale' to report broken site params
  Ensure authToken is present before calling refreshAuthTokenIfNeeded
  Privacy Pro Free Trials - Models and API (#1120)
  remove MaliciousSiteProtectionSubfeature (#1131)
  Malware protection 6: Malware integration (#1099)
  Add underlying error to PrivacyStatsError (#1130)
  Initial changes for compilation time tracking. (#1111)
  iOS System level credential provider (#1127)
  Increase ratio of complete form saves (#1124)
  Add PrivacyStatsError.failedToClearPrivacyStats (#1128)
  Update autofill to 16.0.0 (#1122)
  Update local network routing (#1117)
  Update RMF version matching to ignore build number (#1118)
  Fix threading issue between using a Semaphore and async/await (#1115)
  add experiment test fake feature (#1119)
  Bump Tests/BrowserServicesKitTests/Resources/privacy-reference-tests from `a603ff9` to `6133e7d` (#1109)
  experiment default metrics pixels (#1107)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants