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

Workaround to support ExPlat in Jetpack app #20607

Merged
merged 15 commits into from
May 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ abstract_target 'Apps' do

# Production

pod 'Automattic-Tracks-iOS', '~> 0.13'
pod 'Automattic-Tracks-iOS', '~> 2.2'
# While in PR
# pod 'Automattic-Tracks-iOS', git: 'https://github.com/Automattic/Automattic-Tracks-iOS.git', branch: ''
# Local Development
Expand Down Expand Up @@ -404,7 +404,7 @@ pre_install do |installer|
installer.pod_targets.each do |pod|
# Statically linking Sentry results in a conflict with `NSDictionary.objectAtKeyPath`, but dynamically
# linking it resolves this.
if pod.name == 'Sentry'
if %w[Sentry SentryPrivate].include? pod.name
dynamic << pod
next
end
Expand Down
27 changes: 16 additions & 11 deletions Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ PODS:
- AppCenter/Core
- AppCenter/Distribute (4.4.1):
- AppCenter/Core
- Automattic-Tracks-iOS (0.13.0):
- Sentry (~> 7.25)
- Automattic-Tracks-iOS (2.2.0):
- Sentry (~> 8.0)
- Sodium (>= 0.9.1)
- UIDeviceIdentifier (~> 2.0)
- boost (1.76.0)
Expand Down Expand Up @@ -490,14 +490,17 @@ PODS:
- SDWebImageWebPCoder (0.8.5):
- libwebp (~> 1.0)
- SDWebImage/Core (~> 5.10)
- Sentry (7.27.0):
- Sentry/Core (= 7.27.0)
- Sentry/Core (7.27.0)
- Sentry (8.6.0):
- Sentry/Core (= 8.6.0)
- SentryPrivate (= 8.6.0)
- Sentry/Core (8.6.0):
- SentryPrivate (= 8.6.0)
- SentryPrivate (8.6.0)
- Sodium (0.9.1)
- Starscream (3.0.6)
- SVProgressHUD (2.2.5)
- SwiftLint (0.50.3)
- UIDeviceIdentifier (2.1.0)
- UIDeviceIdentifier (2.3.0)
- WordPress-Aztec-iOS (1.19.8)
- WordPress-Editor-iOS (1.19.8):
- WordPress-Aztec-iOS (= 1.19.8)
Expand Down Expand Up @@ -541,7 +544,7 @@ DEPENDENCIES:
- AlamofireNetworkActivityIndicator (~> 2.4)
- AppCenter (~> 4.1)
- AppCenter/Distribute (~> 4.1)
- Automattic-Tracks-iOS (~> 0.13)
- Automattic-Tracks-iOS (~> 2.2)
- boost (from `https://raw.githubusercontent.com/wordpress-mobile/gutenberg-mobile/v1.94.0/third-party-podspecs/boost.podspec.json`)
- BVLinearGradient (from `https://raw.githubusercontent.com/wordpress-mobile/gutenberg-mobile/v1.94.0/third-party-podspecs/BVLinearGradient.podspec.json`)
- CocoaLumberjack/Swift (~> 3.0)
Expand Down Expand Up @@ -651,6 +654,7 @@ SPEC REPOS:
- SDWebImage
- SDWebImageWebPCoder
- Sentry
- SentryPrivate
- Sodium
- Starscream
- SVProgressHUD
Expand Down Expand Up @@ -800,7 +804,7 @@ SPEC CHECKSUMS:
AlamofireNetworkActivityIndicator: 9acc3de3ca6645bf0efed462396b0df13dd3e7b8
AppAuth: e48b432bb4ba88b10cb2bcc50d7f3af21e78b9c2
AppCenter: b0b6f1190215b5f983c42934db718f3b46fff3c0
Automattic-Tracks-iOS: 63e55654f500b3e8fb35087e64575e00d12eb2f5
Automattic-Tracks-iOS: a1b020ab02f0e5a39c5d4e6870a498273f286158
boost: 32a63928ef0a5bf8b60f6b930c8864113fa28779
BVLinearGradient: 708898fab8f7113d927b0ef611a321e759f6ad3e
CocoaLumberjack: 78abfb691154e2a9df8ded4350d504ee19d90732
Expand Down Expand Up @@ -871,12 +875,13 @@ SPEC CHECKSUMS:
RNTAztecView: 80480c43423929f7e3b7012670787e7375fbac9c
SDWebImage: a7f831e1a65eb5e285e3fb046a23fcfbf08e696d
SDWebImageWebPCoder: 908b83b6adda48effe7667cd2b7f78c897e5111d
Sentry: 026b36fdc09531604db9279e55f047fe652e3f4a
Sentry: d80553ff85ea72def75b792aaa5a71c158e51595
SentryPrivate: ef1c5b3dfe44ec0c70e2eb343a5be2689164c021
Sodium: 23d11554ecd556196d313cf6130d406dfe7ac6da
Starscream: ef3ece99d765eeccb67de105bfa143f929026cf5
SVProgressHUD: 1428aafac632c1f86f62aa4243ec12008d7a51d6
SwiftLint: 77f7cb2b9bb81ab4a12fcc86448ba3f11afa50c6
UIDeviceIdentifier: e6a801d25f4f178de5bdf475ffe29050d0148176
UIDeviceIdentifier: 442b65b4ff1832d4ca9c2a157815cb29ad981b17
WordPress-Aztec-iOS: 7d11d598f14c82c727c08b56bd35fbeb7dafb504
WordPress-Editor-iOS: 9eb9f12f21a5209cb837908d81ffe1e31cb27345
WordPressAuthenticator: b0b900696de5129a215adcd1e9ae6eb89da36ac8
Expand All @@ -895,6 +900,6 @@ SPEC CHECKSUMS:
ZendeskSupportSDK: 3a8e508ab1d9dd22dc038df6c694466414e037ba
ZIPFoundation: ae5b4b813d216d3bf0a148773267fff14bd51d37

PODFILE CHECKSUM: d48e2c793016c27a80eba0bc3b3ccb30ee05ba6f
PODFILE CHECKSUM: ab88bd849ac377484fd7f0c4b079701ce16de5a3

COCOAPODS: 1.11.3
5 changes: 4 additions & 1 deletion WordPress/Classes/Services/SiteAddressService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ final class DomainsServiceAdapter: SiteAddressService {

// MARK: Properties

private let domainPurchasingEnabled = FeatureFlag.siteCreationDomainPurchasing.enabled
/// Checks if the Domain Purchasing Feature Flag and AB Experiment are enabled
private var domainPurchasingEnabled: Bool {
FeatureFlag.siteCreationDomainPurchasing.enabled && ABTest.siteCreationDomainPurchasing.isTreatmentVariation
}

/**
Corresponds to:
Expand Down
22 changes: 16 additions & 6 deletions WordPress/Classes/Utility/AB Testing/ABTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,35 @@ import AutomatticTracks
// Jetpack is not supported
enum ABTest: String, CaseIterable {
case unknown = "unknown"
case siteCreationDomainPurchasing = "jpios_site_creation_domain_purchasing_v1"

/// Returns a variation for the given experiment
var variation: Variation {
return ExPlat.shared?.experiment(self.rawValue) ?? .control
}

/// Flag indicating whether the experiment's variation is treament or not.
var isTreatmentVariation: Bool {
switch variation {
case .treatment, .customTreatment: return true
case .control: return false
}
}
}

extension ABTest {
/// Start the AB Testing platform if any experiment exists
///
static func start() {
guard ABTest.allCases.count > 1, AccountHelper.isLoggedIn,
AppConfiguration.isWordPress else {
guard ABTest.allCases.count > 1,
AccountHelper.isLoggedIn,
AppConfiguration.isJetpack,
let exPlat = ExPlat.shared
else {
return
}

let experimentNames = ABTest.allCases.filter { $0 != .unknown }.map { $0.rawValue }
ExPlat.shared?.register(experiments: experimentNames)

ExPlat.shared?.refresh()
exPlat.register(experiments: experimentNames)
exPlat.refresh()
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import Foundation

extension WPAnalytics {

/// Checks if the Domain Purchasing Feature Flag and AB Experiment are enabled
private static var domainPurchasingEnabled: Bool {
FeatureFlag.siteCreationDomainPurchasing.enabled && ABTest.siteCreationDomainPurchasing.isTreatmentVariation
}

static func domainsProperties(for blog: Blog) -> [AnyHashable: Any] {
// For now we do not have the `siteCreation` route implemented so hardcoding `menu`
domainsProperties(usingCredit: blog.canRegisterDomainWithPaidPlan, origin: .menu)
Expand All @@ -11,7 +17,7 @@ extension WPAnalytics {
origin: DomainPurchaseWebViewViewOrigin?
) -> [AnyHashable: Any] {
var dict: [AnyHashable: Any] = ["using_credit": usingCredit.stringLiteral]
if FeatureFlag.siteCreationDomainPurchasing.enabled,
if Self.domainPurchasingEnabled,
let origin = origin {
dict["origin"] = origin.rawValue
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ - (instancetype)init
_contextManager = [TracksContextManager new];
_tracksService = [[TracksService alloc] initWithContextManager:_contextManager];
_tracksService.eventNamePrefix = AppConstants.eventNamePrefix;
_tracksService.platform = AppConstants.explatPlatform;
}
return self;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import WordPressAuthenticator
static let shareAppName: ShareAppName = .wordpress
static let mobileAnnounceAppId = "2"
@objc static let eventNamePrefix = "wpios"
@objc static let explatPlatform = "wpios"
@objc static let authKeychainServiceName = "public-api.wordpress.com"

/// Notifications Constants
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ extension BlogListViewController {
return
}
self.present(wizard, animated: true)
WPAnalytics.track(.enhancedSiteCreationAccessed, withProperties: ["source": source])
SiteCreationAnalyticsHelper.trackSiteCreationAccessed(source: source)
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ class MySiteViewController: UIViewController, NoResultsViewHost {
return
}
self.present(wizard, animated: true)
WPAnalytics.track(.enhancedSiteCreationAccessed, withProperties: ["source": source])
SiteCreationAnalyticsHelper.trackSiteCreationAccessed(source: source)
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ extension WordPressAuthenticationManager: WordPressAuthenticatorDelegate {
}

navigationController.present(wizard, animated: true)
WPAnalytics.track(.enhancedSiteCreationAccessed, withProperties: ["source": source])
SiteCreationAnalyticsHelper.trackSiteCreationAccessed(source: source)
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ final class SiteAssemblyContentView: UIView {
label.font = WPStyleGuide.fontForTextStyle(.title1, fontWeight: .bold)
label.textColor = .text

if FeatureFlag.siteCreationDomainPurchasing.enabled {
if siteCreator.domainPurchasingEnabled {
label.textAlignment = .natural
} else {
label.textAlignment = .center
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Foundation

enum SiteCreationAnalyticsEvent: String {
case domainPurchasingExperiment = "site_creation_domain_purchasing_experiment"
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ extension Variation {
switch self {
case .treatment:
return "treatment"
case .customTreatment:
return "custom_treatment"
case .control:
return "control"
}
Expand All @@ -23,6 +25,25 @@ class SiteCreationAnalyticsHelper {
private static let variationKey = "variation"
private static let siteNameKey = "site_name"
private static let recommendedKey = "recommended"
private static let customTreatmentNameKey = "custom_treatment_variation_name"

// MARK: - Lifecycle
static func trackSiteCreationAccessed(source: String) {
WPAnalytics.track(.enhancedSiteCreationAccessed, withProperties: ["source": source])

if FeatureFlag.siteCreationDomainPurchasing.enabled {
let domainPurchasingExperimentProperties: [String: String] = {
var dict: [String: String] = [Self.variationKey: ABTest.siteCreationDomainPurchasing.variation.tracksProperty]

if case let .customTreatment(name) = ABTest.siteCreationDomainPurchasing.variation {
dict[Self.customTreatmentNameKey] = name
}

return dict
}()
Self.track(.domainPurchasingExperiment, properties: domainPurchasingExperimentProperties)
}
}

// MARK: - Site Intent
static func trackSiteIntentViewed() {
Expand Down Expand Up @@ -135,6 +156,11 @@ class SiteCreationAnalyticsHelper {
}

// MARK: - Common
private static func track(_ event: SiteCreationAnalyticsEvent, properties: [String: String] = [:]) {
let event = AnalyticsEvent(name: event.rawValue, properties: properties)
WPAnalytics.track(event)
}

private static func commonProperties(_ properties: Any?...) -> [AnyHashable: Any] {
var result: [AnyHashable: Any] = [:]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ final class AddressTableViewCell: UITableViewCell {

// MARK: - Dependencies

private let domainPurchasingEnabled = FeatureFlag.siteCreationDomainPurchasing.enabled
private var domainPurchasingEnabled: Bool {
FeatureFlag.siteCreationDomainPurchasing.enabled && ABTest.siteCreationDomainPurchasing.isTreatmentVariation
}

// MARK: - Views

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ final class WebAddressWizardContent: CollapsableHeaderViewController {
return .hidden
}

/// Checks if the Domain Purchasing Feature Flag is enabled
private let domainPurchasingEnabled = FeatureFlag.siteCreationDomainPurchasing.enabled
/// Checks if the Domain Purchasing Feature Flag and AB Experiment are enabled
private var domainPurchasingEnabled: Bool {
return siteCreator.domainPurchasingEnabled
}

/// The creator collects user input as they advance through the wizard flow.
private let siteCreator: SiteCreator
Expand Down Expand Up @@ -146,7 +148,7 @@ final class WebAddressWizardContent: CollapsableHeaderViewController {
}

private func configureUIIfNeeded() {
guard FeatureFlag.siteCreationDomainPurchasing.enabled else {
guard domainPurchasingEnabled else {
return
}

Expand All @@ -160,7 +162,7 @@ final class WebAddressWizardContent: CollapsableHeaderViewController {

private func loadHeaderView() {

if FeatureFlag.siteCreationDomainPurchasing.enabled {
if domainPurchasingEnabled {
searchBar.searchBarStyle = UISearchBar.Style.default
searchBar.translatesAutoresizingMaskIntoConstraints = false
WPStyleGuide.configureSearchBar(searchBar, backgroundColor: .clear, returnKeyType: .search)
Expand Down Expand Up @@ -215,9 +217,9 @@ final class WebAddressWizardContent: CollapsableHeaderViewController {
updateNoResultsLabelTopInset()

coordinator.animate(alongsideTransition: nil) { [weak self] (_) in
guard let `self` = self else { return }
guard let self else { return }

if FeatureFlag.siteCreationDomainPurchasing.enabled {
if self.domainPurchasingEnabled {
if !self.siteTemplateHostingController.view.isHidden {
self.updateTitleViewVisibility(true)
}
Expand Down Expand Up @@ -332,7 +334,7 @@ final class WebAddressWizardContent: CollapsableHeaderViewController {
}

private func restoreSearchIfNeeded() {
if FeatureFlag.siteCreationDomainPurchasing.enabled {
if domainPurchasingEnabled {
search(searchBar.text)
} else {
search(query(from: searchTextField))
Expand Down Expand Up @@ -422,7 +424,7 @@ final class WebAddressWizardContent: CollapsableHeaderViewController {
"search_term": lastSearchQuery as AnyObject
]

if FeatureFlag.siteCreationDomainPurchasing.enabled {
if domainPurchasingEnabled {
domainSuggestionProperties["domain_cost"] = domainSuggestion.costString
}

Expand All @@ -447,15 +449,15 @@ final class WebAddressWizardContent: CollapsableHeaderViewController {
// MARK: - Search logic

private func setAddressHintVisibility(isHidden: Bool) {
if FeatureFlag.siteCreationDomainPurchasing.enabled {
if domainPurchasingEnabled {
siteTemplateHostingController.view?.isHidden = isHidden
} else {
sitePromptView.isHidden = isHidden
}
}

private func addAddressHintView() {
if FeatureFlag.siteCreationDomainPurchasing.enabled {
if domainPurchasingEnabled {
guard let siteCreationView = siteTemplateHostingController.view else {
return
}
Expand Down Expand Up @@ -661,7 +663,7 @@ extension WebAddressWizardContent: UITableViewDelegate {
let domainSuggestion = data[indexPath.row]
self.selectedDomain = domainSuggestion

if FeatureFlag.siteCreationDomainPurchasing.enabled {
if domainPurchasingEnabled {
searchBar.resignFirstResponder()
} else {
searchTextField.resignFirstResponder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,14 @@ final class SiteCreator {
information?.title != nil
}

/// Checks if the Domain Purchasing Feature Flag and AB Experiment are enabled
var domainPurchasingEnabled: Bool {
FeatureFlag.siteCreationDomainPurchasing.enabled && ABTest.siteCreationDomainPurchasing.isTreatmentVariation
}

/// Flag indicating whether the domain checkout flow should appear or not.
var shouldShowDomainCheckout: Bool {
return FeatureFlag.siteCreationDomainPurchasing.enabled && !(address?.isFree ?? false)
domainPurchasingEnabled && !(address?.isFree ?? false)
}

/// Returns the domain suggestion if there's one,
Expand Down
Loading