Skip to content

Commit

Permalink
♻️ Support a more flexible group name
Browse files Browse the repository at this point in the history
  • Loading branch information
iujames committed Oct 21, 2022
1 parent b4190fb commit 6478b04
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 16 deletions.
10 changes: 1 addition & 9 deletions Sources/AppcuesKit/Data/Models/Experiment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,5 @@
import Foundation

internal struct Experiment: Decodable {

enum ExperimentGroup: String, Decodable {
case control
case exposed
}

// making this optional so an unknown experiment group does not fail
// the entire qualify response deserialization
let group: ExperimentGroup?
let group: String
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,18 @@ internal class ExperienceRenderer: ExperienceRendering {
}

// check if this experience is part of an active experiment
if let experiment = experiment, let experimentID = experience.experimentID, let group = experiment.group {
if let experimentID = experience.experimentID, let group = experiment?.group {
// always send analytics for experiment_entered, with the group
analyticsPublisher.publish(TrackingUpdate(
type: .event(name: "appcues:experiment_entered", interactive: false),
properties: [
"experimentId": experimentID,
"group": group.rawValue
"group": group
],
isInternal: true))

// if this user is in the control group, it should not show
if group == .control {
if group == "control" {
completion?(.failure(ExperienceRendererError.experimentControl))
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ class ExperienceRendererTests: XCTestCase {
let presentExpectation = expectation(description: "Experience presented")
presentExpectation.isInverted = true
let experimentID = "6ce90d1d-4de2-41a6-bc93-07ae23b728c5"
let experiment = Experiment(group: .control)
let experiment = Experiment(group: "control")
let experience = ExperienceData.mockWithExperiment(experimentID: experimentID)
let preconditionPackage: ExperiencePackage = experience.package(presentExpectation: presentExpectation)
appcues.traitComposer.onPackage = { _, _ in preconditionPackage }
Expand All @@ -336,7 +336,7 @@ class ExperienceRendererTests: XCTestCase {
let completionExpectation = expectation(description: "Completion called")
let presentExpectation = expectation(description: "Experience presented")
let experimentID = "6ce90d1d-4de2-41a6-bc93-07ae23b728c5"
let experiment = Experiment(group: .exposed)
let experiment = Experiment(group: "exposed")
let experience = ExperienceData.mockWithExperiment(experimentID: experimentID)
let preconditionPackage: ExperiencePackage = experience.package(presentExpectation: presentExpectation)
appcues.traitComposer.onPackage = { _, _ in preconditionPackage }
Expand All @@ -356,7 +356,7 @@ class ExperienceRendererTests: XCTestCase {
// Arrange
let analyticsExpectation = expectation(description: "Triggered experiment_entered analytics")
let experimentID = "6ce90d1d-4de2-41a6-bc93-07ae23b728c5"
let experiment = Experiment(group: .control)
let experiment = Experiment(group: "control")
let experience = ExperienceData.mockWithExperiment(experimentID: experimentID)
let properties: [String: Any] = [
"experimentId": experimentID,
Expand Down Expand Up @@ -384,7 +384,7 @@ class ExperienceRendererTests: XCTestCase {
// Arrange
let analyticsExpectation = expectation(description: "Triggered experiment_entered analytics")
let experimentID = "6ce90d1d-4de2-41a6-bc93-07ae23b728c5"
let experiment = Experiment(group: .exposed)
let experiment = Experiment(group: "exposed")
let experience = ExperienceData.mockWithExperiment(experimentID: experimentID)
let properties: [String: Any] = [
"experimentId": experimentID,
Expand Down

0 comments on commit 6478b04

Please sign in to comment.