From 7fe77b0ce7f95db15c9cb9be9c57f81a75d39bdb Mon Sep 17 00:00:00 2001 From: Christina Date: Fri, 2 Oct 2020 15:57:54 -0700 Subject: [PATCH 01/10] Update Remote Command for JSON --- Cartfile | 2 +- Cartfile.resolved | 5 +- Sources/ContentsquareConstants.swift | 29 +- Sources/ContentsquareRemoteCommand.swift | 72 +-- Sources/ContentsquareTrackable.swift | 427 ++++++++++++++++- Sources/ContentsquareTracker.swift | 438 ------------------ TealiumContentsquare.podspec | 9 +- .../project.pbxproj | 57 +-- TealiumContentsquareExample/Podfile | 5 +- TealiumContentsquareExample/Podfile.lock | 43 +- .../project.pbxproj | 4 + .../TealiumHelper.swift | 57 ++- .../Views/TransactionView.swift | 12 +- .../contentsquare.json | 21 + Tests/ContentsquareTrackerTests.swift | 24 +- 15 files changed, 596 insertions(+), 609 deletions(-) delete mode 100644 Sources/ContentsquareTracker.swift create mode 100644 TealiumContentsquareExample/TealiumContentsquareExample/contentsquare.json diff --git a/Cartfile b/Cartfile index 6d021dd..ca70819 100644 --- a/Cartfile +++ b/Cartfile @@ -1,2 +1,2 @@ -github "tealium/tealium-swift" +github "tealium/tealium-swift", "~> 2.1" github "ContentSquare/CS_iOS_SDK" diff --git a/Cartfile.resolved b/Cartfile.resolved index 4e25e4d..a292ba2 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1,3 +1,2 @@ -binary "https://tags.tiqcdn.com/dle/tealiummobile/tealium-ios-carthage/tealium-carthage-plcrashreporter.json" "1.3.6" -github "ContentSquare/CS_iOS_SDK" "v3.0.0" -github "tealium/tealium-swift" "1.9.1" +git "file:///Users/christina/Projects/work-repos/github/tealium-swift-builder" "388d0ac6726fd110a03c48ad14cdfa8ae87706e1" +github "ContentSquare/CS_iOS_SDK" "v3.2.1" diff --git a/Sources/ContentsquareConstants.swift b/Sources/ContentsquareConstants.swift index 9bee84f..9fa2eec 100644 --- a/Sources/ContentsquareConstants.swift +++ b/Sources/ContentsquareConstants.swift @@ -3,25 +3,26 @@ // TealiumContentsquare // // Created by Jonathan Wong on 3/4/20. -// Copyright © 2020 Jonathan Wong. All rights reserved. +// Copyright © 2020 Tealium. All rights reserved. // extension ContentsquareRemoteCommand { enum Contentsquare { - enum Commands { - static let commandKey = "command_name" - static let separator: Character = "," - - static let sendScreenView = "sendscreenview" - static let sendTransaction = "sendtransaction" - static let sendDynamicVar = "senddynamicvar" - static let stopTracking = "stoptracking" - static let resumeTracking = "resumetracking" - static let forgetMe = "forgetme" - static let optIn = "optin" - static let optOut = "optout" - + static let commandId = "contentsquare" + static let description = "Contentsquare Remote Command" + static let commandKey = "command_name" + static let separator: Character = "," + + enum Commands: String { + case sendScreenView = "sendscreenview" + case sendTransaction = "sendtransaction" + case sendDynamicVar = "senddynamicvar" + case stopTracking = "stoptracking" + case resumeTracking = "resumetracking" + case forgetMe = "forgetme" + case optIn = "optin" + case optOut = "optout" } enum ScreenView { diff --git a/Sources/ContentsquareRemoteCommand.swift b/Sources/ContentsquareRemoteCommand.swift index 483ef81..129c4db 100644 --- a/Sources/ContentsquareRemoteCommand.swift +++ b/Sources/ContentsquareRemoteCommand.swift @@ -3,7 +3,7 @@ // TealiumContentsquare // // Created by Jonathan Wong on 3/6/20. -// Copyright © 2020 Jonathan Wong. All rights reserved. +// Copyright © 2020 Tealium. All rights reserved. // import Foundation @@ -15,42 +15,42 @@ import TealiumTagManagement import TealiumRemoteCommands #endif -public class ContentsquareRemoteCommand { +public class ContentsquareRemoteCommand: RemoteCommand { - let contentsquareTracker: - ContentsquareTrackable + var contentsquareTracker: ContentsquareTrackable? - public init(contentsquareTracker: - ContentsquareTrackable) { - self.contentsquareTracker = - contentsquareTracker + public init(contentsquareTracker: ContentsquareTrackable = ContentsquareTracker(), type: RemoteCommandType = .webview) { + self.contentsquareTracker = contentsquareTracker + weak var selfWorkaround: ContentsquareRemoteCommand? + super.init(commandId: Contentsquare.commandId, + description: Contentsquare.description, + type: type, + completion: { response in + guard let payload = response.payload else { + return + } + selfWorkaround?.processRemoteCommand(with: payload) + }) + selfWorkaround = self } - public func remoteCommand() -> TealiumRemoteCommand { - return TealiumRemoteCommand(commandId: "contentsquare", - description: "Contentsquare Remote Command") { response in - let payload = response.payload() - guard let command = payload[Contentsquare.Commands.commandKey] as? String else { - return - } - - let commands = command.split(separator: Contentsquare.Commands.separator) - let formatted = commands.map { command in - return command.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines) - } - - self.parseCommands(formatted, payload: payload) + func processRemoteCommand(with payload: [String: Any]) { + guard let contentsquareTracker = contentsquareTracker, + let command = payload[Contentsquare.commandKey] as? String else { + return } - } - - func parseCommands(_ commands: [String], payload: [String: Any]) { - commands.forEach { command in - let lowercasedCommand = command.lowercased() - switch lowercasedCommand { - case Contentsquare.Commands.sendScreenView: + let commands = command.split(separator: Contentsquare.separator) + let contentsquareCommands = commands.map { command in + return command.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines) + } + + contentsquareCommands.forEach { + let command = Contentsquare.Commands(rawValue: $0.lowercased()) + switch command { + case .sendScreenView: guard let screenName = payload[Contentsquare.ScreenView.screenName] as? String else { return } contentsquareTracker.sendScreenView(screenName: screenName) - case Contentsquare.Commands.sendTransaction: + case .sendTransaction: guard let options = payload[Contentsquare.TransactionProperties.transaction] as? [String: Any] else { print("Contentsquare.TransactionProperties.transaction key is missing.") return @@ -59,18 +59,18 @@ public class ContentsquareRemoteCommand { let currency: String = options[Contentsquare.TransactionProperties.currency] as? String else { return } let transactionId: String? = options[Contentsquare.TransactionProperties.transactionId] as? String contentsquareTracker.sendTransaction(price: price, currency: currency, transactionId: transactionId) - case Contentsquare.Commands.sendDynamicVar: + case .sendDynamicVar: guard let dynamicVar = payload[Contentsquare.DynamicVar.dynamicVar] as? [String: Any] else { return } contentsquareTracker.sendDynamicVar(dynamicVar: dynamicVar) - case Contentsquare.Commands.stopTracking: + case .stopTracking: contentsquareTracker.stopTracking() - case Contentsquare.Commands.resumeTracking: + case .resumeTracking: contentsquareTracker.resumeTracking() - case Contentsquare.Commands.forgetMe: + case .forgetMe: contentsquareTracker.forgetMe() - case Contentsquare.Commands.optIn: + case .optIn: contentsquareTracker.optIn() - case Contentsquare.Commands.optOut: + case .optOut: contentsquareTracker.optOut() default: break } diff --git a/Sources/ContentsquareTrackable.swift b/Sources/ContentsquareTrackable.swift index 31c4f04..541ac75 100644 --- a/Sources/ContentsquareTrackable.swift +++ b/Sources/ContentsquareTrackable.swift @@ -1,24 +1,441 @@ // -// ContentsquareTrackable.swift +// ContentsquareTracker.swift // TealiumContentsquare // // Created by Jonathan Wong on 3/6/20. -// Copyright © 2020 Jonathan Wong. All rights reserved. +// Copyright © 2020 Tealium. All rights reserved. // import Foundation +import ContentsquareModule public protocol ContentsquareTrackable { func sendScreenView(screenName: String) - func sendTransaction(price: Double, currency: String, transactionId: String?) - func sendDynamicVar(dynamicVar: [String: Any]) - func stopTracking() func resumeTracking() func forgetMe() func optIn() func optOut() +} + +public class ContentsquareTracker: ContentsquareTrackable { + + public init() {} + + public func sendScreenView(screenName: String) { + Contentsquare.send(screenViewWithName: screenName) + } + + public func sendTransaction(price: Double, currency: String, transactionId: String?) { + guard let currency = CurrencyWrapper(rawValue: currency.lowercased())?.currency() else { + print("Error with currency value.") + return + } + let transaction = CustomerTransaction(id: transactionId, value: Float(price), currency: currency) + Contentsquare.send(transaction: transaction) + } + + public func sendDynamicVar(dynamicVar: [String: Any]) { + dynamicVar.forEach { key, value in + if let value = value as? String { + let dynamicVar = DynamicVar(key: key, value: value) + Contentsquare.send(dynamicVar: dynamicVar) + } else if let value = value as? UInt32 { + let dynamicVar = DynamicVar(key: key, value: value) + Contentsquare.send(dynamicVar: dynamicVar) + } else { + print("Incorrect format of value: \(value). Value should be String or UInt32.") + } + } + } + + public func stopTracking() { + Contentsquare.stopTracking() + } + + public func resumeTracking() { + Contentsquare.resumeTracking() + } + + public func forgetMe() { + Contentsquare.forgetMe() + } + + public func optIn() { + Contentsquare.optIn() + } + + public func optOut() { + Contentsquare.optOut() + } +} +/// Maps to Contentsquare's Currency type +public enum CurrencyWrapper: String, Codable { + case mop + case bmd + case kes + case bnd + case iqd + case sdg + case zmw + case xts + case top + case xsu + case svc + case ils + case dzd + case nad + case mxv + case sos + case cad + case sek + case hkd + case zwl + case egp + case clp + case cuc + case lyd + case rsd + case cou + case cve + case khr + case gyd + case mkd + case tmt + case ugx + case kgs + case ves + case ssp + case npr + case sbd + case xpf + case aud + case bhd + case mwk + case mxn + case nio + case lsl + case xxx + case zar + case aoa + case gmd + case gip + case mvr + case kwd + case pln + case mga + case uah + case huf + case rub + case vnd + case lak + case rwf + case syp + case xag + case mur + case wst + case xpd + case gbp + case etb + case isk + case cdf + case usd + case tjs + case cup + case bgn + case eur + case cny + case cop + case gnf + case bbd + case xua + case chw + case xcd + case lrd + case pen + case pkr + case pyg + case lkr + case ron + case uzs + case nzd + case idr + case ern + case czk + case jod + case awg + case irr + case tzs + case brl + case ngn + case che + case chf + case bdt + case thb + case xdr + case mad + case gel + case fkp + case azn + case pab + case twd + case aed + case htg + case xbd + case lbp + case amd + case php + case xpt + case inr + case bwp + case myr + case mnt + case srd + case sll + case uyu + case bam + case bif + case bov + case jmd + case omr + case uyw + case bzd + case nok + case kmf + case kpw + case scr + case jpy + case xof + case shp + case sgd + case dkk + case uyi + case yer + case ang + case ttd + case xbb + case xbc + case fjd + case dop + case byn + case kzt + case xba + case szl + case sar + case gtq + case pgk + case ars + case btn + case afn + case djf + case mdl + case ghs + case qar + case `try` + case mmk + case xaf + case vuv + case xau + case clf + case hrk + case bob + case krw + case bsd + case all + case mru + case hnl + case stn + case usn + case mzn + case tnd + case crc + case kyd + + func currency() -> Currency { + switch self { + case .mop: return .mop + case .bmd: return .bmd + case .kes: return .kes + case .bnd: return .bnd + case .iqd: return .iqd + case .sdg: return .sdg + case .zmw: return .zmw + case .xts: return .xts + case .top: return .top + case .xsu: return .xsu + case .svc: return .svc + case .ils: return .ils + case .dzd: return .dzd + case .nad: return .nad + case .mxv: return .mxv + case .sos: return .sos + case .cad: return .cad + case .sek: return .sek + case .hkd: return .hkd + case .zwl: return .zwl + case .egp: return .egp + case .clp: return .clp + case .cuc: return .cuc + case .lyd: return .lyd + case .rsd: return .rsd + case .cou: return .cou + case .cve: return .cve + case .khr: return .khr + case .gyd: return .gyd + case .mkd: return .mkd + case .tmt: return .tmt + case .ugx: return .ugx + case .kgs: return .kgs + case .ves: return .ves + case .ssp: return .ssp + case .npr: return .npr + case .sbd: return .sbd + case .xpf: return .xpf + case .aud: return .aud + case .bhd: return .bhd + case .mwk: return .mwk + case .mxn: return .mxn + case .nio: return .nio + case .lsl: return .lsl + case .xxx: return .xxx + case .zar: return .zar + case .aoa: return .aoa + case .gmd: return .gmd + case .gip: return .gip + case .mvr: return .mvr + case .kwd: return .kwd + case .pln: return .pln + case .mga: return .mga + case .uah: return .uah + case .huf: return .huf + case .rub: return .rub + case .vnd: return .vnd + case .lak: return .lak + case .rwf: return .rwf + case .syp: return .syp + case .xag: return .xag + case .mur: return .mur + case .wst: return .wst + case .xpd: return .xpd + case .gbp: return .gbp + case .etb: return .etb + case .isk: return .isk + case .cdf: return .cdf + case .usd: return .usd + case .tjs: return .tjs + case .cup: return .cup + case .bgn: return .bgn + case .eur: return .eur + case .cny: return .cny + case .cop: return .cop + case .gnf: return .gnf + case .bbd: return .bbd + case .xua: return .xua + case .chw: return .chw + case .xcd: return .xcd + case .lrd: return .lrd + case .pen: return .pen + case .pkr: return .pkr + case .pyg: return .pyg + case .lkr: return .lkr + case .ron: return .ron + case .uzs: return .uzs + case .nzd: return .nzd + case .idr: return .idr + case .ern: return .ern + case .czk: return .czk + case .jod: return .jod + case .awg: return .awg + case .irr: return .irr + case .tzs: return .tzs + case .brl: return .brl + case .ngn: return .ngn + case .che: return .che + case .chf: return .chf + case .bdt: return .bdt + case .thb: return .thb + case .xdr: return .xdr + case .mad: return .mad + case .gel: return .gel + case .fkp: return .fkp + case .azn: return .azn + case .pab: return .pab + case .twd: return .twd + case .aed: return .aed + case .htg: return .htg + case .xbd: return .xbd + case .lbp: return .lbp + case .amd: return .amd + case .php: return .php + case .xpt: return .xpt + case .inr: return .inr + case .bwp: return .bwp + case .myr: return .myr + case .mnt: return .mnt + case .srd: return .srd + case .sll: return .sll + case .uyu: return .uyu + case .bam: return .bam + case .bif: return .bif + case .bov: return .bov + case .jmd: return .jmd + case .omr: return .omr + case .uyw: return .uyw + case .bzd: return .bzd + case .nok: return .nok + case .kmf: return .kmf + case .kpw: return .kpw + case .scr: return .scr + case .jpy: return .jpy + case .xof: return .xof + case .shp: return .shp + case .sgd: return .sgd + case .dkk: return .dkk + case .uyi: return .uyi + case .yer: return .yer + case .ang: return .ang + case .ttd: return .ttd + case .xbb: return .xbb + case .xbc: return .xbc + case .fjd: return .fjd + case .dop: return .dop + case .byn: return .byn + case .kzt: return .kzt + case .xba: return .xba + case .szl: return .szl + case .sar: return .sar + case .gtq: return .gtq + case .pgk: return .pgk + case .ars: return .ars + case .btn: return .btn + case .afn: return .afn + case .djf: return .djf + case .mdl: return .mdl + case .ghs: return .ghs + case .qar: return .qar + case .`try`: return .`try` + case .mmk: return .mmk + case .xaf: return .xaf + case .vuv: return .vuv + case .xau: return .xau + case .clf: return .clf + case .hrk: return .hrk + case .bob: return .bob + case .krw: return .krw + case .bsd: return .bsd + case .all: return .all + case .mru: return .mru + case .hnl: return .hnl + case .stn: return .stn + case .usn: return .usn + case .mzn: return .mzn + case .tnd: return .tnd + case .crc: return .crc + case .kyd: return .kyd + } + + } } diff --git a/Sources/ContentsquareTracker.swift b/Sources/ContentsquareTracker.swift deleted file mode 100644 index b9c1612..0000000 --- a/Sources/ContentsquareTracker.swift +++ /dev/null @@ -1,438 +0,0 @@ -// -// ContentsquareTracker.swift -// TealiumContentsquare -// -// Created by Jonathan Wong on 3/6/20. -// Copyright © 2020 Jonathan Wong. All rights reserved. -// - -import Foundation -import ContentsquareModule - -public class ContentsquareTracker: ContentsquareTrackable { - - public init() {} - - public func sendScreenView(screenName: String) { - Contentsquare.send(screenViewWithName: screenName) - } - - public func sendTransaction(price: Double, currency: String, transactionId: String?) { - guard let currency = CurrencyWrapper(rawValue: currency.lowercased())?.currency() else { - print("Error with currency value.") - return - } - let transaction = CustomerTransaction(id: transactionId, value: Float(price), currency: currency) - Contentsquare.send(transaction: transaction) - } - - public func sendDynamicVar(dynamicVar: [String: Any]) { - dynamicVar.forEach { key, value in - if let value = value as? String { - do { - let dynamicVar = try DynamicVar(key: key, value: value) - Contentsquare.send(dynamicVar: dynamicVar) - } catch { - print("Error with dynamic variable key: \(key), value: \(value), error: \(error)") - } - } else if let value = value as? UInt32 { - do { - let dynamicVar = try DynamicVar(key: key, value: value) - Contentsquare.send(dynamicVar: dynamicVar) - } catch { - print("Error with dynamic variable key: \(key), value: \(value), error: \(error)") - } - } else { - print("Incorrect format of value: \(value). Value should be String or UInt32.") - } - } - } - - public func stopTracking() { - Contentsquare.stopTracking() - } - - public func resumeTracking() { - Contentsquare.resumeTracking() - } - - public func forgetMe() { - Contentsquare.forgetMe() - } - - public func optIn() { - Contentsquare.optIn() - } - - public func optOut() { - Contentsquare.optOut() - } -} - -/// Maps to Contentsquare's Currency type -public enum CurrencyWrapper: String, Codable { - case mop - case bmd - case kes - case bnd - case iqd - case sdg - case zmw - case xts - case top - case xsu - case svc - case ils - case dzd - case nad - case mxv - case sos - case cad - case sek - case hkd - case zwl - case egp - case clp - case cuc - case lyd - case rsd - case cou - case cve - case khr - case gyd - case mkd - case tmt - case ugx - case kgs - case ves - case ssp - case npr - case sbd - case xpf - case aud - case bhd - case mwk - case mxn - case nio - case lsl - case xxx - case zar - case aoa - case gmd - case gip - case mvr - case kwd - case pln - case mga - case uah - case huf - case rub - case vnd - case lak - case rwf - case syp - case xag - case mur - case wst - case xpd - case gbp - case etb - case isk - case cdf - case usd - case tjs - case cup - case bgn - case eur - case cny - case cop - case gnf - case bbd - case xua - case chw - case xcd - case lrd - case pen - case pkr - case pyg - case lkr - case ron - case uzs - case nzd - case idr - case ern - case czk - case jod - case awg - case irr - case tzs - case brl - case ngn - case che - case chf - case bdt - case thb - case xdr - case mad - case gel - case fkp - case azn - case pab - case twd - case aed - case htg - case xbd - case lbp - case amd - case php - case xpt - case inr - case bwp - case myr - case mnt - case srd - case sll - case uyu - case bam - case bif - case bov - case jmd - case omr - case uyw - case bzd - case nok - case kmf - case kpw - case scr - case jpy - case xof - case shp - case sgd - case dkk - case uyi - case yer - case ang - case ttd - case xbb - case xbc - case fjd - case dop - case byn - case kzt - case xba - case szl - case sar - case gtq - case pgk - case ars - case btn - case afn - case djf - case mdl - case ghs - case qar - case `try` - case mmk - case xaf - case vuv - case xau - case clf - case hrk - case bob - case krw - case bsd - case all - case mru - case hnl - case stn - case usn - case mzn - case tnd - case crc - case kyd - - func currency() -> Currency { - switch self { - case .mop: return .mop - case .bmd: return .bmd - case .kes: return .kes - case .bnd: return .bnd - case .iqd: return .iqd - case .sdg: return .sdg - case .zmw: return .zmw - case .xts: return .xts - case .top: return .top - case .xsu: return .xsu - case .svc: return .svc - case .ils: return .ils - case .dzd: return .dzd - case .nad: return .nad - case .mxv: return .mxv - case .sos: return .sos - case .cad: return .cad - case .sek: return .sek - case .hkd: return .hkd - case .zwl: return .zwl - case .egp: return .egp - case .clp: return .clp - case .cuc: return .cuc - case .lyd: return .lyd - case .rsd: return .rsd - case .cou: return .cou - case .cve: return .cve - case .khr: return .khr - case .gyd: return .gyd - case .mkd: return .mkd - case .tmt: return .tmt - case .ugx: return .ugx - case .kgs: return .kgs - case .ves: return .ves - case .ssp: return .ssp - case .npr: return .npr - case .sbd: return .sbd - case .xpf: return .xpf - case .aud: return .aud - case .bhd: return .bhd - case .mwk: return .mwk - case .mxn: return .mxn - case .nio: return .nio - case .lsl: return .lsl - case .xxx: return .xxx - case .zar: return .zar - case .aoa: return .aoa - case .gmd: return .gmd - case .gip: return .gip - case .mvr: return .mvr - case .kwd: return .kwd - case .pln: return .pln - case .mga: return .mga - case .uah: return .uah - case .huf: return .huf - case .rub: return .rub - case .vnd: return .vnd - case .lak: return .lak - case .rwf: return .rwf - case .syp: return .syp - case .xag: return .xag - case .mur: return .mur - case .wst: return .wst - case .xpd: return .xpd - case .gbp: return .gbp - case .etb: return .etb - case .isk: return .isk - case .cdf: return .cdf - case .usd: return .usd - case .tjs: return .tjs - case .cup: return .cup - case .bgn: return .bgn - case .eur: return .eur - case .cny: return .cny - case .cop: return .cop - case .gnf: return .gnf - case .bbd: return .bbd - case .xua: return .xua - case .chw: return .chw - case .xcd: return .xcd - case .lrd: return .lrd - case .pen: return .pen - case .pkr: return .pkr - case .pyg: return .pyg - case .lkr: return .lkr - case .ron: return .ron - case .uzs: return .uzs - case .nzd: return .nzd - case .idr: return .idr - case .ern: return .ern - case .czk: return .czk - case .jod: return .jod - case .awg: return .awg - case .irr: return .irr - case .tzs: return .tzs - case .brl: return .brl - case .ngn: return .ngn - case .che: return .che - case .chf: return .chf - case .bdt: return .bdt - case .thb: return .thb - case .xdr: return .xdr - case .mad: return .mad - case .gel: return .gel - case .fkp: return .fkp - case .azn: return .azn - case .pab: return .pab - case .twd: return .twd - case .aed: return .aed - case .htg: return .htg - case .xbd: return .xbd - case .lbp: return .lbp - case .amd: return .amd - case .php: return .php - case .xpt: return .xpt - case .inr: return .inr - case .bwp: return .bwp - case .myr: return .myr - case .mnt: return .mnt - case .srd: return .srd - case .sll: return .sll - case .uyu: return .uyu - case .bam: return .bam - case .bif: return .bif - case .bov: return .bov - case .jmd: return .jmd - case .omr: return .omr - case .uyw: return .uyw - case .bzd: return .bzd - case .nok: return .nok - case .kmf: return .kmf - case .kpw: return .kpw - case .scr: return .scr - case .jpy: return .jpy - case .xof: return .xof - case .shp: return .shp - case .sgd: return .sgd - case .dkk: return .dkk - case .uyi: return .uyi - case .yer: return .yer - case .ang: return .ang - case .ttd: return .ttd - case .xbb: return .xbb - case .xbc: return .xbc - case .fjd: return .fjd - case .dop: return .dop - case .byn: return .byn - case .kzt: return .kzt - case .xba: return .xba - case .szl: return .szl - case .sar: return .sar - case .gtq: return .gtq - case .pgk: return .pgk - case .ars: return .ars - case .btn: return .btn - case .afn: return .afn - case .djf: return .djf - case .mdl: return .mdl - case .ghs: return .ghs - case .qar: return .qar - case .`try`: return .`try` - case .mmk: return .mmk - case .xaf: return .xaf - case .vuv: return .vuv - case .xau: return .xau - case .clf: return .clf - case .hrk: return .hrk - case .bob: return .bob - case .krw: return .krw - case .bsd: return .bsd - case .all: return .all - case .mru: return .mru - case .hnl: return .hnl - case .stn: return .stn - case .usn: return .usn - case .mzn: return .mzn - case .tnd: return .tnd - case .crc: return .crc - case .kyd: return .kyd - } - - } -} diff --git a/TealiumContentsquare.podspec b/TealiumContentsquare.podspec index a65bc28..f95ff35 100644 --- a/TealiumContentsquare.podspec +++ b/TealiumContentsquare.podspec @@ -3,7 +3,7 @@ Pod::Spec.new do |s| # ――― Spec Metadata ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # s.name = "TealiumContentsquare" s.module_name = "TealiumContentsquare" - s.version = "1.0.0" + s.version = "2.0.0" s.summary = "Tealium Swift and Contentsquare integration" s.description = <<-DESC Tealium's integration with Contentsquare for iOS. @@ -31,10 +31,9 @@ Pod::Spec.new do |s| s.ios.source_files = "Sources/*.{swift}" # ――― Dependencies ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # - s.ios.dependency 'tealium-swift/Core' - s.ios.dependency 'tealium-swift/TealiumRemoteCommands' - s.ios.dependency 'tealium-swift/TealiumDelegate' - s.ios.dependency 'tealium-swift/TealiumTagManagement' + s.ios.dependency 'tealium-swift/Core', '~> 2.1' + s.ios.dependency 'tealium-swift/RemoteCommands', '~> 2.1' + s.ios.dependency 'tealium-swift/TagManagement', '~> 2.1' s.ios.dependency 'CS_iOS_SDK' end diff --git a/TealiumContentsquare.xcodeproj/project.pbxproj b/TealiumContentsquare.xcodeproj/project.pbxproj index 375e3ee..1bb2b2f 100644 --- a/TealiumContentsquare.xcodeproj/project.pbxproj +++ b/TealiumContentsquare.xcodeproj/project.pbxproj @@ -9,17 +9,19 @@ /* Begin PBXBuildFile section */ 4B4B6E73241B28920084E720 /* ContentsquareTrackerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B4B6E72241B28920084E720 /* ContentsquareTrackerTests.swift */; }; 4BE613FA2412F81F00C4B1EB /* ContentsquareRemoteCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BE613F92412F81F00C4B1EB /* ContentsquareRemoteCommand.swift */; }; - 4BE613FC2412F87E00C4B1EB /* ContentsquareTracker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BE613FB2412F87E00C4B1EB /* ContentsquareTracker.swift */; }; 4BE613FE2412F88A00C4B1EB /* ContentsquareTrackable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BE613FD2412F88A00C4B1EB /* ContentsquareTrackable.swift */; }; 4BE614022412FF7800C4B1EB /* TealiumTagManagement.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4BE614012412FF7700C4B1EB /* TealiumTagManagement.framework */; platformFilter = ios; }; 4BE614042412FF7B00C4B1EB /* TealiumRemoteCommands.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4BE614032412FF7B00C4B1EB /* TealiumRemoteCommands.framework */; platformFilter = ios; }; - 4BE614062412FF8300C4B1EB /* TealiumDelegate.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4BE614052412FF8300C4B1EB /* TealiumDelegate.framework */; platformFilter = ios; }; 4BE614082412FF8700C4B1EB /* TealiumCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4BE614072412FF8700C4B1EB /* TealiumCore.framework */; platformFilter = ios; }; 4BE6140A2413001100C4B1EB /* ContentsquareModule.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4BE614092413001100C4B1EB /* ContentsquareModule.framework */; platformFilter = ios; }; 4BEB130F241046820060D075 /* TealiumContentsquare.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4BEB1305241046820060D075 /* TealiumContentsquare.framework */; platformFilter = ios; }; 4BEB1314241046820060D075 /* MockContentsquareTracker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BEB1313241046820060D075 /* MockContentsquareTracker.swift */; }; 4BEB1316241046820060D075 /* TealiumContentsquare.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BEB1308241046820060D075 /* TealiumContentsquare.h */; settings = {ATTRIBUTES = (Public, ); }; }; 4BEB132024104EDF0060D075 /* ContentsquareConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BEB131F24104EDF0060D075 /* ContentsquareConstants.swift */; }; + CFEF6CE12527DCF900902EC6 /* TealiumRemoteCommands.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4BE614032412FF7B00C4B1EB /* TealiumRemoteCommands.framework */; }; + CFEF6CE62527DD4400902EC6 /* TealiumRemoteCommands.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 4BE614032412FF7B00C4B1EB /* TealiumRemoteCommands.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + CFEF6CE92527DD7900902EC6 /* TealiumCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4BE614072412FF8700C4B1EB /* TealiumCore.framework */; }; + CFEF6CEA2527DD7F00902EC6 /* TealiumCore.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 4BE614072412FF8700C4B1EB /* TealiumCore.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -32,10 +34,23 @@ }; /* End PBXContainerItemProxy section */ +/* Begin PBXCopyFilesBuildPhase section */ + CFEF6CE42527DD3500902EC6 /* CopyFiles */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = ""; + dstSubfolderSpec = 10; + files = ( + CFEF6CEA2527DD7F00902EC6 /* TealiumCore.framework in CopyFiles */, + CFEF6CE62527DD4400902EC6 /* TealiumRemoteCommands.framework in CopyFiles */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase section */ + /* Begin PBXFileReference section */ 4B4B6E72241B28920084E720 /* ContentsquareTrackerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentsquareTrackerTests.swift; sourceTree = ""; }; 4BE613F92412F81F00C4B1EB /* ContentsquareRemoteCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentsquareRemoteCommand.swift; sourceTree = ""; }; - 4BE613FB2412F87E00C4B1EB /* ContentsquareTracker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentsquareTracker.swift; sourceTree = ""; }; 4BE613FD2412F88A00C4B1EB /* ContentsquareTrackable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentsquareTrackable.swift; sourceTree = ""; }; 4BE614012412FF7700C4B1EB /* TealiumTagManagement.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = TealiumTagManagement.framework; path = Carthage/Build/iOS/TealiumTagManagement.framework; sourceTree = ""; }; 4BE614032412FF7B00C4B1EB /* TealiumRemoteCommands.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = TealiumRemoteCommands.framework; path = Carthage/Build/iOS/TealiumRemoteCommands.framework; sourceTree = ""; }; @@ -57,7 +72,6 @@ buildActionMask = 2147483647; files = ( 4BE614022412FF7800C4B1EB /* TealiumTagManagement.framework in Frameworks */, - 4BE614062412FF8300C4B1EB /* TealiumDelegate.framework in Frameworks */, 4BE614042412FF7B00C4B1EB /* TealiumRemoteCommands.framework in Frameworks */, 4BE614082412FF8700C4B1EB /* TealiumCore.framework in Frameworks */, 4BE6140A2413001100C4B1EB /* ContentsquareModule.framework in Frameworks */, @@ -68,6 +82,8 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + CFEF6CE92527DD7900902EC6 /* TealiumCore.framework in Frameworks */, + CFEF6CE12527DCF900902EC6 /* TealiumRemoteCommands.framework in Frameworks */, 4BEB130F241046820060D075 /* TealiumContentsquare.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; @@ -112,7 +128,6 @@ 4BEB131F24104EDF0060D075 /* ContentsquareConstants.swift */, 4BE613F92412F81F00C4B1EB /* ContentsquareRemoteCommand.swift */, 4BE613FD2412F88A00C4B1EB /* ContentsquareTrackable.swift */, - 4BE613FB2412F87E00C4B1EB /* ContentsquareTracker.swift */, 4BEB1308241046820060D075 /* TealiumContentsquare.h */, 4BEB1309241046820060D075 /* Info.plist */, ); @@ -169,7 +184,7 @@ 4BEB130A241046820060D075 /* Sources */, 4BEB130B241046820060D075 /* Frameworks */, 4BEB130C241046820060D075 /* Resources */, - 4B4B6E71241B26C50084E720 /* Carthage */, + CFEF6CE42527DD3500902EC6 /* CopyFiles */, ); buildRules = ( ); @@ -237,26 +252,6 @@ /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ - 4B4B6E71241B26C50084E720 /* Carthage */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputFileListPaths = ( - ); - inputPaths = ( - TealiumCore.framework, - TealiumRemoteCommands.framework, - ); - name = Carthage; - outputFileListPaths = ( - ); - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "#exec \"${SRCROOT}/scripts/copy-carthage-frameworks.sh\"\n"; - }; 4BE613FF2412F95500C4B1EB /* Carthage */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; @@ -266,7 +261,6 @@ ); inputPaths = ( "$(SRCROOT)/Carthage/Build/iOS/TealiumTagManagement.framework", - "$(SRCROOT)/Carthage/Build/iOS/TealiumDelegate.framework", "$(SRCROOT)/Carthage/Build/iOS/TealiumRemoteCommands.framework", "$(SRCROOT)/Carthage/Build/iOS/TealiumCore.framework", "$(SRCROOT)/Carthage/Build/iOS/ContentsquareModule.framework", @@ -290,7 +284,6 @@ 4BE613FE2412F88A00C4B1EB /* ContentsquareTrackable.swift in Sources */, 4BE613FA2412F81F00C4B1EB /* ContentsquareRemoteCommand.swift in Sources */, 4BEB132024104EDF0060D075 /* ContentsquareConstants.swift in Sources */, - 4BE613FC2412F87E00C4B1EB /* ContentsquareTracker.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -500,6 +493,10 @@ ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; CODE_SIGN_STYLE = Automatic; DEVELOPMENT_TEAM = XC939GDC9P; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/Carthage/Build/iOS", + ); INFOPLIST_FILE = Tests/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", @@ -519,6 +516,10 @@ ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; CODE_SIGN_STYLE = Automatic; DEVELOPMENT_TEAM = XC939GDC9P; + FRAMEWORK_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/Carthage/Build/iOS", + ); INFOPLIST_FILE = Tests/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", diff --git a/TealiumContentsquareExample/Podfile b/TealiumContentsquareExample/Podfile index 079bf31..210f154 100644 --- a/TealiumContentsquareExample/Podfile +++ b/TealiumContentsquareExample/Podfile @@ -6,6 +6,7 @@ target 'TealiumContentsquareExample' do use_frameworks! # Pods for TealiumContentsquareExample - pod "tealium-swift", "~> 1.9" - pod "TealiumContentsquare", :path => "../" + # pod "TealiumContentsquare", :path => "../" + pod "tealium-swift", :path=> "/Users/christina/Projects/work-repos/github/tealium-swift-builder" + pod 'CS_iOS_SDK' end diff --git a/TealiumContentsquareExample/Podfile.lock b/TealiumContentsquareExample/Podfile.lock index 83d6f73..7d980b6 100644 --- a/TealiumContentsquareExample/Podfile.lock +++ b/TealiumContentsquareExample/Podfile.lock @@ -1,44 +1,25 @@ PODS: - - CS_iOS_SDK (3.0.0) - - tealium-swift (1.9.1): - - tealium-swift/TealiumFull (= 1.9.1) - - tealium-swift/Core (1.9.4) - - tealium-swift/TealiumDelegate (1.9.4): - - tealium-swift/Core - - tealium-swift/TealiumFull (1.9.1): - - TealiumCrashReporter - - tealium-swift/TealiumRemoteCommands (1.9.4): - - tealium-swift/Core - - tealium-swift/TealiumTagManagement (1.9.4): - - tealium-swift/Core - - TealiumContentsquare (1.0.0): - - CS_iOS_SDK - - tealium-swift/Core - - tealium-swift/TealiumDelegate - - tealium-swift/TealiumRemoteCommands - - tealium-swift/TealiumTagManagement - - TealiumCrashReporter (1.3.5) + - CS_iOS_SDK (3.2.1) + - tealium-swift (2.0.1): + - tealium-swift/TealiumFull (= 2.0.1) + - tealium-swift/TealiumFull (2.0.1) DEPENDENCIES: - - tealium-swift (~> 1.9) - - TealiumContentsquare (from `../`) + - CS_iOS_SDK + - tealium-swift (from `/Users/christina/Projects/work-repos/github/tealium-swift-builder`) SPEC REPOS: trunk: - CS_iOS_SDK - - tealium-swift - - TealiumCrashReporter EXTERNAL SOURCES: - TealiumContentsquare: - :path: "../" + tealium-swift: + :path: "/Users/christina/Projects/work-repos/github/tealium-swift-builder" SPEC CHECKSUMS: - CS_iOS_SDK: b80d4df95751c8fb8d7b1babf0e0390a701bfef9 - tealium-swift: c478175eadd99de290a65c5c2cc38a7bb86ac28c - TealiumContentsquare: 2245c0fba1a4c584f0c14a8330429df3bc53f904 - TealiumCrashReporter: 74fbdd3703a65740c04e983cd0b360c673199b53 + CS_iOS_SDK: d4ab9a1fd87e8254ce888724cb56256362fe0c1a + tealium-swift: 076272449cf1c60fd9d15b156e0204fdf02da37f -PODFILE CHECKSUM: 5961879c2fd9a2d65d83dfe34f2e8c8c10f67415 +PODFILE CHECKSUM: 2fa462dfa913d72a41a3175b6b744204150c8736 -COCOAPODS: 1.9.0 +COCOAPODS: 1.9.3 diff --git a/TealiumContentsquareExample/TealiumContentsquareExample.xcodeproj/project.pbxproj b/TealiumContentsquareExample/TealiumContentsquareExample.xcodeproj/project.pbxproj index 52951d6..b3c1048 100644 --- a/TealiumContentsquareExample/TealiumContentsquareExample.xcodeproj/project.pbxproj +++ b/TealiumContentsquareExample/TealiumContentsquareExample.xcodeproj/project.pbxproj @@ -21,6 +21,7 @@ 4B4F33F02416F42D009C41B8 /* ScreenView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B4F33EF2416F42D009C41B8 /* ScreenView.swift */; }; 4B4F33F32416F957009C41B8 /* TransactionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B4F33F22416F957009C41B8 /* TransactionView.swift */; }; 4B9781EA2419573C0021B638 /* DynamicVarView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B9781E92419573C0021B638 /* DynamicVarView.swift */; }; + CFEF6CF62527DFCA00902EC6 /* contentsquare.json in Resources */ = {isa = PBXBuildFile; fileRef = CFEF6CF22527DFCA00902EC6 /* contentsquare.json */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -41,6 +42,7 @@ 4B4F33F22416F957009C41B8 /* TransactionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TransactionView.swift; sourceTree = ""; }; 4B9781E92419573C0021B638 /* DynamicVarView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DynamicVarView.swift; sourceTree = ""; }; 91A882ADFA088997BE0E233A /* Pods-TealiumContentsquareExample.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-TealiumContentsquareExample.release.xcconfig"; path = "Target Support Files/Pods-TealiumContentsquareExample/Pods-TealiumContentsquareExample.release.xcconfig"; sourceTree = ""; }; + CFEF6CF22527DFCA00902EC6 /* contentsquare.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = contentsquare.json; sourceTree = ""; }; DE37BE8EAF8C7792D28D9949 /* Pods_TealiumContentsquareExample.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_TealiumContentsquareExample.framework; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ @@ -99,6 +101,7 @@ 4B4F33D92416D946009C41B8 /* SceneDelegate.swift */, 4B4F33DB2416D946009C41B8 /* ContentView.swift */, 4B4F33ED2416DE70009C41B8 /* TealiumHelper.swift */, + CFEF6CF22527DFCA00902EC6 /* contentsquare.json */, 4B4F33DD2416D948009C41B8 /* Assets.xcassets */, 4B4F33E22416D948009C41B8 /* LaunchScreen.storyboard */, 4B4F33E52416D948009C41B8 /* Info.plist */, @@ -190,6 +193,7 @@ files = ( 4B4F33E42416D948009C41B8 /* LaunchScreen.storyboard in Resources */, 4B4F33E12416D948009C41B8 /* Preview Assets.xcassets in Resources */, + CFEF6CF62527DFCA00902EC6 /* contentsquare.json in Resources */, 4B4F33DE2416D948009C41B8 /* Assets.xcassets in Resources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/TealiumContentsquareExample/TealiumContentsquareExample/TealiumHelper.swift b/TealiumContentsquareExample/TealiumContentsquareExample/TealiumHelper.swift index 3dc1947..0cf416c 100644 --- a/TealiumContentsquareExample/TealiumContentsquareExample/TealiumHelper.swift +++ b/TealiumContentsquareExample/TealiumContentsquareExample/TealiumHelper.swift @@ -10,44 +10,55 @@ import Foundation import TealiumSwift import TealiumContentsquare +enum TealiumConfiguration { + static let account = "tealiummobile" + static let profile = "contentsquare-dev" + static let environment = "qa" +} + class TealiumHelper { - + static let shared = TealiumHelper() - let config = TealiumConfig(account: "tealiummobile", - profile: "contentsquare-dev", - environment: "qa", - datasource: nil) - + + let config = TealiumConfig(account: TealiumConfiguration.account, + profile: TealiumConfiguration.profile, + environment: TealiumConfiguration.environment) + var tealium: Tealium? + static var universalData = [String: Any]() + // JSON Remote Command + let contentsquareRemoteCommand = ContentsquareRemoteCommand(type: .remote(url: "https://tags.tiqcdn.com/dle/tealiummobile/demo/contentsquare.json")) + private init() { - let list = TealiumModulesList(isWhitelist: false, - moduleNames: ["autotracking", "collect", "consentmanager"]) - config.modulesList = list - config.logLevel = .verbose - config.shouldUseRemotePublishSettings = true + config.shouldUseRemotePublishSettings = false config.batchingEnabled = false + config.remoteAPIEnabled = true + config.logLevel = .info + config.dispatchers = [Dispatchers.TagManagement, Dispatchers.RemoteCommands] - tealium = Tealium(config: config) { responses in - guard let remoteCommands = self.tealium?.remoteCommands() else { - return - } - let contentsquareTracker = ContentsquareTracker() - let contentsquareCommand = ContentsquareRemoteCommand(contentsquareTracker: contentsquareTracker) - let contentsquareRemoteCommand = contentsquareCommand.remoteCommand() - remoteCommands.add(contentsquareRemoteCommand) - } + config.addRemoteCommand(contentsquareRemoteCommand) + + tealium = Tealium(config: config) } - + + class func start() { _ = TealiumHelper.shared } - + + class func trackView(title: String, data: [String: Any]?) { + let tealiumView = TealiumView(title, dataLayer: data) + TealiumHelper.shared.tealium?.track(tealiumView) + } + class func track(title: String, data: [String: Any]?) { if let data = data { universalData = universalData.merging(data) { _, new in new } } - TealiumHelper.shared.tealium?.track(title: title, data: universalData, completion: nil) + let tealiumEvent = TealiumEvent(title, dataLayer: universalData) + TealiumHelper.shared.tealium?.track(tealiumEvent) } + } diff --git a/TealiumContentsquareExample/TealiumContentsquareExample/Views/TransactionView.swift b/TealiumContentsquareExample/TealiumContentsquareExample/Views/TransactionView.swift index 7b163cd..a4bdc9a 100644 --- a/TealiumContentsquareExample/TealiumContentsquareExample/Views/TransactionView.swift +++ b/TealiumContentsquareExample/TealiumContentsquareExample/Views/TransactionView.swift @@ -37,16 +37,12 @@ struct TransactionView: View { extension TransactionView { func trackTransactionView(price: Double, id: String?) { guard let id = id else { - TealiumHelper.track(title: "transaction", data: - ["transaction": ["price": price, - "currency": "EUR" - ]]) + TealiumHelper.track(title: "transaction", + data: ["price": price, "currency": "EUR"]) return } - TealiumHelper.track(title: "transaction", data: - ["transaction": ["price": price, - "currency": 1, - "transaction_id": id]]) + TealiumHelper.track(title: "transaction", + data: ["price": price,"currency": "USD","transaction_id": id]) } } diff --git a/TealiumContentsquareExample/TealiumContentsquareExample/contentsquare.json b/TealiumContentsquareExample/TealiumContentsquareExample/contentsquare.json new file mode 100644 index 0000000..f5898df --- /dev/null +++ b/TealiumContentsquareExample/TealiumContentsquareExample/contentsquare.json @@ -0,0 +1,21 @@ +{ + "config": {}, + "mappings": { + "screen": "screen_name", + "dynamic_var": "dynamic_var", + "price": "transaction.price", + "currency": "transaction.currency", + "transaction_id": "transaction.transaction_id" + }, + "commands": { + "screen_title": "sendscreenview", + "dynamic_var": "senddynamicvar", + "transaction": "sendtransaction", + "stop_tracking": "stoptracking", + "resume_tracking": "resumetracking", + "forget_me": "forgetme", + "opt_in": "optin", + "opt_out": "optout" + } +} + diff --git a/Tests/ContentsquareTrackerTests.swift b/Tests/ContentsquareTrackerTests.swift index 0fa0daa..f1c69e4 100644 --- a/Tests/ContentsquareTrackerTests.swift +++ b/Tests/ContentsquareTrackerTests.swift @@ -17,66 +17,60 @@ class ContentsquareTrackerTests: XCTestCase { let contentsquareTracker = MockContentsquareTracker() var contentsquareCommand: ContentsquareRemoteCommand! - var remoteCommand: TealiumRemoteCommand! override func setUp() { contentsquareCommand = ContentsquareRemoteCommand(contentsquareTracker: contentsquareTracker) - remoteCommand = contentsquareCommand.remoteCommand() - } - - override func tearDown() { - } func testScreenViewCalledWithKey() { - contentsquareCommand.parseCommands(["sendscreenview"], payload: ["screen_name": "home"]) + contentsquareCommand.processRemoteCommand(with: ["command_name": "sendscreenview", "screen_name": "home"]) XCTAssertEqual(1, contentsquareTracker.sendScreenViewCallCount) } func testScreenViewNotCalledWitouthKey() { - contentsquareCommand.parseCommands(["sendscreenview"], payload: ["not_screen_name": "home"]) + contentsquareCommand.processRemoteCommand(with: ["command_name": "sendscreenview", "not_screen_name": "home"]) XCTAssertEqual(0, contentsquareTracker.sendScreenViewCallCount) } func testTransactionCalledWithKey() { - contentsquareCommand.parseCommands(["sendtransaction"], payload: ["transaction": ["price": 1.99, + contentsquareCommand.processRemoteCommand(with: ["command_name": "sendtransaction", "transaction": ["price": 1.99, "currency": "USD"]]) XCTAssertEqual(1, contentsquareTracker.sendTransactionCallCount) } func testTransactionNotCalledWithoutKey() { - contentsquareCommand.parseCommands(["sendtransaction"], payload: ["not_transaction": ["price": 1.99, + contentsquareCommand.processRemoteCommand(with: ["command_name": "sendtransaction", "not_transaction": ["price": 1.99, "currency": Int(1)]]) XCTAssertEqual(0, contentsquareTracker.sendTransactionCallCount) } func testTransactionCalledWithIdKey() { - contentsquareCommand.parseCommands(["sendtransaction"], payload: ["transaction": ["price": 1.99, + contentsquareCommand.processRemoteCommand(with: ["command_name": "sendtransaction", "transaction": ["price": 1.99, "currency": "CAD", "id": "123"]]) XCTAssertEqual(1, contentsquareTracker.sendTransactionCallCount) } func testTransactionNotCalledWithoutPriceKey() { - contentsquareCommand.parseCommands(["sendtransaction"], payload: ["not_transaction": ["not_price": 1.99, + contentsquareCommand.processRemoteCommand(with: ["command_name": "sendtransaction", "not_transaction": ["not_price": 1.99, "currency": Int(1)]]) XCTAssertEqual(0, contentsquareTracker.sendTransactionCallCount) } func testTransactionNotCalledWithoutCurrencyKey() { - contentsquareCommand.parseCommands(["sendtransaction"], payload: ["not_transaction": ["price": 1.99, + contentsquareCommand.processRemoteCommand(with: ["command_name": "sendtransaction", "not_transaction": ["price": 1.99, "not_currency": Int(1)]]) XCTAssertEqual(0, contentsquareTracker.sendTransactionCallCount) } func testDynamicVarCalledWithKey() { - contentsquareCommand.parseCommands(["senddynamicvar"], payload: ["dynamic_var": ["not_price": 1.99, + contentsquareCommand.processRemoteCommand(with: ["command_name": "senddynamicvar", "dynamic_var": ["not_price": 1.99, "currency": Int(1)]]) XCTAssertEqual(0, contentsquareTracker.sendTransactionCallCount) } func testDynamicVarNotCalledWithoutKey() { - contentsquareCommand.parseCommands(["senddynamicvar"], payload: ["not_dynamic_var": ["price": 1.99, + contentsquareCommand.processRemoteCommand(with: ["command_name": "senddynamicvar", "not_dynamic_var": ["price": 1.99, "not_currency": Int(1)]]) XCTAssertEqual(0, contentsquareTracker.sendTransactionCallCount) } From 87970c45d9adda6f5cedf0bfe0b48b28ca079c6d Mon Sep 17 00:00:00 2001 From: Christina Date: Fri, 2 Oct 2020 16:00:48 -0700 Subject: [PATCH 02/10] Update Cartfile for testing --- Cartfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Cartfile b/Cartfile index ca70819..b4e3bfb 100644 --- a/Cartfile +++ b/Cartfile @@ -1,2 +1,3 @@ -github "tealium/tealium-swift", "~> 2.1" +git "file:///Users/christina/Projects/work-repos/github/tealium-swift-builder" "2.1.0" +#github "tealium/tealium-swift" ~> 2.1 github "ContentSquare/CS_iOS_SDK" From dae942ec6b71a86d18885059cea1c67ba2dfb55a Mon Sep 17 00:00:00 2001 From: Christina Date: Fri, 2 Oct 2020 16:25:55 -0700 Subject: [PATCH 03/10] Update Cartfile for release --- Cartfile | 3 +-- TealiumContentsquare.xcodeproj/project.pbxproj | 2 ++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Cartfile b/Cartfile index b4e3bfb..91adcfb 100644 --- a/Cartfile +++ b/Cartfile @@ -1,3 +1,2 @@ -git "file:///Users/christina/Projects/work-repos/github/tealium-swift-builder" "2.1.0" -#github "tealium/tealium-swift" ~> 2.1 +github "tealium/tealium-swift" ~> 2.1 github "ContentSquare/CS_iOS_SDK" diff --git a/TealiumContentsquare.xcodeproj/project.pbxproj b/TealiumContentsquare.xcodeproj/project.pbxproj index 1bb2b2f..8aa9321 100644 --- a/TealiumContentsquare.xcodeproj/project.pbxproj +++ b/TealiumContentsquare.xcodeproj/project.pbxproj @@ -444,6 +444,7 @@ ); INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 13.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -474,6 +475,7 @@ ); INFOPLIST_FILE = Sources/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 13.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", From 23ad288f57b151e13a548438442f3139e3c98d5b Mon Sep 17 00:00:00 2001 From: Christina Date: Wed, 14 Oct 2020 15:18:39 -0700 Subject: [PATCH 04/10] Updated transaction key --- Sources/ContentsquareConstants.swift | 1 + Sources/ContentsquareRemoteCommand.swift | 8 +++--- ...kable.swift => ContentsquareTracker.swift} | 0 .../project.pbxproj | 26 +++++++++---------- TealiumContentsquareExample/Podfile | 5 ++-- TealiumContentsquareExample/Podfile.lock | 8 +++--- .../contentsquare.json | 6 ++--- Tests/ContentsquareTrackerTests.swift | 8 +++++- Tests/MockContentsquareTracker.swift | 14 +++++----- 9 files changed, 42 insertions(+), 34 deletions(-) rename Sources/{ContentsquareTrackable.swift => ContentsquareTracker.swift} (100%) diff --git a/Sources/ContentsquareConstants.swift b/Sources/ContentsquareConstants.swift index 9fa2eec..f233436 100644 --- a/Sources/ContentsquareConstants.swift +++ b/Sources/ContentsquareConstants.swift @@ -30,6 +30,7 @@ extension ContentsquareRemoteCommand { } enum TransactionProperties { + static let purchase = "purchase" static let transaction = "transaction" static let price = "price" // required static let currency = "currency" // required diff --git a/Sources/ContentsquareRemoteCommand.swift b/Sources/ContentsquareRemoteCommand.swift index 129c4db..a854a99 100644 --- a/Sources/ContentsquareRemoteCommand.swift +++ b/Sources/ContentsquareRemoteCommand.swift @@ -51,9 +51,11 @@ public class ContentsquareRemoteCommand: RemoteCommand { guard let screenName = payload[Contentsquare.ScreenView.screenName] as? String else { return } contentsquareTracker.sendScreenView(screenName: screenName) case .sendTransaction: - guard let options = payload[Contentsquare.TransactionProperties.transaction] as? [String: Any] else { - print("Contentsquare.TransactionProperties.transaction key is missing.") - return + var options = [String: Any]() + if let transaction = payload[Contentsquare.TransactionProperties.transaction] as? [String: Any] { + options = transaction + } else if let purchase = payload[Contentsquare.TransactionProperties.purchase] as? [String: Any] { + options = purchase } guard let price: Double = options[Contentsquare.TransactionProperties.price] as? Double, let currency: String = options[Contentsquare.TransactionProperties.currency] as? String else { return } diff --git a/Sources/ContentsquareTrackable.swift b/Sources/ContentsquareTracker.swift similarity index 100% rename from Sources/ContentsquareTrackable.swift rename to Sources/ContentsquareTracker.swift diff --git a/TealiumContentsquare.xcodeproj/project.pbxproj b/TealiumContentsquare.xcodeproj/project.pbxproj index 8aa9321..f3b4e40 100644 --- a/TealiumContentsquare.xcodeproj/project.pbxproj +++ b/TealiumContentsquare.xcodeproj/project.pbxproj @@ -8,8 +8,6 @@ /* Begin PBXBuildFile section */ 4B4B6E73241B28920084E720 /* ContentsquareTrackerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B4B6E72241B28920084E720 /* ContentsquareTrackerTests.swift */; }; - 4BE613FA2412F81F00C4B1EB /* ContentsquareRemoteCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BE613F92412F81F00C4B1EB /* ContentsquareRemoteCommand.swift */; }; - 4BE613FE2412F88A00C4B1EB /* ContentsquareTrackable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BE613FD2412F88A00C4B1EB /* ContentsquareTrackable.swift */; }; 4BE614022412FF7800C4B1EB /* TealiumTagManagement.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4BE614012412FF7700C4B1EB /* TealiumTagManagement.framework */; platformFilter = ios; }; 4BE614042412FF7B00C4B1EB /* TealiumRemoteCommands.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4BE614032412FF7B00C4B1EB /* TealiumRemoteCommands.framework */; platformFilter = ios; }; 4BE614082412FF8700C4B1EB /* TealiumCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4BE614072412FF8700C4B1EB /* TealiumCore.framework */; platformFilter = ios; }; @@ -17,7 +15,9 @@ 4BEB130F241046820060D075 /* TealiumContentsquare.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4BEB1305241046820060D075 /* TealiumContentsquare.framework */; platformFilter = ios; }; 4BEB1314241046820060D075 /* MockContentsquareTracker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BEB1313241046820060D075 /* MockContentsquareTracker.swift */; }; 4BEB1316241046820060D075 /* TealiumContentsquare.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BEB1308241046820060D075 /* TealiumContentsquare.h */; settings = {ATTRIBUTES = (Public, ); }; }; - 4BEB132024104EDF0060D075 /* ContentsquareConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BEB131F24104EDF0060D075 /* ContentsquareConstants.swift */; }; + CFE092162537AF74005E09AB /* ContentsquareConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = CFE092142537AF74005E09AB /* ContentsquareConstants.swift */; }; + CFE092172537AF74005E09AB /* ContentsquareRemoteCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = CFE092152537AF74005E09AB /* ContentsquareRemoteCommand.swift */; }; + CFE0921A2537AFC8005E09AB /* ContentsquareTracker.swift in Sources */ = {isa = PBXBuildFile; fileRef = CFE092192537AFC8005E09AB /* ContentsquareTracker.swift */; }; CFEF6CE12527DCF900902EC6 /* TealiumRemoteCommands.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4BE614032412FF7B00C4B1EB /* TealiumRemoteCommands.framework */; }; CFEF6CE62527DD4400902EC6 /* TealiumRemoteCommands.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 4BE614032412FF7B00C4B1EB /* TealiumRemoteCommands.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; CFEF6CE92527DD7900902EC6 /* TealiumCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4BE614072412FF8700C4B1EB /* TealiumCore.framework */; }; @@ -50,8 +50,6 @@ /* Begin PBXFileReference section */ 4B4B6E72241B28920084E720 /* ContentsquareTrackerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentsquareTrackerTests.swift; sourceTree = ""; }; - 4BE613F92412F81F00C4B1EB /* ContentsquareRemoteCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentsquareRemoteCommand.swift; sourceTree = ""; }; - 4BE613FD2412F88A00C4B1EB /* ContentsquareTrackable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentsquareTrackable.swift; sourceTree = ""; }; 4BE614012412FF7700C4B1EB /* TealiumTagManagement.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = TealiumTagManagement.framework; path = Carthage/Build/iOS/TealiumTagManagement.framework; sourceTree = ""; }; 4BE614032412FF7B00C4B1EB /* TealiumRemoteCommands.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = TealiumRemoteCommands.framework; path = Carthage/Build/iOS/TealiumRemoteCommands.framework; sourceTree = ""; }; 4BE614052412FF8300C4B1EB /* TealiumDelegate.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = TealiumDelegate.framework; path = Carthage/Build/iOS/TealiumDelegate.framework; sourceTree = ""; }; @@ -63,7 +61,9 @@ 4BEB130E241046820060D075 /* TealiumContentsquareTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = TealiumContentsquareTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 4BEB1313241046820060D075 /* MockContentsquareTracker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockContentsquareTracker.swift; sourceTree = ""; }; 4BEB1315241046820060D075 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 4BEB131F24104EDF0060D075 /* ContentsquareConstants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentsquareConstants.swift; sourceTree = ""; }; + CFE092142537AF74005E09AB /* ContentsquareConstants.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContentsquareConstants.swift; sourceTree = ""; }; + CFE092152537AF74005E09AB /* ContentsquareRemoteCommand.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContentsquareRemoteCommand.swift; sourceTree = ""; }; + CFE092192537AFC8005E09AB /* ContentsquareTracker.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContentsquareTracker.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -125,9 +125,9 @@ 4BEB1307241046820060D075 /* Sources */ = { isa = PBXGroup; children = ( - 4BEB131F24104EDF0060D075 /* ContentsquareConstants.swift */, - 4BE613F92412F81F00C4B1EB /* ContentsquareRemoteCommand.swift */, - 4BE613FD2412F88A00C4B1EB /* ContentsquareTrackable.swift */, + CFE092142537AF74005E09AB /* ContentsquareConstants.swift */, + CFE092152537AF74005E09AB /* ContentsquareRemoteCommand.swift */, + CFE092192537AFC8005E09AB /* ContentsquareTracker.swift */, 4BEB1308241046820060D075 /* TealiumContentsquare.h */, 4BEB1309241046820060D075 /* Info.plist */, ); @@ -208,7 +208,7 @@ TargetAttributes = { 4BEB1304241046820060D075 = { CreatedOnToolsVersion = 11.2.1; - LastSwiftMigration = 1120; + LastSwiftMigration = 1200; }; 4BEB130D241046820060D075 = { CreatedOnToolsVersion = 11.2.1; @@ -281,9 +281,9 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 4BE613FE2412F88A00C4B1EB /* ContentsquareTrackable.swift in Sources */, - 4BE613FA2412F81F00C4B1EB /* ContentsquareRemoteCommand.swift in Sources */, - 4BEB132024104EDF0060D075 /* ContentsquareConstants.swift in Sources */, + CFE092172537AF74005E09AB /* ContentsquareRemoteCommand.swift in Sources */, + CFE0921A2537AFC8005E09AB /* ContentsquareTracker.swift in Sources */, + CFE092162537AF74005E09AB /* ContentsquareConstants.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/TealiumContentsquareExample/Podfile b/TealiumContentsquareExample/Podfile index 210f154..d6d699c 100644 --- a/TealiumContentsquareExample/Podfile +++ b/TealiumContentsquareExample/Podfile @@ -6,7 +6,6 @@ target 'TealiumContentsquareExample' do use_frameworks! # Pods for TealiumContentsquareExample - # pod "TealiumContentsquare", :path => "../" - pod "tealium-swift", :path=> "/Users/christina/Projects/work-repos/github/tealium-swift-builder" - pod 'CS_iOS_SDK' + pod "TealiumContentsquare", :path => "../" + end diff --git a/TealiumContentsquareExample/Podfile.lock b/TealiumContentsquareExample/Podfile.lock index 7d980b6..d99d552 100644 --- a/TealiumContentsquareExample/Podfile.lock +++ b/TealiumContentsquareExample/Podfile.lock @@ -1,8 +1,8 @@ PODS: - CS_iOS_SDK (3.2.1) - - tealium-swift (2.0.1): - - tealium-swift/TealiumFull (= 2.0.1) - - tealium-swift/TealiumFull (2.0.1) + - tealium-swift (2.1.0): + - tealium-swift/TealiumFull (= 2.1.0) + - tealium-swift/TealiumFull (2.1.0) DEPENDENCIES: - CS_iOS_SDK @@ -18,7 +18,7 @@ EXTERNAL SOURCES: SPEC CHECKSUMS: CS_iOS_SDK: d4ab9a1fd87e8254ce888724cb56256362fe0c1a - tealium-swift: 076272449cf1c60fd9d15b156e0204fdf02da37f + tealium-swift: a670c2c6f3e7e5d775d9507387e8858a8541e526 PODFILE CHECKSUM: 2fa462dfa913d72a41a3175b6b744204150c8736 diff --git a/TealiumContentsquareExample/TealiumContentsquareExample/contentsquare.json b/TealiumContentsquareExample/TealiumContentsquareExample/contentsquare.json index f5898df..4feccf4 100644 --- a/TealiumContentsquareExample/TealiumContentsquareExample/contentsquare.json +++ b/TealiumContentsquareExample/TealiumContentsquareExample/contentsquare.json @@ -3,9 +3,9 @@ "mappings": { "screen": "screen_name", "dynamic_var": "dynamic_var", - "price": "transaction.price", - "currency": "transaction.currency", - "transaction_id": "transaction.transaction_id" + "price": "purchase.price", + "currency": "purchase.currency", + "transaction_id": "purchase.transaction_id" }, "commands": { "screen_title": "sendscreenview", diff --git a/Tests/ContentsquareTrackerTests.swift b/Tests/ContentsquareTrackerTests.swift index f1c69e4..2a0ed70 100644 --- a/Tests/ContentsquareTrackerTests.swift +++ b/Tests/ContentsquareTrackerTests.swift @@ -3,7 +3,7 @@ // TealiumContentsquareTests // // Created by Jonathan Wong on 3/12/20. -// Copyright © 2020 Jonathan Wong. All rights reserved. +// Copyright © 2020 Tealium. All rights reserved. // import XCTest @@ -38,6 +38,12 @@ class ContentsquareTrackerTests: XCTestCase { XCTAssertEqual(1, contentsquareTracker.sendTransactionCallCount) } + func testTransactionCalledWithKeyJSON() { + contentsquareCommand.processRemoteCommand(with: ["command_name": "sendtransaction", "purchase": ["price": 1.99, + "currency": "USD"]]) + XCTAssertEqual(1, contentsquareTracker.sendTransactionCallCount) + } + func testTransactionNotCalledWithoutKey() { contentsquareCommand.processRemoteCommand(with: ["command_name": "sendtransaction", "not_transaction": ["price": 1.99, "currency": Int(1)]]) diff --git a/Tests/MockContentsquareTracker.swift b/Tests/MockContentsquareTracker.swift index 7b961b3..7195e1c 100644 --- a/Tests/MockContentsquareTracker.swift +++ b/Tests/MockContentsquareTracker.swift @@ -1,11 +1,11 @@ -//// -//// TealiumContentsquareTests.swift -//// TealiumContentsquareTests -//// -//// Created by Jonathan Wong on 3/4/20. -//// Copyright © 2020 Jonathan Wong. All rights reserved. -//// // +// TealiumContentsquareTests.swift +// TealiumContentsquareTests +// +// Created by Jonathan Wong on 3/4/20. +// Copyright © 2020 Tealium. All rights reserved. +// + import XCTest @testable import TealiumContentsquare From 91eb64a09df616bbb19387ba1ae6d94abd0a9394 Mon Sep 17 00:00:00 2001 From: Christina Date: Mon, 19 Oct 2020 13:37:00 -0700 Subject: [PATCH 05/10] Update Tracker to Instance --- ...cker.swift => ContentsquareInstance.swift} | 6 ++-- Sources/ContentsquareRemoteCommand.swift | 24 ++++++++-------- .../project.pbxproj | 24 ++++++++-------- .../AppDelegate.swift | 2 +- .../ContentView.swift | 2 +- .../SceneDelegate.swift | 2 +- .../TealiumHelper.swift | 2 +- .../Views/ButtonViewModifier.swift | 2 +- .../Views/DynamicItemVarView.swift | 2 +- .../Views/DynamicVarView.swift | 2 +- .../Views/MiscellaneousView.swift | 2 +- .../Views/ScreenView.swift | 2 +- .../Views/TransactionView.swift | 2 +- ...swift => ContentsquareInstanceTests.swift} | 28 +++++++++---------- ....swift => MockContentsquareInstance.swift} | 2 +- 15 files changed, 52 insertions(+), 52 deletions(-) rename Sources/{ContentsquareTracker.swift => ContentsquareInstance.swift} (98%) rename Tests/{ContentsquareTrackerTests.swift => ContentsquareInstanceTests.swift} (78%) rename Tests/{MockContentsquareTracker.swift => MockContentsquareInstance.swift} (95%) diff --git a/Sources/ContentsquareTracker.swift b/Sources/ContentsquareInstance.swift similarity index 98% rename from Sources/ContentsquareTracker.swift rename to Sources/ContentsquareInstance.swift index 541ac75..688e93d 100644 --- a/Sources/ContentsquareTracker.swift +++ b/Sources/ContentsquareInstance.swift @@ -1,5 +1,5 @@ // -// ContentsquareTracker.swift +// ContentsquareInstance.swift // TealiumContentsquare // // Created by Jonathan Wong on 3/6/20. @@ -9,7 +9,7 @@ import Foundation import ContentsquareModule -public protocol ContentsquareTrackable { +public protocol ContentsquareCommand { func sendScreenView(screenName: String) func sendTransaction(price: Double, currency: String, transactionId: String?) func sendDynamicVar(dynamicVar: [String: Any]) @@ -20,7 +20,7 @@ public protocol ContentsquareTrackable { func optOut() } -public class ContentsquareTracker: ContentsquareTrackable { +public class ContentsquareInstance: ContentsquareCommand { public init() {} diff --git a/Sources/ContentsquareRemoteCommand.swift b/Sources/ContentsquareRemoteCommand.swift index a854a99..662def1 100644 --- a/Sources/ContentsquareRemoteCommand.swift +++ b/Sources/ContentsquareRemoteCommand.swift @@ -17,10 +17,10 @@ import TealiumRemoteCommands public class ContentsquareRemoteCommand: RemoteCommand { - var contentsquareTracker: ContentsquareTrackable? + var contentsquareInstance: ContentsquareCommand? - public init(contentsquareTracker: ContentsquareTrackable = ContentsquareTracker(), type: RemoteCommandType = .webview) { - self.contentsquareTracker = contentsquareTracker + public init(contentsquareInstance: ContentsquareCommand = ContentsquareInstance(), type: RemoteCommandType = .webview) { + self.contentsquareInstance = contentsquareInstance weak var selfWorkaround: ContentsquareRemoteCommand? super.init(commandId: Contentsquare.commandId, description: Contentsquare.description, @@ -35,7 +35,7 @@ public class ContentsquareRemoteCommand: RemoteCommand { } func processRemoteCommand(with payload: [String: Any]) { - guard let contentsquareTracker = contentsquareTracker, + guard let contentsquareInstance = contentsquareInstance, let command = payload[Contentsquare.commandKey] as? String else { return } @@ -49,7 +49,7 @@ public class ContentsquareRemoteCommand: RemoteCommand { switch command { case .sendScreenView: guard let screenName = payload[Contentsquare.ScreenView.screenName] as? String else { return } - contentsquareTracker.sendScreenView(screenName: screenName) + contentsquareInstance.sendScreenView(screenName: screenName) case .sendTransaction: var options = [String: Any]() if let transaction = payload[Contentsquare.TransactionProperties.transaction] as? [String: Any] { @@ -60,20 +60,20 @@ public class ContentsquareRemoteCommand: RemoteCommand { guard let price: Double = options[Contentsquare.TransactionProperties.price] as? Double, let currency: String = options[Contentsquare.TransactionProperties.currency] as? String else { return } let transactionId: String? = options[Contentsquare.TransactionProperties.transactionId] as? String - contentsquareTracker.sendTransaction(price: price, currency: currency, transactionId: transactionId) + contentsquareInstance.sendTransaction(price: price, currency: currency, transactionId: transactionId) case .sendDynamicVar: guard let dynamicVar = payload[Contentsquare.DynamicVar.dynamicVar] as? [String: Any] else { return } - contentsquareTracker.sendDynamicVar(dynamicVar: dynamicVar) + contentsquareInstance.sendDynamicVar(dynamicVar: dynamicVar) case .stopTracking: - contentsquareTracker.stopTracking() + contentsquareInstance.stopTracking() case .resumeTracking: - contentsquareTracker.resumeTracking() + contentsquareInstance.resumeTracking() case .forgetMe: - contentsquareTracker.forgetMe() + contentsquareInstance.forgetMe() case .optIn: - contentsquareTracker.optIn() + contentsquareInstance.optIn() case .optOut: - contentsquareTracker.optOut() + contentsquareInstance.optOut() default: break } } diff --git a/TealiumContentsquare.xcodeproj/project.pbxproj b/TealiumContentsquare.xcodeproj/project.pbxproj index f3b4e40..8a41151 100644 --- a/TealiumContentsquare.xcodeproj/project.pbxproj +++ b/TealiumContentsquare.xcodeproj/project.pbxproj @@ -7,17 +7,17 @@ objects = { /* Begin PBXBuildFile section */ - 4B4B6E73241B28920084E720 /* ContentsquareTrackerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B4B6E72241B28920084E720 /* ContentsquareTrackerTests.swift */; }; + 4B4B6E73241B28920084E720 /* ContentsquareInstanceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B4B6E72241B28920084E720 /* ContentsquareInstanceTests.swift */; }; 4BE614022412FF7800C4B1EB /* TealiumTagManagement.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4BE614012412FF7700C4B1EB /* TealiumTagManagement.framework */; platformFilter = ios; }; 4BE614042412FF7B00C4B1EB /* TealiumRemoteCommands.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4BE614032412FF7B00C4B1EB /* TealiumRemoteCommands.framework */; platformFilter = ios; }; 4BE614082412FF8700C4B1EB /* TealiumCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4BE614072412FF8700C4B1EB /* TealiumCore.framework */; platformFilter = ios; }; 4BE6140A2413001100C4B1EB /* ContentsquareModule.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4BE614092413001100C4B1EB /* ContentsquareModule.framework */; platformFilter = ios; }; 4BEB130F241046820060D075 /* TealiumContentsquare.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4BEB1305241046820060D075 /* TealiumContentsquare.framework */; platformFilter = ios; }; - 4BEB1314241046820060D075 /* MockContentsquareTracker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BEB1313241046820060D075 /* MockContentsquareTracker.swift */; }; + 4BEB1314241046820060D075 /* MockContentsquareInstance.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4BEB1313241046820060D075 /* MockContentsquareInstance.swift */; }; 4BEB1316241046820060D075 /* TealiumContentsquare.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BEB1308241046820060D075 /* TealiumContentsquare.h */; settings = {ATTRIBUTES = (Public, ); }; }; CFE092162537AF74005E09AB /* ContentsquareConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = CFE092142537AF74005E09AB /* ContentsquareConstants.swift */; }; CFE092172537AF74005E09AB /* ContentsquareRemoteCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = CFE092152537AF74005E09AB /* ContentsquareRemoteCommand.swift */; }; - CFE0921A2537AFC8005E09AB /* ContentsquareTracker.swift in Sources */ = {isa = PBXBuildFile; fileRef = CFE092192537AFC8005E09AB /* ContentsquareTracker.swift */; }; + CFE0921A2537AFC8005E09AB /* ContentsquareInstance.swift in Sources */ = {isa = PBXBuildFile; fileRef = CFE092192537AFC8005E09AB /* ContentsquareInstance.swift */; }; CFEF6CE12527DCF900902EC6 /* TealiumRemoteCommands.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4BE614032412FF7B00C4B1EB /* TealiumRemoteCommands.framework */; }; CFEF6CE62527DD4400902EC6 /* TealiumRemoteCommands.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 4BE614032412FF7B00C4B1EB /* TealiumRemoteCommands.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; CFEF6CE92527DD7900902EC6 /* TealiumCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4BE614072412FF8700C4B1EB /* TealiumCore.framework */; }; @@ -49,7 +49,7 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ - 4B4B6E72241B28920084E720 /* ContentsquareTrackerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentsquareTrackerTests.swift; sourceTree = ""; }; + 4B4B6E72241B28920084E720 /* ContentsquareInstanceTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentsquareInstanceTests.swift; sourceTree = ""; }; 4BE614012412FF7700C4B1EB /* TealiumTagManagement.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = TealiumTagManagement.framework; path = Carthage/Build/iOS/TealiumTagManagement.framework; sourceTree = ""; }; 4BE614032412FF7B00C4B1EB /* TealiumRemoteCommands.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = TealiumRemoteCommands.framework; path = Carthage/Build/iOS/TealiumRemoteCommands.framework; sourceTree = ""; }; 4BE614052412FF8300C4B1EB /* TealiumDelegate.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = TealiumDelegate.framework; path = Carthage/Build/iOS/TealiumDelegate.framework; sourceTree = ""; }; @@ -59,11 +59,11 @@ 4BEB1308241046820060D075 /* TealiumContentsquare.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TealiumContentsquare.h; sourceTree = ""; }; 4BEB1309241046820060D075 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 4BEB130E241046820060D075 /* TealiumContentsquareTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = TealiumContentsquareTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; - 4BEB1313241046820060D075 /* MockContentsquareTracker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockContentsquareTracker.swift; sourceTree = ""; }; + 4BEB1313241046820060D075 /* MockContentsquareInstance.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockContentsquareInstance.swift; sourceTree = ""; }; 4BEB1315241046820060D075 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; CFE092142537AF74005E09AB /* ContentsquareConstants.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContentsquareConstants.swift; sourceTree = ""; }; CFE092152537AF74005E09AB /* ContentsquareRemoteCommand.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContentsquareRemoteCommand.swift; sourceTree = ""; }; - CFE092192537AFC8005E09AB /* ContentsquareTracker.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContentsquareTracker.swift; sourceTree = ""; }; + CFE092192537AFC8005E09AB /* ContentsquareInstance.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContentsquareInstance.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -127,7 +127,7 @@ children = ( CFE092142537AF74005E09AB /* ContentsquareConstants.swift */, CFE092152537AF74005E09AB /* ContentsquareRemoteCommand.swift */, - CFE092192537AFC8005E09AB /* ContentsquareTracker.swift */, + CFE092192537AFC8005E09AB /* ContentsquareInstance.swift */, 4BEB1308241046820060D075 /* TealiumContentsquare.h */, 4BEB1309241046820060D075 /* Info.plist */, ); @@ -137,8 +137,8 @@ 4BEB1312241046820060D075 /* Tests */ = { isa = PBXGroup; children = ( - 4BEB1313241046820060D075 /* MockContentsquareTracker.swift */, - 4B4B6E72241B28920084E720 /* ContentsquareTrackerTests.swift */, + 4BEB1313241046820060D075 /* MockContentsquareInstance.swift */, + 4B4B6E72241B28920084E720 /* ContentsquareInstanceTests.swift */, 4BEB1315241046820060D075 /* Info.plist */, ); path = Tests; @@ -282,7 +282,7 @@ buildActionMask = 2147483647; files = ( CFE092172537AF74005E09AB /* ContentsquareRemoteCommand.swift in Sources */, - CFE0921A2537AFC8005E09AB /* ContentsquareTracker.swift in Sources */, + CFE0921A2537AFC8005E09AB /* ContentsquareInstance.swift in Sources */, CFE092162537AF74005E09AB /* ContentsquareConstants.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -291,8 +291,8 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 4BEB1314241046820060D075 /* MockContentsquareTracker.swift in Sources */, - 4B4B6E73241B28920084E720 /* ContentsquareTrackerTests.swift in Sources */, + 4BEB1314241046820060D075 /* MockContentsquareInstance.swift in Sources */, + 4B4B6E73241B28920084E720 /* ContentsquareInstanceTests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/TealiumContentsquareExample/TealiumContentsquareExample/AppDelegate.swift b/TealiumContentsquareExample/TealiumContentsquareExample/AppDelegate.swift index 9bc0e32..2d2a215 100644 --- a/TealiumContentsquareExample/TealiumContentsquareExample/AppDelegate.swift +++ b/TealiumContentsquareExample/TealiumContentsquareExample/AppDelegate.swift @@ -3,7 +3,7 @@ // TealiumContentsquareExample // // Created by Jonathan Wong on 3/9/20. -// Copyright © 2020 Jonathan Wong. All rights reserved. +// Copyright © 2020 Tealium. All rights reserved. // import UIKit diff --git a/TealiumContentsquareExample/TealiumContentsquareExample/ContentView.swift b/TealiumContentsquareExample/TealiumContentsquareExample/ContentView.swift index 21fdc92..a831ece 100644 --- a/TealiumContentsquareExample/TealiumContentsquareExample/ContentView.swift +++ b/TealiumContentsquareExample/TealiumContentsquareExample/ContentView.swift @@ -3,7 +3,7 @@ // TealiumContentsquareExample // // Created by Jonathan Wong on 3/9/20. -// Copyright © 2020 Jonathan Wong. All rights reserved. +// Copyright © 2020 Tealium. All rights reserved. // import SwiftUI diff --git a/TealiumContentsquareExample/TealiumContentsquareExample/SceneDelegate.swift b/TealiumContentsquareExample/TealiumContentsquareExample/SceneDelegate.swift index d931190..78280fe 100644 --- a/TealiumContentsquareExample/TealiumContentsquareExample/SceneDelegate.swift +++ b/TealiumContentsquareExample/TealiumContentsquareExample/SceneDelegate.swift @@ -3,7 +3,7 @@ // TealiumContentsquareExample // // Created by Jonathan Wong on 3/9/20. -// Copyright © 2020 Jonathan Wong. All rights reserved. +// Copyright © 2020 Tealium. All rights reserved. // import UIKit diff --git a/TealiumContentsquareExample/TealiumContentsquareExample/TealiumHelper.swift b/TealiumContentsquareExample/TealiumContentsquareExample/TealiumHelper.swift index 0cf416c..1e0f78c 100644 --- a/TealiumContentsquareExample/TealiumContentsquareExample/TealiumHelper.swift +++ b/TealiumContentsquareExample/TealiumContentsquareExample/TealiumHelper.swift @@ -3,7 +3,7 @@ // BrazeRemoteCommand // // Created by Jonathan Wong on 5/29/19. -// Copyright © 2019 Jonathan Wong. All rights reserved. +// Copyright © 2019 Tealium. All rights reserved. // import Foundation diff --git a/TealiumContentsquareExample/TealiumContentsquareExample/Views/ButtonViewModifier.swift b/TealiumContentsquareExample/TealiumContentsquareExample/Views/ButtonViewModifier.swift index ba3826d..8d8ec4b 100644 --- a/TealiumContentsquareExample/TealiumContentsquareExample/Views/ButtonViewModifier.swift +++ b/TealiumContentsquareExample/TealiumContentsquareExample/Views/ButtonViewModifier.swift @@ -3,7 +3,7 @@ // TealiumContentsquareExample // // Created by Jonathan Wong on 3/12/20. -// Copyright © 2020 Jonathan Wong. All rights reserved. +// Copyright © 2020 Tealium. All rights reserved. // import SwiftUI diff --git a/TealiumContentsquareExample/TealiumContentsquareExample/Views/DynamicItemVarView.swift b/TealiumContentsquareExample/TealiumContentsquareExample/Views/DynamicItemVarView.swift index b1c9e27..2392b44 100644 --- a/TealiumContentsquareExample/TealiumContentsquareExample/Views/DynamicItemVarView.swift +++ b/TealiumContentsquareExample/TealiumContentsquareExample/Views/DynamicItemVarView.swift @@ -3,7 +3,7 @@ // TealiumContentsquareExample // // Created by Jonathan Wong on 3/11/20. -// Copyright © 2020 Jonathan Wong. All rights reserved. +// Copyright © 2020 Tealium. All rights reserved. // import SwiftUI diff --git a/TealiumContentsquareExample/TealiumContentsquareExample/Views/DynamicVarView.swift b/TealiumContentsquareExample/TealiumContentsquareExample/Views/DynamicVarView.swift index 64601ab..177203d 100644 --- a/TealiumContentsquareExample/TealiumContentsquareExample/Views/DynamicVarView.swift +++ b/TealiumContentsquareExample/TealiumContentsquareExample/Views/DynamicVarView.swift @@ -3,7 +3,7 @@ // TealiumContentsquareExample // // Created by Jonathan Wong on 3/11/20. -// Copyright © 2020 Jonathan Wong. All rights reserved. +// Copyright © 2020 Tealium. All rights reserved. // import SwiftUI diff --git a/TealiumContentsquareExample/TealiumContentsquareExample/Views/MiscellaneousView.swift b/TealiumContentsquareExample/TealiumContentsquareExample/Views/MiscellaneousView.swift index 221914c..c179b65 100644 --- a/TealiumContentsquareExample/TealiumContentsquareExample/Views/MiscellaneousView.swift +++ b/TealiumContentsquareExample/TealiumContentsquareExample/Views/MiscellaneousView.swift @@ -3,7 +3,7 @@ // TealiumContentsquareExample // // Created by Jonathan Wong on 3/12/20. -// Copyright © 2020 Jonathan Wong. All rights reserved. +// Copyright © 2020 Tealium. All rights reserved. // import SwiftUI diff --git a/TealiumContentsquareExample/TealiumContentsquareExample/Views/ScreenView.swift b/TealiumContentsquareExample/TealiumContentsquareExample/Views/ScreenView.swift index 4118799..596880c 100644 --- a/TealiumContentsquareExample/TealiumContentsquareExample/Views/ScreenView.swift +++ b/TealiumContentsquareExample/TealiumContentsquareExample/Views/ScreenView.swift @@ -3,7 +3,7 @@ // TealiumContentsquareExample // // Created by Jonathan Wong on 3/9/20. -// Copyright © 2020 Jonathan Wong. All rights reserved. +// Copyright © 2020 Tealium. All rights reserved. // import SwiftUI diff --git a/TealiumContentsquareExample/TealiumContentsquareExample/Views/TransactionView.swift b/TealiumContentsquareExample/TealiumContentsquareExample/Views/TransactionView.swift index a4bdc9a..79883b1 100644 --- a/TealiumContentsquareExample/TealiumContentsquareExample/Views/TransactionView.swift +++ b/TealiumContentsquareExample/TealiumContentsquareExample/Views/TransactionView.swift @@ -3,7 +3,7 @@ // TealiumContentsquareExample // // Created by Jonathan Wong on 3/9/20. -// Copyright © 2020 Jonathan Wong. All rights reserved. +// Copyright © 2020 Tealium. All rights reserved. // import SwiftUI diff --git a/Tests/ContentsquareTrackerTests.swift b/Tests/ContentsquareInstanceTests.swift similarity index 78% rename from Tests/ContentsquareTrackerTests.swift rename to Tests/ContentsquareInstanceTests.swift index 2a0ed70..7e7ed7f 100644 --- a/Tests/ContentsquareTrackerTests.swift +++ b/Tests/ContentsquareInstanceTests.swift @@ -1,5 +1,5 @@ // -// ContentsquareTrackerTests.swift +// ContentsquareInstanceTests.swift // TealiumContentsquareTests // // Created by Jonathan Wong on 3/12/20. @@ -13,71 +13,71 @@ import XCTest import TealiumRemoteCommands #endif -class ContentsquareTrackerTests: XCTestCase { +class ContentsquareInstanceTests: XCTestCase { - let contentsquareTracker = MockContentsquareTracker() + let contentsquareInstance = MockContentsquareInstance() var contentsquareCommand: ContentsquareRemoteCommand! override func setUp() { - contentsquareCommand = ContentsquareRemoteCommand(contentsquareTracker: contentsquareTracker) + contentsquareCommand = ContentsquareRemoteCommand(contentsquareInstance: contentsquareInstance) } func testScreenViewCalledWithKey() { contentsquareCommand.processRemoteCommand(with: ["command_name": "sendscreenview", "screen_name": "home"]) - XCTAssertEqual(1, contentsquareTracker.sendScreenViewCallCount) + XCTAssertEqual(1, contentsquareInstance.sendScreenViewCallCount) } func testScreenViewNotCalledWitouthKey() { contentsquareCommand.processRemoteCommand(with: ["command_name": "sendscreenview", "not_screen_name": "home"]) - XCTAssertEqual(0, contentsquareTracker.sendScreenViewCallCount) + XCTAssertEqual(0, contentsquareInstance.sendScreenViewCallCount) } func testTransactionCalledWithKey() { contentsquareCommand.processRemoteCommand(with: ["command_name": "sendtransaction", "transaction": ["price": 1.99, "currency": "USD"]]) - XCTAssertEqual(1, contentsquareTracker.sendTransactionCallCount) + XCTAssertEqual(1, contentsquareInstance.sendTransactionCallCount) } func testTransactionCalledWithKeyJSON() { contentsquareCommand.processRemoteCommand(with: ["command_name": "sendtransaction", "purchase": ["price": 1.99, "currency": "USD"]]) - XCTAssertEqual(1, contentsquareTracker.sendTransactionCallCount) + XCTAssertEqual(1, contentsquareInstance.sendTransactionCallCount) } func testTransactionNotCalledWithoutKey() { contentsquareCommand.processRemoteCommand(with: ["command_name": "sendtransaction", "not_transaction": ["price": 1.99, "currency": Int(1)]]) - XCTAssertEqual(0, contentsquareTracker.sendTransactionCallCount) + XCTAssertEqual(0, contentsquareInstance.sendTransactionCallCount) } func testTransactionCalledWithIdKey() { contentsquareCommand.processRemoteCommand(with: ["command_name": "sendtransaction", "transaction": ["price": 1.99, "currency": "CAD", "id": "123"]]) - XCTAssertEqual(1, contentsquareTracker.sendTransactionCallCount) + XCTAssertEqual(1, contentsquareInstance.sendTransactionCallCount) } func testTransactionNotCalledWithoutPriceKey() { contentsquareCommand.processRemoteCommand(with: ["command_name": "sendtransaction", "not_transaction": ["not_price": 1.99, "currency": Int(1)]]) - XCTAssertEqual(0, contentsquareTracker.sendTransactionCallCount) + XCTAssertEqual(0, contentsquareInstance.sendTransactionCallCount) } func testTransactionNotCalledWithoutCurrencyKey() { contentsquareCommand.processRemoteCommand(with: ["command_name": "sendtransaction", "not_transaction": ["price": 1.99, "not_currency": Int(1)]]) - XCTAssertEqual(0, contentsquareTracker.sendTransactionCallCount) + XCTAssertEqual(0, contentsquareInstance.sendTransactionCallCount) } func testDynamicVarCalledWithKey() { contentsquareCommand.processRemoteCommand(with: ["command_name": "senddynamicvar", "dynamic_var": ["not_price": 1.99, "currency": Int(1)]]) - XCTAssertEqual(0, contentsquareTracker.sendTransactionCallCount) + XCTAssertEqual(0, contentsquareInstance.sendTransactionCallCount) } func testDynamicVarNotCalledWithoutKey() { contentsquareCommand.processRemoteCommand(with: ["command_name": "senddynamicvar", "not_dynamic_var": ["price": 1.99, "not_currency": Int(1)]]) - XCTAssertEqual(0, contentsquareTracker.sendTransactionCallCount) + XCTAssertEqual(0, contentsquareInstance.sendTransactionCallCount) } } diff --git a/Tests/MockContentsquareTracker.swift b/Tests/MockContentsquareInstance.swift similarity index 95% rename from Tests/MockContentsquareTracker.swift rename to Tests/MockContentsquareInstance.swift index 7195e1c..cca0bc7 100644 --- a/Tests/MockContentsquareTracker.swift +++ b/Tests/MockContentsquareInstance.swift @@ -9,7 +9,7 @@ import XCTest @testable import TealiumContentsquare -class MockContentsquareTracker: ContentsquareTrackable { +class MockContentsquareInstance: ContentsquareCommand { var sendScreenViewCallCount = 0 var sendTransactionCallCount = 0 From 08126cf29f1afed12d6fcdcb08965e6d977d4363 Mon Sep 17 00:00:00 2001 From: Christina Date: Tue, 20 Oct 2020 16:11:05 -0700 Subject: [PATCH 06/10] JSON remote commands --- TealiumContentsquareExample/Podfile.lock | 26 ++++++++++++++++-------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/TealiumContentsquareExample/Podfile.lock b/TealiumContentsquareExample/Podfile.lock index d99d552..ed7db78 100644 --- a/TealiumContentsquareExample/Podfile.lock +++ b/TealiumContentsquareExample/Podfile.lock @@ -1,25 +1,33 @@ PODS: - CS_iOS_SDK (3.2.1) - - tealium-swift (2.1.0): - - tealium-swift/TealiumFull (= 2.1.0) - - tealium-swift/TealiumFull (2.1.0) + - tealium-swift/Core (2.1.0) + - tealium-swift/RemoteCommands (2.1.0): + - tealium-swift/Core + - tealium-swift/TagManagement (2.1.0): + - tealium-swift/Core + - TealiumContentsquare (2.0.0): + - CS_iOS_SDK + - tealium-swift/Core (~> 2.1) + - tealium-swift/RemoteCommands (~> 2.1) + - tealium-swift/TagManagement (~> 2.1) DEPENDENCIES: - - CS_iOS_SDK - - tealium-swift (from `/Users/christina/Projects/work-repos/github/tealium-swift-builder`) + - TealiumContentsquare (from `../`) SPEC REPOS: trunk: - CS_iOS_SDK + - tealium-swift EXTERNAL SOURCES: - tealium-swift: - :path: "/Users/christina/Projects/work-repos/github/tealium-swift-builder" + TealiumContentsquare: + :path: "../" SPEC CHECKSUMS: CS_iOS_SDK: d4ab9a1fd87e8254ce888724cb56256362fe0c1a tealium-swift: a670c2c6f3e7e5d775d9507387e8858a8541e526 + TealiumContentsquare: 3177c797b0a8b001e1b211122b7728db05a8b481 -PODFILE CHECKSUM: 2fa462dfa913d72a41a3175b6b744204150c8736 +PODFILE CHECKSUM: 484e8e2d3515241393ce3d9ae9ded5e340792e49 -COCOAPODS: 1.9.3 +COCOAPODS: 1.10.0 From d38bb5743a25c741a71c762bd515c1913eae8f4c Mon Sep 17 00:00:00 2001 From: Christina Date: Tue, 20 Oct 2020 16:11:47 -0700 Subject: [PATCH 07/10] Remove Objective C files --- Objective-C/ContentsquareCommand.swift | 79 ---- Objective-C/ContentsquareConstants.swift | 42 --- Objective-C/ContentsquareTrackable.swift | 24 -- Objective-C/ContentsquareTracker.swift | 438 ----------------------- 4 files changed, 583 deletions(-) delete mode 100644 Objective-C/ContentsquareCommand.swift delete mode 100644 Objective-C/ContentsquareConstants.swift delete mode 100644 Objective-C/ContentsquareTrackable.swift delete mode 100644 Objective-C/ContentsquareTracker.swift diff --git a/Objective-C/ContentsquareCommand.swift b/Objective-C/ContentsquareCommand.swift deleted file mode 100644 index 6f31bc8..0000000 --- a/Objective-C/ContentsquareCommand.swift +++ /dev/null @@ -1,79 +0,0 @@ -// -// ContentsquareRemoteCommand.swift -// TealiumContentsquare -// -// Created by Jonathan Wong on 3/6/20. -// Copyright © 2020 Jonathan Wong. All rights reserved. -// - -import Foundation -#if COCOAPODS -import TealiumSwift -#else -import TealiumCore -import TealiumTagManagement -import TealiumRemoteCommands -#endif - -public class ContentsquareCommand { - - let contentsquareTracker: - ContentsquareTrackable - - public init(contentsquareTracker: - ContentsquareTrackable) { - self.contentsquareTracker = - contentsquareTracker - } - - public func remoteCommand() -> TealiumRemoteCommand { - return TealiumRemoteCommand(commandId: "contentsquare", - description: "Contentsquare Remote Command") { response in - let payload = response.payload() - guard let command = payload[Contentsquare.Commands.commandKey] as? String else { - return - } - - let commands = command.split(separator: ",") - let formatted = commands.map { command in - return command.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines) - } - - self.parseCommands(formatted, payload: payload) - } - } - - func parseCommands(_ commands: [String], payload: [String: Any]) { - commands.forEach { command in - let lowercasedCommand = command.lowercased() - switch lowercasedCommand { - case Contentsquare.Commands.sendScreenView: - guard let screenName = payload[Contentsquare.ScreenView.screenName] as? String else { return } - contentsquareTracker.sendScreenView(screenName: screenName) - case Contentsquare.Commands.sendTransaction: - guard let options = payload[Contentsquare.TransactionProperties.transaction] as? [String: Any] else { - print("Contentsquare.TransactionProperties.transaction key is missing.") - return - } - guard let price: Double = options[Contentsquare.TransactionProperties.price] as? Double, - let currency: String = options[Contentsquare.TransactionProperties.currency] as? String else { return } - let transactionId: String? = options[Contentsquare.TransactionProperties.transactionId] as? String - contentsquareTracker.sendTransaction(price: price, currency: currency, transactionId: transactionId) - case Contentsquare.Commands.sendDynamicVar: - guard let dynamicVar = payload[Contentsquare.DynamicVar.dynamicVar] as? [String: Any] else { return } - contentsquareTracker.sendDynamicVar(dynamicVar: dynamicVar) - case Contentsquare.Commands.stopTracking: - contentsquareTracker.stopTracking() - case Contentsquare.Commands.resumeTracking: - contentsquareTracker.resumeTracking() - case Contentsquare.Commands.forgetMe: - contentsquareTracker.forgetMe() - case Contentsquare.Commands.optIn: - contentsquareTracker.optIn() - case Contentsquare.Commands.optOut: - contentsquareTracker.optOut() - default: break - } - } - } -} diff --git a/Objective-C/ContentsquareConstants.swift b/Objective-C/ContentsquareConstants.swift deleted file mode 100644 index 8b7a73f..0000000 --- a/Objective-C/ContentsquareConstants.swift +++ /dev/null @@ -1,42 +0,0 @@ -// -// ContentsquareConstants.swift -// TealiumContentsquare -// -// Created by Jonathan Wong on 3/4/20. -// Copyright © 2020 Jonathan Wong. All rights reserved. -// - -extension ContentsquareCommand { - enum Contentsquare { - - enum Commands { - static let commandKey = "command_name" - static let separator = "," - - static let sendScreenView = "sendscreenview" - static let sendTransaction = "sendtransaction" - static let sendDynamicVar = "senddynamicvar" - static let stopTracking = "stoptracking" - static let resumeTracking = "resumetracking" - static let forgetMe = "forgetme" - static let optIn = "optin" - static let optOut = "optout" - - } - - enum ScreenView { - static let screenName = "screen_name" - } - - enum TransactionProperties { - static let transaction = "transaction" - static let price = "price" // required - static let currency = "currency" // required - static let transactionId = "transaction_id" // optional - } - - enum DynamicVar { - static let dynamicVar = "dynamic_var" - } - } -} diff --git a/Objective-C/ContentsquareTrackable.swift b/Objective-C/ContentsquareTrackable.swift deleted file mode 100644 index 31c4f04..0000000 --- a/Objective-C/ContentsquareTrackable.swift +++ /dev/null @@ -1,24 +0,0 @@ -// -// ContentsquareTrackable.swift -// TealiumContentsquare -// -// Created by Jonathan Wong on 3/6/20. -// Copyright © 2020 Jonathan Wong. All rights reserved. -// - -import Foundation - -public protocol ContentsquareTrackable { - func sendScreenView(screenName: String) - - func sendTransaction(price: Double, currency: String, transactionId: String?) - - func sendDynamicVar(dynamicVar: [String: Any]) - - func stopTracking() - func resumeTracking() - func forgetMe() - func optIn() - func optOut() - -} diff --git a/Objective-C/ContentsquareTracker.swift b/Objective-C/ContentsquareTracker.swift deleted file mode 100644 index b9c1612..0000000 --- a/Objective-C/ContentsquareTracker.swift +++ /dev/null @@ -1,438 +0,0 @@ -// -// ContentsquareTracker.swift -// TealiumContentsquare -// -// Created by Jonathan Wong on 3/6/20. -// Copyright © 2020 Jonathan Wong. All rights reserved. -// - -import Foundation -import ContentsquareModule - -public class ContentsquareTracker: ContentsquareTrackable { - - public init() {} - - public func sendScreenView(screenName: String) { - Contentsquare.send(screenViewWithName: screenName) - } - - public func sendTransaction(price: Double, currency: String, transactionId: String?) { - guard let currency = CurrencyWrapper(rawValue: currency.lowercased())?.currency() else { - print("Error with currency value.") - return - } - let transaction = CustomerTransaction(id: transactionId, value: Float(price), currency: currency) - Contentsquare.send(transaction: transaction) - } - - public func sendDynamicVar(dynamicVar: [String: Any]) { - dynamicVar.forEach { key, value in - if let value = value as? String { - do { - let dynamicVar = try DynamicVar(key: key, value: value) - Contentsquare.send(dynamicVar: dynamicVar) - } catch { - print("Error with dynamic variable key: \(key), value: \(value), error: \(error)") - } - } else if let value = value as? UInt32 { - do { - let dynamicVar = try DynamicVar(key: key, value: value) - Contentsquare.send(dynamicVar: dynamicVar) - } catch { - print("Error with dynamic variable key: \(key), value: \(value), error: \(error)") - } - } else { - print("Incorrect format of value: \(value). Value should be String or UInt32.") - } - } - } - - public func stopTracking() { - Contentsquare.stopTracking() - } - - public func resumeTracking() { - Contentsquare.resumeTracking() - } - - public func forgetMe() { - Contentsquare.forgetMe() - } - - public func optIn() { - Contentsquare.optIn() - } - - public func optOut() { - Contentsquare.optOut() - } -} - -/// Maps to Contentsquare's Currency type -public enum CurrencyWrapper: String, Codable { - case mop - case bmd - case kes - case bnd - case iqd - case sdg - case zmw - case xts - case top - case xsu - case svc - case ils - case dzd - case nad - case mxv - case sos - case cad - case sek - case hkd - case zwl - case egp - case clp - case cuc - case lyd - case rsd - case cou - case cve - case khr - case gyd - case mkd - case tmt - case ugx - case kgs - case ves - case ssp - case npr - case sbd - case xpf - case aud - case bhd - case mwk - case mxn - case nio - case lsl - case xxx - case zar - case aoa - case gmd - case gip - case mvr - case kwd - case pln - case mga - case uah - case huf - case rub - case vnd - case lak - case rwf - case syp - case xag - case mur - case wst - case xpd - case gbp - case etb - case isk - case cdf - case usd - case tjs - case cup - case bgn - case eur - case cny - case cop - case gnf - case bbd - case xua - case chw - case xcd - case lrd - case pen - case pkr - case pyg - case lkr - case ron - case uzs - case nzd - case idr - case ern - case czk - case jod - case awg - case irr - case tzs - case brl - case ngn - case che - case chf - case bdt - case thb - case xdr - case mad - case gel - case fkp - case azn - case pab - case twd - case aed - case htg - case xbd - case lbp - case amd - case php - case xpt - case inr - case bwp - case myr - case mnt - case srd - case sll - case uyu - case bam - case bif - case bov - case jmd - case omr - case uyw - case bzd - case nok - case kmf - case kpw - case scr - case jpy - case xof - case shp - case sgd - case dkk - case uyi - case yer - case ang - case ttd - case xbb - case xbc - case fjd - case dop - case byn - case kzt - case xba - case szl - case sar - case gtq - case pgk - case ars - case btn - case afn - case djf - case mdl - case ghs - case qar - case `try` - case mmk - case xaf - case vuv - case xau - case clf - case hrk - case bob - case krw - case bsd - case all - case mru - case hnl - case stn - case usn - case mzn - case tnd - case crc - case kyd - - func currency() -> Currency { - switch self { - case .mop: return .mop - case .bmd: return .bmd - case .kes: return .kes - case .bnd: return .bnd - case .iqd: return .iqd - case .sdg: return .sdg - case .zmw: return .zmw - case .xts: return .xts - case .top: return .top - case .xsu: return .xsu - case .svc: return .svc - case .ils: return .ils - case .dzd: return .dzd - case .nad: return .nad - case .mxv: return .mxv - case .sos: return .sos - case .cad: return .cad - case .sek: return .sek - case .hkd: return .hkd - case .zwl: return .zwl - case .egp: return .egp - case .clp: return .clp - case .cuc: return .cuc - case .lyd: return .lyd - case .rsd: return .rsd - case .cou: return .cou - case .cve: return .cve - case .khr: return .khr - case .gyd: return .gyd - case .mkd: return .mkd - case .tmt: return .tmt - case .ugx: return .ugx - case .kgs: return .kgs - case .ves: return .ves - case .ssp: return .ssp - case .npr: return .npr - case .sbd: return .sbd - case .xpf: return .xpf - case .aud: return .aud - case .bhd: return .bhd - case .mwk: return .mwk - case .mxn: return .mxn - case .nio: return .nio - case .lsl: return .lsl - case .xxx: return .xxx - case .zar: return .zar - case .aoa: return .aoa - case .gmd: return .gmd - case .gip: return .gip - case .mvr: return .mvr - case .kwd: return .kwd - case .pln: return .pln - case .mga: return .mga - case .uah: return .uah - case .huf: return .huf - case .rub: return .rub - case .vnd: return .vnd - case .lak: return .lak - case .rwf: return .rwf - case .syp: return .syp - case .xag: return .xag - case .mur: return .mur - case .wst: return .wst - case .xpd: return .xpd - case .gbp: return .gbp - case .etb: return .etb - case .isk: return .isk - case .cdf: return .cdf - case .usd: return .usd - case .tjs: return .tjs - case .cup: return .cup - case .bgn: return .bgn - case .eur: return .eur - case .cny: return .cny - case .cop: return .cop - case .gnf: return .gnf - case .bbd: return .bbd - case .xua: return .xua - case .chw: return .chw - case .xcd: return .xcd - case .lrd: return .lrd - case .pen: return .pen - case .pkr: return .pkr - case .pyg: return .pyg - case .lkr: return .lkr - case .ron: return .ron - case .uzs: return .uzs - case .nzd: return .nzd - case .idr: return .idr - case .ern: return .ern - case .czk: return .czk - case .jod: return .jod - case .awg: return .awg - case .irr: return .irr - case .tzs: return .tzs - case .brl: return .brl - case .ngn: return .ngn - case .che: return .che - case .chf: return .chf - case .bdt: return .bdt - case .thb: return .thb - case .xdr: return .xdr - case .mad: return .mad - case .gel: return .gel - case .fkp: return .fkp - case .azn: return .azn - case .pab: return .pab - case .twd: return .twd - case .aed: return .aed - case .htg: return .htg - case .xbd: return .xbd - case .lbp: return .lbp - case .amd: return .amd - case .php: return .php - case .xpt: return .xpt - case .inr: return .inr - case .bwp: return .bwp - case .myr: return .myr - case .mnt: return .mnt - case .srd: return .srd - case .sll: return .sll - case .uyu: return .uyu - case .bam: return .bam - case .bif: return .bif - case .bov: return .bov - case .jmd: return .jmd - case .omr: return .omr - case .uyw: return .uyw - case .bzd: return .bzd - case .nok: return .nok - case .kmf: return .kmf - case .kpw: return .kpw - case .scr: return .scr - case .jpy: return .jpy - case .xof: return .xof - case .shp: return .shp - case .sgd: return .sgd - case .dkk: return .dkk - case .uyi: return .uyi - case .yer: return .yer - case .ang: return .ang - case .ttd: return .ttd - case .xbb: return .xbb - case .xbc: return .xbc - case .fjd: return .fjd - case .dop: return .dop - case .byn: return .byn - case .kzt: return .kzt - case .xba: return .xba - case .szl: return .szl - case .sar: return .sar - case .gtq: return .gtq - case .pgk: return .pgk - case .ars: return .ars - case .btn: return .btn - case .afn: return .afn - case .djf: return .djf - case .mdl: return .mdl - case .ghs: return .ghs - case .qar: return .qar - case .`try`: return .`try` - case .mmk: return .mmk - case .xaf: return .xaf - case .vuv: return .vuv - case .xau: return .xau - case .clf: return .clf - case .hrk: return .hrk - case .bob: return .bob - case .krw: return .krw - case .bsd: return .bsd - case .all: return .all - case .mru: return .mru - case .hnl: return .hnl - case .stn: return .stn - case .usn: return .usn - case .mzn: return .mzn - case .tnd: return .tnd - case .crc: return .crc - case .kyd: return .kyd - } - - } -} From cc22021dfcb6e102fdb6d30d9150ad475ae15563 Mon Sep 17 00:00:00 2001 From: Christina Date: Tue, 20 Oct 2020 16:12:21 -0700 Subject: [PATCH 08/10] Remove Cartfile.resolved --- Cartfile.resolved | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 Cartfile.resolved diff --git a/Cartfile.resolved b/Cartfile.resolved deleted file mode 100644 index a292ba2..0000000 --- a/Cartfile.resolved +++ /dev/null @@ -1,2 +0,0 @@ -git "file:///Users/christina/Projects/work-repos/github/tealium-swift-builder" "388d0ac6726fd110a03c48ad14cdfa8ae87706e1" -github "ContentSquare/CS_iOS_SDK" "v3.2.1" From 9f8053da40dc3f4bec94523fedc36353dac0b430 Mon Sep 17 00:00:00 2001 From: Christina Date: Tue, 20 Oct 2020 17:16:57 -0700 Subject: [PATCH 09/10] Update podspec --- TealiumContentsquare.podspec | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/TealiumContentsquare.podspec b/TealiumContentsquare.podspec index f95ff35..9df2199 100644 --- a/TealiumContentsquare.podspec +++ b/TealiumContentsquare.podspec @@ -22,7 +22,11 @@ Pod::Spec.new do |s| # ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― # s.swift_version = "5.1" s.platform = :ios, "10.0" - s.ios.deployment_target = "10.0" + s.ios.deployment_target = "10.0" + + # ――― Excluded Archs ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # + s.user_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' } + s.pod_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' } # ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # s.source = { :git => "https://github.com/Tealium/tealium-ios-contentsquare-remote-command.git", :tag => "#{s.version}" } From a16e1dab9011dd6224feaa1e758cf21e1b42d6b2 Mon Sep 17 00:00:00 2001 From: Christina Date: Wed, 21 Oct 2020 10:56:46 -0700 Subject: [PATCH 10/10] Update to weakSelf --- Sources/ContentsquareRemoteCommand.swift | 6 +++--- TealiumContentsquareExample/Podfile.lock | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/ContentsquareRemoteCommand.swift b/Sources/ContentsquareRemoteCommand.swift index 662def1..986184c 100644 --- a/Sources/ContentsquareRemoteCommand.swift +++ b/Sources/ContentsquareRemoteCommand.swift @@ -21,7 +21,7 @@ public class ContentsquareRemoteCommand: RemoteCommand { public init(contentsquareInstance: ContentsquareCommand = ContentsquareInstance(), type: RemoteCommandType = .webview) { self.contentsquareInstance = contentsquareInstance - weak var selfWorkaround: ContentsquareRemoteCommand? + weak var weakSelf: ContentsquareRemoteCommand? super.init(commandId: Contentsquare.commandId, description: Contentsquare.description, type: type, @@ -29,9 +29,9 @@ public class ContentsquareRemoteCommand: RemoteCommand { guard let payload = response.payload else { return } - selfWorkaround?.processRemoteCommand(with: payload) + weakSelf?.processRemoteCommand(with: payload) }) - selfWorkaround = self + weakSelf = self } func processRemoteCommand(with payload: [String: Any]) { diff --git a/TealiumContentsquareExample/Podfile.lock b/TealiumContentsquareExample/Podfile.lock index ed7db78..746ac40 100644 --- a/TealiumContentsquareExample/Podfile.lock +++ b/TealiumContentsquareExample/Podfile.lock @@ -26,7 +26,7 @@ EXTERNAL SOURCES: SPEC CHECKSUMS: CS_iOS_SDK: d4ab9a1fd87e8254ce888724cb56256362fe0c1a tealium-swift: a670c2c6f3e7e5d775d9507387e8858a8541e526 - TealiumContentsquare: 3177c797b0a8b001e1b211122b7728db05a8b481 + TealiumContentsquare: 25672334d89d7201f9aee4825c5304c475ae30e9 PODFILE CHECKSUM: 484e8e2d3515241393ce3d9ae9ded5e340792e49