Skip to content

Commit

Permalink
♻️ Update experience analytics properties
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaatttt committed May 16, 2022
1 parent 5979db1 commit 03ee409
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
14 changes: 7 additions & 7 deletions Sources/AppcuesKit/Data/Models/Experience.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Foundation

internal protocol StepModel {
var id: UUID { get }
var type: String { get }
var traits: [Experience.Trait] { get }
var actions: [String: [Experience.Action]] { get }
}
Expand Down Expand Up @@ -51,6 +52,9 @@ internal struct Experience {

let id: UUID
let name: String
let type: String
// a millisecond timestamp
let publishedAt: Int?
// tags, theme, actions
// TODO: Handle experience-level actions
let traits: [Trait]
Expand All @@ -62,31 +66,27 @@ internal struct Experience {

extension Experience: Decodable {
private enum CodingKeys: CodingKey {
case id, name, traits, steps
case id, name, type, publishedAt, traits, steps
}
}

extension Experience.Step: Decodable {
struct Group: StepModel, Decodable {
let id: UUID
let type: String
let children: [Child]
let traits: [Experience.Trait]
let actions: [String: [Experience.Action]]
}

struct Child: StepModel, Decodable {
let id: UUID
let type: String
let content: ExperienceComponent
let traits: [Experience.Trait]
let actions: [String: [Experience.Action]]
}

private enum CodingKeys: CodingKey {
case steps
case contentType
case content
}

init(from decoder: Decoder) throws {
let modelContainer = try decoder.singleValueContainer()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,20 @@ internal enum LifecycleEvent: String, CaseIterable {
static func properties(_ experience: Experience, _ stepIndex: Experience.StepIndex? = nil, error: ErrorBody? = nil) -> [String: Any] {
var properties: [String: Any] = [
"experienceId": experience.id.uuidString.lowercased(),
"experienceName": experience.name
// TODO: The experience object does not current include version
// "version": experience.version
"experienceName": experience.name,
"experienceType": experience.type
// TODO: Add locale values to analytics for localized experiences
// "localeName": "",
// "localeId": ""
]

if let version = experience.publishedAt {
properties["version"] = version
}

if let stepIndex = stepIndex, let step = experience.step(at: stepIndex) {
properties["stepId"] = step.id.uuidString.lowercased()
properties["stepType"] = step.type
// stepIndex is added primarily for use by the debugger
properties["stepIndex"] = stepIndex.description
}
Expand Down

0 comments on commit 03ee409

Please sign in to comment.