This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public protocol AnalyticsEventProtocol { | |
/// This is the identifier | |
var name: String { get } | |
/// the dictionary that will be sent to the SDK | |
var parameters: [String: Any]? { get } | |
} | |
extension AnalyticsEventProtocol { | |
// Default Implementation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public protocol AnalyticsServiceProtocol { | |
/// This will be called within AppDelegate application:didFinishLaunchingWithOptions: method | |
/// In this method, you should initialize the SDK. | |
func initialize(application: UIApplication, launchOptions: [UIApplicationLaunchOptionsKey: Any]?) | |
/// This will actually track events in the app. | |
func send(event: AnalyticsEventProtocol) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// The list of events using an Enum | |
enum AnalyticsEvent: String, AnalyticsEventProtocol { | |
case userLoggedIn = "User Logged In" | |
case userLoggedOut = "User Logged Out" | |
var name: String { | |
return self.rawValue | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public enum AnalyticsEvent: AnalyticsEventProtocol { | |
case userLoggedIn | |
case userLoggedOut | |
case productSelected(productId: Int) | |
var name: String { | |
switch self { | |
case .userLoggedIn: return "User Logged In" | |
case .userLoggedOut: return "User Logged Out" | |
case .productSelected: return "Product Selected" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public protocol AnalyticsEventProtocol { | |
... | |
/// The list of the AnalyticsEventProtocol conforming types that will track an event. | |
var isTrackedOnAnalyticsServices: [AnalyticsServiceProtocol.Type] { get } | |
} | |
extension AnalyticsEventProtocol { | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final class AnalyticsManagerService: AnalyticsServiceProtocol { | |
/// This will hold a strong reference to the other services | |
/// while still having the implementations encapsulated | |
fileprivate private(set) var services: [AnalyticsServiceProtocol] = [] | |
/// A singleton, for ease of access | |
static let shared: AnalyticsManagerService = AnalyticsManagerService() | |
/// A hidden init so this class cannot be reinstantiated anywhere else | |
fileprivate init() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FabricAnalyticsService: AnalyticsServiceProtocol { | |
func initialize(application: UIApplication, launchOptions: [UIApplicationLaunchOptionsKey : Any]?) { | |
Fabric.with([Answers.self]) | |
} | |
func send(event: AnalyticsEventProtocol) { | |
Answers.logCustomEvent(withName: event.name, customAttributes: event.parameters) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { | |
... | |
// Add our services | |
AnalyticsManagerService.shared.add(service: FacebookAnalyticsService()) | |
AnalyticsManagerService.shared.add(service: FabricAnalyticsService()) | |
// Initialize the analytics | |
AnalyticsManagerService.shared.initialize(application: application: launchOptions: launchOptions) | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public enum AnalyticsEvent: AnalyticsEventProtocol { | |
case userLoggedIn | |
case userLoggedOut | |
case productSelected(productId: Int) | |
var name: String { | |
switch self { | |
case .userLoggedIn: return "User Logged In" | |
case .userLoggedOut: return "User Logged Out" | |
case .productSelected: return "Product Selected" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RESOURCE_PATH=${SRCROOT}/GoogleService-Info/${CONFIGURATION} | |
BUILD_APP_DIR=${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app | |
echo "Copying all files under ${RESOURCE_PATH} to ${BUILD_APP_DIR}" | |
cp -v "${RESOURCE_PATH}/"* "${BUILD_APP_DIR}/" |
OlderNewer