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

[EP-157] Fix Properties (Phase One) #1371

Merged
merged 3 commits into from
Feb 11, 2021
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
11 changes: 0 additions & 11 deletions Kickstarter-iOS/ViewModels/AppDelegateViewModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2431,17 +2431,6 @@ final class AppDelegateViewModelTests: TestCase {
}
}

private func qualtricsProps() -> [String: String] {
return [
"bundle_id": AppEnvironment.current.mainBundle.bundleIdentifier,
"language": AppEnvironment.current.language.rawValue,
"logged_in": "true",
"distinct_id": AppEnvironment.current.device.identifierForVendor?.uuidString,
"user_uid": AppEnvironment.current.currentUser.flatMap { $0.id }.map(String.init)
]
.compact()
}

private let backingForCreatorPushData: [String: Any] = [
"aps": [
"alert": "HEYYYY"
Expand Down
2 changes: 1 addition & 1 deletion Kickstarter-iOS/Views/Cells/DiscoveryPostcardCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ internal final class DiscoveryPostcardCell: UITableViewCell, ValueCell {

self.watchProjectViewModel.inputs.configure(with: (
value.project,
KSRAnalytics.LocationContext.discovery,
KSRAnalytics.PageContext.discovery,
value.params
))
}
Expand Down
2 changes: 1 addition & 1 deletion Kickstarter-iOS/Views/Cells/DiscoveryProjectCardCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ final class DiscoveryProjectCardCell: UITableViewCell, ValueCell {

self.watchProjectViewModel.inputs.configure(with: (
value.project,
KSRAnalytics.LocationContext.discovery,
KSRAnalytics.PageContext.discovery,
value.params
))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public final class ProjectNavBarViewController: UIViewController {
self.viewModel.inputs.configureWith(project: project, refTag: refTag)
self.shareViewModel.inputs.configureWith(shareContext: .project(project), shareContextView: nil)
self.watchProjectViewModel.inputs
.configure(with: (project, KSRAnalytics.LocationContext.projectPage, nil))
.configure(with: (project, KSRAnalytics.PageContext.projectPage, nil))
}

internal func setDidScrollToTop(_ didScrollToTop: Bool) {
Expand Down
8 changes: 4 additions & 4 deletions KsApi/models/Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ public struct Project {
}

/// Pledged amount converted to USD.
public var pledgedUsd: Int {
return Int(floor(Float(self.pledged) * self.staticUsdRate))
public var pledgedUsd: Float {
return floor(Float(self.pledged) * self.staticUsdRate)
}

/// Goal amount converted to USD.
public var goalUsd: Int {
return Int(floor(Float(self.goal) * self.staticUsdRate))
public var goalUsd: Float {
return floor(Float(self.goal) * self.staticUsdRate)
}

/// Goal amount converted to current currency.
Expand Down
14 changes: 2 additions & 12 deletions Library/OptimizelyClientType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,6 @@ public func optimizelyProperties(environment: Environment? = AppEnvironment.curr
}

let environmentType = env.environmentType
let userId = deviceIdentifier(uuid: UUID())
let attributes = optimizelyUserAttributes()

var sdkKey: String

Expand All @@ -115,16 +113,8 @@ public func optimizelyProperties(environment: Environment? = AppEnvironment.curr
}

let allExperiments = optimizelyClient.allExperiments().map { experimentKey -> [String: String] in
let variation = try? optimizelyClient.getVariationKey(
Copy link
Contributor

Choose a reason for hiding this comment

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

Question: Why did this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A couple of relevant pieces of context:

  • in phase 8 we are essentially deprecating the entirety of optimizelyProperties
  • insights wants the format to be session_variants_optimizely : [experimentKey1: variation, experimentKey2: variation ...]

I decided to delete some of these properties here because after making the change to the format of session_variants_optimizely i realized those other values were not being used for anything.

experimentKey: experimentKey,
userId: userId,
attributes: attributes
)

return [
"optimizely_experiment_slug": experimentKey,
"optimizely_variant_id": variation ?? "unknown"
]
let variation = optimizelyClient.getVariation(for: experimentKey)
return [experimentKey: variation.rawValue]
}

return [
Expand Down
12 changes: 4 additions & 8 deletions Library/OptimizelyClientTypeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -135,20 +135,16 @@ final class OptimizelyClientTypeTests: TestCase {
XCTAssertEqual(Secrets.OptimizelySDKKey.staging, properties?["optimizely_api_key"] as? String)
XCTAssertEqual([
[
"optimizely_experiment_slug": "fake_experiment_1",
"optimizely_variant_id": "control"
"fake_experiment_1": "control"
],
[
"optimizely_experiment_slug": "fake_experiment_2",
"optimizely_variant_id": "variant-1"
"fake_experiment_2": "variant-1"
],
[
"optimizely_experiment_slug": "fake_experiment_3",
"optimizely_variant_id": "variant-2"
"fake_experiment_3": "variant-2"
],
[
"optimizely_experiment_slug": "fake_experiment_4",
"optimizely_variant_id": "unknown" // Not found in experiments
"fake_experiment_4": "control" // Not found in experiments
]
], optimizelyExperiments)

Expand Down
58 changes: 29 additions & 29 deletions Library/Tracking/KSRAnalytics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,28 +67,28 @@ public final class KSRAnalytics {
}

/// Determines the screen from which the event is sent.
public enum LocationContext: String {
case activities = "activity_feed_screen" // ActivitiesViewController
case addOnsSelection = "add_ons_selection" // RewardAddOnSelectionViewController
case campaign = "campaign_screen" // ProjectDescriptionViewController
case discovery = "explore_screen" // DiscoveryViewController
case editorialProjects = "editorial_collection_screen" // EditorialProjectsViewController
public enum PageContext: String {
case activities = "activity_feed" // ActivitiesViewController
case addOnsSelection = "add_ons" // RewardAddOnSelectionViewController
case campaign // ProjectDescriptionViewController
case discovery = "discover" // DiscoveryViewController
case editorialProjects = "editorial_collection" // EditorialProjectsViewController
case emailVerification = "email_verification" // EmailVerificationViewController
case forgotPassword = "forgot_password_screen" // ResetPasswordViewController
case forgotPassword = "forgot_password" // ResetPasswordViewController
case landingPage = "landing_page" // LandingViewController
case login = "login_screen" // LoginViewController
case loginTout = "login_or_signup_screen" // LoginToutViewController
case managePledgeScreen = "manage_pledge_screen" // ManagePledgeViewController
case login = "log_in" // LoginViewController
case loginTout = "log_in_sign_up" // LoginToutViewController
case managePledgeScreen = "manage_pledge" // ManagePledgeViewController
case onboarding // CategorySelectionViewController, CuratedProjectsViewController
case pledgeAddNewCard = "pledge_add_new_card_screen" // AddNewCardViewController
case pledgeScreen = "pledge_screen" // PledgeViewController
case projectPage = "project_screen" // ProjectPamphletViewController
case rewards = "rewards_screen" // RewardsViewController
case search = "search_screen" // SearchViewController
case settingsAddNewCard = "settings_add_new_card_screen" // AddNewCardViewController
case pledgeAddNewCard = "pledge_add_new_card" // AddNewCardViewController
case pledgeScreen = "pledge" // PledgeViewController
case projectPage = "project" // ProjectPamphletViewController
case rewards // RewardsViewController
case search // SearchViewController
case settingsAddNewCard = "settings_add_new_card" // AddNewCardViewController
case signup = "sign_up" // SignupViewController
case thanks = "thanks_screen" // ThanksViewController
case twoFactorAuth = "two_factor_auth_verify_screen" // TwoFactorViewController
case thanks // ThanksViewController
case twoFactorAuth = "two_factor_auth" // TwoFactorViewController
}

/// Determines the authentication type for login or signup events.
Expand Down Expand Up @@ -352,7 +352,7 @@ public final class KSRAnalytics {
let checkoutId: Int?
let estimatedDelivery: TimeInterval?
let paymentType: String?
let revenueInUsdCents: Int
let revenueInUsd: Double
let rewardId: Int
let rewardMinimumUsd: String
let rewardTitle: String?
Expand Down Expand Up @@ -572,7 +572,7 @@ public final class KSRAnalytics {

public func trackProjectCardClicked(project: Project,
params: DiscoveryParams,
location: LocationContext,
location: PageContext,
optimizelyProperties: [String: Any] = [:]) {
let props = discoveryProperties(from: params)
.withAllValuesFrom(projectProperties(from: project, loggedInUser: self.loggedInUser))
Expand Down Expand Up @@ -786,7 +786,7 @@ public final class KSRAnalytics {

public func trackAddNewCardButtonClicked(
context: KSRAnalytics.PledgeContext,
location: KSRAnalytics.LocationContext? = nil,
location: KSRAnalytics.PageContext? = nil,
project: Project,
refTag: RefTag?,
reward: Reward
Expand Down Expand Up @@ -1089,7 +1089,7 @@ public final class KSRAnalytics {

public func trackWatchProjectButtonClicked(
project: Project,
location: LocationContext,
location: PageContext,
params: DiscoveryParams? = nil
) {
var props = projectProperties(from: project, loggedInUser: self.loggedInUser)
Expand All @@ -1107,7 +1107,7 @@ public final class KSRAnalytics {

public func trackCampaignDetailsButtonClicked(
project: Project,
location: LocationContext,
location: PageContext,
refTag: RefTag?,
cookieRefTag: RefTag? = nil,
optimizelyProperties: [String: Any] = [:]
Expand All @@ -1125,7 +1125,7 @@ public final class KSRAnalytics {
}

public func trackCampaignDetailsPledgeButtonClicked(project: Project,
location: LocationContext,
location: PageContext,
refTag: RefTag?,
cookieRefTag: RefTag? = nil,
optimizelyProperties: [String: Any] = [:]) {
Expand Down Expand Up @@ -1162,14 +1162,14 @@ public final class KSRAnalytics {
// Private tracking method that merges in default properties.
private func track(
event: String,
location: KSRAnalytics.LocationContext? = nil,
location: KSRAnalytics.PageContext? = nil,
properties: [String: Any] = [:],
refTag: String? = nil,
referrerCredit: String? = nil
) {
let props = self.sessionProperties(refTag: refTag, referrerCredit: referrerCredit)
.withAllValuesFrom(userProperties(for: self.loggedInUser, config: self.config))
.withAllValuesFrom(contextProperties(location: location))
.withAllValuesFrom(contextProperties(page: location))
.withAllValuesFrom(properties)

self.logEventCallback?(event, props)
Expand Down Expand Up @@ -1376,7 +1376,7 @@ private func checkoutProperties(from data: KSRAnalytics.CheckoutPropertiesData,
var result: [String: Any] = [:]

result["amount"] = data.amount
result["amount_total_usd"] = data.revenueInUsdCents
result["amount_total_usd"] = data.revenueInUsd
result["add_ons_count_total"] = data.addOnsCountTotal
result["add_ons_count_unique"] = data.addOnsCountUnique
result["add_ons_minimum_usd"] = data.addOnsMinimumUsd
Expand Down Expand Up @@ -1442,12 +1442,12 @@ private func properties(category: KsApi.Category, prefix: String = "category_")
private func contextProperties(
pledgeFlowContext: KSRAnalytics.PledgeContext? = nil,
tabBarLabel: KSRAnalytics.TabBarItemLabel? = nil,
location: KSRAnalytics.LocationContext? = nil,
page: KSRAnalytics.PageContext? = nil,
prefix: String = "context_"
) -> [String: Any] {
var result: [String: Any] = [:]

result["location"] = location?.rawValue
result["page"] = page?.rawValue
result["pledge_flow"] = pledgeFlowContext?.trackingString
result["timestamp"] = AppEnvironment.current.dateType.init().timeIntervalSince1970
result["tab_bar_label"] = tabBarLabel?.trackingString
Expand Down
Loading