Skip to content

Commit

Permalink
Sample app updates and finalize remote command (#5)
Browse files Browse the repository at this point in the history
* Sample app updates and finalize remote command

* review feedback

* update objective c files

Co-authored-by: Christina <[email protected]>
  • Loading branch information
christinasund and Christina authored Jun 5, 2020
1 parent 1bae798 commit 3a6d1bb
Show file tree
Hide file tree
Showing 36 changed files with 520 additions and 697 deletions.
31 changes: 15 additions & 16 deletions Objective-C/AppsFlyerCommandTracker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,55 +76,55 @@ public class AppsFlyerCommandTracker: NSObject, AppsFlyerTrackable, TealiumRegis
}

public func trackEvent(_ eventName: String, values: [String: Any]) {
AppsFlyerTracker.shared()?.trackEvent(eventName, withValues: values)
AppsFlyerTracker.shared().trackEvent(eventName, withValues: values)
}

public func trackLocation(longitude: Double, latitude: Double) {
AppsFlyerTracker.shared()?.trackLocation(longitude, latitude: latitude)
AppsFlyerTracker.shared().trackLocation(longitude, latitude: latitude)
}

/// Used to track push notification activity from native APNs or other push service
/// Please refer to this for more information:
/// https://support.appsflyer.com/hc/en-us/articles/207364076-Measuring-Push-Notification-Re-Engagement-Campaigns
public func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
AppsFlyerTracker.shared()?.handlePushNotification(userInfo)
AppsFlyerTracker.shared()?.trackEvent(AppsFlyerConstants.Events.pushNotificationOpened, withValues: [:])
AppsFlyerTracker.shared().handlePushNotification(userInfo)
AppsFlyerTracker.shared().trackEvent(AppsFlyerConstants.Events.pushNotificationOpened, withValues: [:])
}

public func handlePushNofification(payload: [String: Any]?) {
AppsFlyerTracker.shared()?.handlePushNotification(payload)
AppsFlyerTracker.shared().handlePushNotification(payload)
}

public func setHost(_ host: String, with prefix: String) {
AppsFlyerTracker.shared()?.setHost(host, withHostPrefix: prefix)
AppsFlyerTracker.shared().setHost(host, withHostPrefix: prefix)
}

public func setUserEmails(emails: [String], with cryptType: Int) {
AppsFlyerTracker.shared()?.setUserEmails(emails, with: EmailCryptType(rawValue: EmailCryptType.RawValue(cryptType)))
AppsFlyerTracker.shared().setUserEmails(emails, with: EmailCryptType(rawValue: EmailCryptType.RawValue(cryptType)))
}

public func currencyCode(_ currency: String) {
AppsFlyerTracker.shared()?.currencyCode = currency
AppsFlyerTracker.shared().currencyCode = currency
}

public func customerId(_ id: String) {
AppsFlyerTracker.shared()?.customerUserID = id
AppsFlyerTracker.shared().customerUserID = id
}

public func disableTracking(_ disable: Bool) {
AppsFlyerTracker.shared()?.isStopTracking = disable
AppsFlyerTracker.shared().isStopTracking = disable
}

/// APNs and Push Messaging must be configured in order to track installs.
/// Apple will not register the uninstall until 8 days after the user removes the app.
/// Instructions to set up: https://support.appsflyer.com/hc/en-us/articles/210289286-Uninstall-Measurement#iOS-Uninstall
public func registerPushToken(_ token: String) {
guard let dataToken = token.data(using: .utf8) else { return }
AppsFlyerTracker.shared()?.registerUninstall(dataToken)
AppsFlyerTracker.shared().registerUninstall(dataToken)
}

public func resolveDeepLinkURLs(_ urls: [String]) {
AppsFlyerTracker.shared()?.resolveDeepLinkURLs = urls
AppsFlyerTracker.shared().resolveDeepLinkURLs = urls
}

}
Expand All @@ -140,7 +140,7 @@ extension AppsFlyerCommandTracker: AppsFlyerTrackerDelegate {
return
}
guard firstLaunch else {
print("AppsFlyer Attribution: Not First Launch")
print("\(AppsFlyerConstants.attributionLog)Not First Launch")
return
}
tealium.trackEvent(withTitle: AppsFlyerConstants.Attribution.conversionReceived,
Expand All @@ -149,14 +149,13 @@ extension AppsFlyerCommandTracker: AppsFlyerTrackerDelegate {
guard let status = conversionInfo[AppsFlyerConstants.Attribution.status] as? String else {
return
}

if (status == "Non-organic") {
if let mediaSource = conversionInfo[AppsFlyerConstants.Attribution.source],
let campaign = conversionInfo[AppsFlyerConstants.Attribution.campaign] {
print("AppsFlyer Attribution: This is a Non-Organic install. Media source: \(mediaSource) Campaign: \(campaign)")
print("\(AppsFlyerConstants.attributionLog)This is a Non-Organic install. Media source: \(mediaSource) Campaign: \(campaign)")
}
} else {
print("AppsFlyer Attribution: This is an organic install.")
print("\(AppsFlyerConstants.attributionLog)This is an organic install.")
}
}

Expand Down
46 changes: 21 additions & 25 deletions Objective-C/AppsFlyerConstants.swift
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
//
// AppsFlyerConstants.swift
// AppsFlyerRemoteCommand
// TealiumAppsFlyer
//
// Created by Christina Sund on 5/29/19.
// Copyright © 2019 Christina. All rights reserved.
// Created by Christina S on 5/29/19.
// Copyright © 2019 Tealium. All rights reserved.
//

import Foundation

public enum AppsFlyerConstants {

static let commandName = "command_name"
static let separator: Character = ","
static let errorPrefix = "AppsFlyer Error: "
static let attributionLog = "AppsFlyer Attribution: "

/// Standard AppsFlyer events: https://support.appsflyer.com/hc/en-us/articles/115005544169#Event-Types
public enum EventCommandNames: String, CaseIterable {
case achievelevel
Expand Down Expand Up @@ -39,21 +44,20 @@ public enum AppsFlyerConstants {
case customersegment
}

/// Other events/methods
public enum CommandNames {
static let launch = "launch"
static let initialize = "initialize"
static let inAppPurchase = "inapppurchase"
static let trackLocation = "tracklocation"
static let setHost = "sethost"
static let setUserEmails = "setuseremails"
static let setCurrencyCode = "setcurrencycode"
static let setCustomerId = "setcustomerid"
static let disableTracking = "disabletracking"
static let resolveDeepLinkUrls = "resolvedeeplinkurls"
public enum CommandNames: String {
case launch = "launch"
case initialize = "initialize"
case trackLocation = "tracklocation"
case setHost = "sethost"
case setUserEmails = "setuseremails"
case setCurrencyCode = "setcurrencycode"
case setCustomerId = "setcustomerid"
case disableTracking = "disabletracking"
case resolveDeepLinkUrls = "resolvedeeplinkurls"
}

public enum Configuration {
static let appId = "app_id"
static let appDevKey = "app_dev_key"
static let debug = "debug"
static let disableAdTracking = "disable_ad_tracking"
Expand All @@ -62,12 +66,9 @@ public enum AppsFlyerConstants {
static let anonymizeUser = "anonymize_user"
static let collectDeviceName = "collect_device_name"
static let customData = "custom_data"
static let config = "config"
static let settings = "settings"
}

/// These parameters are available to send with events and commands
/// For more information about what to send with a particular event,
/// please refer to this document: https://support.appsflyer.com/hc/en-us/articles/115005544169#Event-Types
public enum Parameters {
static let latitude = "af_lat"
static let longitude = "af_long"
Expand Down Expand Up @@ -110,13 +111,12 @@ public enum AppsFlyerConstants {
static let customerSegment = "af_customer_segment"
static let pushNotificationOpened = "af_opened_from_push_notification"
}

public enum Attribution {
static let appOpen = "app_open_attribution"
static let appOpenFailure = "app_open_attribution_failure"
static let firstLaunch = "is_first_launch"
static let conversionReceived = "conversion_data_received"
static let conversionError = "appsflyer_error"
static let conversionFailure = "conversion_data_failure"
static let errorName = "error_name"
static let errorDescription = "error_description"
Expand All @@ -126,8 +126,4 @@ public enum AppsFlyerConstants {
static let error = "appsflyer_error"
}

static let commandName = "command_name"
static let apiKey = "api_key"
static let appId = "app_id"

}
Loading

0 comments on commit 3a6d1bb

Please sign in to comment.