Skip to content

Instantly share code, notes, and snippets.

View kuyazee's full-sized avatar
:octocat:
Learning every day

Zonily Jame kuyazee

:octocat:
Learning every day
View GitHub Profile
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
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)
}
/// 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
}
}
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"
public protocol AnalyticsEventProtocol {
...
/// The list of the AnalyticsEventProtocol conforming types that will track an event.
var isTrackedOnAnalyticsServices: [AnalyticsServiceProtocol.Type] { get }
}
extension AnalyticsEventProtocol {
...
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() {}
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)
}
}
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)
...
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"
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}/"