SDK Version: 4.8.11 (Release notes)
1. Garis Besar
Panduan ini menjelaskan cara pengintegrasian SDK AppsFlyer ke aplikasi iOS. Anda dapat melacak instalasi, pembaruan, sesi, dan event dalam-aplikasi tambahan serta instalasi aplikasi (termasuk pembelian dalam-aplikasi, tingkat permainan, dll.) untuk mengevaluasi tingkat pulangan (ROI) dan tingkat interaksi pengguna. SDK iOS kompatibel dengan semua perangkat iOS (iPhone, iPod, iPad) dengan iOS versi 6 dan di atasnya.
Catatan
SDK AppsFlyer sepenuhnya mematuhi Jaringan IPv6 DNS64/NAT64 milik Apple. Untuk informasi lebih lanjut, klik di sini.
Important!
SDK AppsFlyer memanfaatkan kelas NSUserDefaults. Menghapus semua data dari NSUserDefaults dapat menyebabkan masalah atribusi.
2. Mulai
2.1 Mengunduh dan menambahkan SDK AppsFlyer ke Xcode
- Pastikan Anda telah mengunduh dan menginstal CocoaPods versi terbaru.
- Add the following row to your
Podfile
:pod 'AppsFlyerFramework'
- jalankan
pod install
- Pastikan Anda menggunakan file
.xcworkspace
untuk membuka proyek dalam Xcode, bukan menggunakan file.xcodeproj
mulai sekarang.
- Pastikan Anda telah menginstal Carthage versi terbaru.
- Tambahkan baris berikut ke Cartfile Anda:
- github "AppsFlyerSDK/AppsFlyerFramework"
Catatan
Pendekatan ini hanya kompatibel dengan iOS 8 dan di atasnya.
- Unduh SDK iOS sebagai framework statis.
- Unzip file AppsFlyerLib.framework.zip yang baru saja diunduh
- Geser AppsFlyerLib.framework dan jatuhkan file ke proyek Xcode
- Pastikan Salin item jika diperlukan tercentang.
- Tambahkan file AdSupport.framework dan iAd.framework ke proyek Anda dan atur sebagai Opsional.
Catatan
Pendekatan ini hanya disarankan jika Anda ingin mendukung iOS 7 di aplikasi Anda.
- Unduh SDK iOS sebagai pustaka statis.
- Unzip file yang Anda unduh
- Geser & jatuhkan file AppsFlyerTracker.h dan libAppsFlyerLib.a ke proyek Xcode Anda
- Pastikan Salin item jika diperlukan tercentang.
- Tambahkan file AdSupport.framework dan iAd.framework ke proyek Anda dan atur sebagai Opsional.
SDK AppsFlyer menggunakan framework asli berikut:
- AdSupport.framework
- This framework is required to collect the IDFA from devices.
Without IDFA you cannot track Facebook Ads, Twitter, Google ads and other networks. - iAd.framework
- Framework ini diperlukan untuk melacak Iklan Pencarian Apple di aplikasi Anda
2.2 Mengonfigurasi Integrasi di dalam Delegasi Aplikasi
Buka file AppDelegate.m aplikasi Anda dan impor SDK AppsFlyer:
import AppsFlyerLib
#import <AppsFlyerLib/AppsFlyerTracker.h>
AppsFlyerTracker.shared().appsFlyerDevKey = "<your-appsflyer-dev-key>";
AppsFlyerTracker.shared().appleAppID = "123456789"
AppsFlyerTracker.shared().delegate = self
#ifdef DEBUG
AppsFlyerTracker.shared().isDebug = true
#endif
[AppsFlyerTracker sharedTracker].appsFlyerDevKey = @"<your-appsflyer-dev-key>";
[AppsFlyerTracker sharedTracker].appleAppID = @"123456789";
[AppsFlyerTracker sharedTracker].delegate = self;
#ifdef DEBUG
[AppsFlyerTracker sharedTracker].isDebug = true;
#endif
Catatan
Log SDK AppsFlyer akan ditampilkan di Konsol xCode jika isDebug=true
telah diatur
- Tambahkan kode berikut pada fungsi
applicationDidBecomeActive
:
func applicationDidBecomeActive(application: UIApplication) {
// Track Installs, updates & sessions(app opens) (You must include this API to enable tracking)
AppsFlyerTracker.shared().trackAppLaunch()
// your other code here.... }
- (void)applicationDidBecomeActive:(UIApplication *)application {
// Track Installs, updates & sessions(app opens) (You must include this API to enable tracking)
[[AppsFlyerTracker sharedTracker] trackAppLaunch];
// your other code here.... }
4. Melacak Event Dalam-Aplikasi
Event Dalam-Aplikasi memberikan informasi tentang hal yang terjadi dalam aplikasi Anda. Sebaiknya luangkan waktu dan tentukan event yang ingin Anda ukur agar Anda dapat melacak ROI (Return on Investment) dan LTV (Lifetime Value).
Melacak event dalam-aplikasi dilakukan dengan cara memanggil trackEvent
bersama nama event dan parameternya. Lihat Event Dalam-Aplikasi untuk informasi lebih lanjut.
Nama event dalam-aplikasi tidak boleh lebih dari 45 karakter. Nama Event yang melebihi 45 karakter tidak muncul di dashboard, namun hanya tertera di laporan data lengkap, API Pull dan API Push.
Contoh: Event Level Tercapai
AppsFlyerTracker.shared().trackEvent(AFEventLevelAchieved, withValues: [
AFEventParamLevel: 9,
AFEventParamScore : 100
]);
[[AppsFlyerTracker sharedTracker] trackEvent: AFEventLevelAchieved withValues:@{
AFEventParamLevel: @9,
AFEventParamScore : @100
}];
Ini akan menghasilkan nama event af_level_achieved
(menggunakan konstanta AFEventLevelAchieved
) dengan parameter event berikut: {af_level: 9 , af_score: 100}
Catatan
AppsFlyer supports non-English characters with in-app events, or with any other SDK API, starting from iOS SDK version 4.8.1.
5. Melacak Deep Linking
Tips
Kami sangat menyarankan Deep Linking terintegrasi dalam aplikasi Anda.
iOS 9 dan di atasnya memerlukan aplikasi yang mendukung Universal Links. Untuk informasi lebih lanjut, klik di sini.
To report such launches, add the following code to the app delegate:
// Laporan aplikasi dibuka dari tautan Universal untuk iOS 9 atau yang lebih baru
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
AppsFlyerTracker.shared().continue(userActivity, restorationHandler: restorationHandler)
return true
}
// Laporan Aplikasi dibuka dari tautan langsung dari aplikasi yang tidak mendukung Tautan Universal (Twitter) dan untuk iOS 8 dan di bawahnya
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
AppsFlyerTracker.shared().handleOpen(url, sourceApplication: sourceApplication, withAnnotation: annotation)
return true
}
// Laporan aplikasi dibuka dari tautan langsung untuk iOS 10 dan yang lebih baru
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
AppsFlyerTracker.shared().handleOpen(url, options: options)
return true
}
// Laporan aplikasi dibuka dari Tautan Universal untuk iOS 9 dan di atasnya
- (BOOL) application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray *_Nullable))restorationHandler {
[[AppsFlyerTracker sharedTracker] continueUserActivity:userActivity restorationHandler:restorationHandler];
return YES;
}
// Laporan aplikasi dibuka dari tautan langsung dari aplikasi yang tidak mendukung Tautan Universal (Twitter) dan untuk iOS 8 dan di bawahnya
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString*)sourceApplication annotation:(id)annotation {
[[AppsFlyerTracker sharedTracker] handleOpenURL:url sourceApplication:sourceApplication withAnnotation:annotation];
return YES;
}
// Laporan aplikasi dibuka dari tautan langsung untuk iOS 10
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
options:(NSDictionary *) options {
[[AppsFlyerTracker sharedTracker] handleOpenUrl:url options:options];
return YES;
}
6. Melacak Pendapatan
Use the af_revenue
(AFInAppEventParameterName.REVENUE
) event parameter to count revenue as part of an in-app event. You can populate it with any numeric value, positive or negative.
Catatan
AFEventParamRevenue
(sama dengan penggunaan af_revenue
) adalah SATU-SATUNYA parameter event yang dihitung oleh AppsFlyer sebagai pendapatan pada laporan data lengkap dan dashboard. Untuk informasi lebih lanjut klik di sini.
Example: Revenue In-App Event
AppsFlyerTracker.shared().trackEvent(AFEventPurchase, withValues: [
AFEventParamContentId:"1234567",
AFEventParamContentType : "category_a",
AFEventParamRevenue: 1.99,
AFEventParamCurrency:"USD"
]);
[[AppsFlyerTracker sharedTracker] trackEvent: AFEventPurchase withValues:@{
AFEventParamContentId:@"1234567",
AFEventParamContentType : @"category_a",
AFEventParamRevenue: @1.99,
AFEventParamCurrency:@"USD"
}];
7. Memperoleh Data Konversi
AppsFlyer memungkinkan Anda untuk mengakses data atribusi pengguna secara aktual untuk setiap instalasi baru, langsung dari SDK AppsFlyer. Dengan cara ini, Anda dapat melayani pengguna dengan menyajikan konten yang personal atau mengirimkan mereka ke halaman tertentu dalam aplikasi, yang secara signifikan dapat meningkatkan interaksi pengguna dengan aplikasi Anda.
Untuk informasi lebih lanjut tentang fungsi ini, klik di sini.
8. Pengidentifikasi Pengguna
Ada beberapa pilihan untuk memperoleh pengidentifikasi pengguna:
Memperoleh AppsFlyer Device ID
AppsFlyer Device ID dibuat untuk setiap instalasi aplikasi baru. Anda dapat memperolehnya dengan menggunakan kode berikut:
let appsflyerId = AppsFlyerTracker.shared().getAppsFlyerUID()
NSString *appsflyerId = [AppsFlyerTracker sharedTracker].getAppsFlyerUID;
Mengatur ID Pengguna Pelanggan
Dengan mengatur ID pelanggan Anda sendiri, Anda dapat membandingkan ID pelanggan Anda dengan ID unik AppsFlyer dan ID perangkat lainnya. ID ini tersedia di laporan data lengkap AppsFlyer bersama dengan API Postback untuk memandingkan dengan ID internal Anda.
Cara mengatur ID Pengguna Pelanggan Anda:
AppsFlyerTracker.shared().customerUserID = "my user id"
[AppsFlyerTracker sharedTracker].customerUserID = @"my user id";
Catatan Penting
The customerUserID
SHOULD be set before the trackAppLaunch. It is recommended to set your Customer User ID as soon as possible as it is only associated to events reported after its setup. Customer User ID can also be used to complete integrations with Analytics platforms such as Mixpanel and Swrve.
For more information about the Customer User ID, click here.
Mengatur Email Pengguna
AppsFlyer memungkinkan Anda untuk melaporkan satu atau lebih alamat email pengguna, jika Anda mengumpulkan data tersebut di dalam aplikasi Anda. Nilai email dapat dienkripsikan dengan menggunakan metode enkripsi berikut: Sha1, MD5, dan plain.
Contoh: Mengumpulkan Email Pengguna
AppsFlyerTracker.shared().setUserEmails( ["email1@domain.com", "email2@domain.com"], dengan: EmailCryptTypeSHA1)
Catatan
Informasi Personal yang didapatkan (PII) seperti alamat email tidak disimpan oleh AppsFlyer dan informasi ini tidak ditampilkan pada laporan mana pun. Tujuan pengumpulan informasi ini adalah postback ke sumber media instalasi.
IDFA dan IDFV
AppsFlyer secara otomatis mengumpulkan IDFA (ID Untuk Pengiklan) dan IDFV (ID Untuk Vendor) jika AdSupport.framework dimuat di aplikasi.
9. Fitur Pilihan
Mengukur Pelepasan Instalasi
Untuk Mengukur Pelepasan Instalasi, aktifkan remote push notification di aplikasi Anda. Lihat Panduan Pemrograman Pemberitahuan Remote dari Apple untuk informasi lebih lanjut.
Ikuti instruksi integrasi SDK iOS untuk menyelesaikan pengaturan fitur pelepasan instalasi.
Melacak Push Notification
Untuk mengaktifkan Pengukuran aplikasi dibuka dari push notification, tambahkan kode berikut ke delegasi aplikasi:
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {
AppsFlyerTracker.shared().handlePushNotification(userInfo)
}
-(void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
[[AppsFlyerTracker sharedTracker] handlePushNotification:userInfo];
}
Push Notification harus memiliki parameter af
dengan parameter pelacakan AppsFlyer.
Contoh Pesan:
{
"aps": {
"alert": "Push text",
"sound": "default",
"category": "REMINDER_CATEGORY"
},
"_p": 123456,
"payloadKey": "payloadValue"
"af": {
"pid": "swrve_int",
"is_retargeting": true,
"c": "test_campaign"
}
}
Pelacakan Promosi Silang
AppsFlyer memungkinkan Anda untuk mengukur dan mengatribusi instalasi yang berasal dari promosi silang antar aplikasi Anda dari dalam aplikasi yang saat ini dimiliki oleh pengguna. Aplikasi promosi silang dapat menjadi faktor pertumbuhan utama dalam mendorong instalasi tambahan untuk aplikasi Anda.
Untuk informasi lebih lanjut, lihat artikel Pelacakan Promosi Silang, di sini.
Pelacakan Undangan Pengguna
Mengatur Kode Mata Uang
Nilai default adalah USD. Anda dapat melihat kode mata uang ISO yang dapat diterima di sini.
Gunakan API berikut untuk mengatur kode mata uang:
public void currencyCode(String currencyCode);
Contoh Penggunaan:
AppsFlyerTracker.shared().currencyCode = "USD"
[AppsFlyerTracker sharedTracker].currencyCode = @"USD";
Validasi Pembelian Dalam-Aplikasi
Catatan
Fungsi ini didukung untuk iOS 7 dan di atasnya.
AppsFlyer’s SDK can provide in‐app purchase server verification. To set receipt validation tracking you need to call the validateAndTrackInAppPurchase method inside the SKStoreKit’s completeTransaction: callback. This call automatically generates an af_purchase in‐app event.
- (void) validateAndTrackInAppPurchase:(NSString *) productIdentifier
price:(NSString *) price
currency:(NSString *) currency
transactionId:(NSString *) tranactionId
additionalParameters:(NSDictionary *) params
success:(void (^)(NSDictionary *response)) successBlock
failure:(void (^)(NSError *error, id reponse)) failedBlock;
Catatan
Parameter harga harus berisi total pendapatan yang terkait dengan event pembelian tervalidasi.
This call has two callback blocks, one for ‘success’ and one for ‘failure’ (for any reason, including validation fail). On success, a dictionary is returned with the receipt validation data provided by Apple’s servers.
Penting
Untuk tujuan pengujian, kami menyarankan pengaturan bendera useReceiptValidationSandbox ke YES, karena ini akan mengarahkan permintaan ke server sandbox Apple.
#ifdef DEBUG
[AppsFlyerTracker sharedTracker].useReceiptValidationSandbox = YES;
#endif
Contoh
[[AppsFlyerTracker sharedTracker] validateAndTrackInAppPurchase:product.productIdentifier price:product.price.stringValue
currency:@"USD"
transactionId:trans.transactionIdentifier
additionalParameters:@{@"test": @"val" , @"test1" : @"val 1"}
success:^(NSDictionary *result){
NSLog(@"Purchase succeeded And verified!!! response: %@", result[@"receipt"]);
} failure:^(NSError *error, id response) {
NSLog(@"response = %@", response);
}];
AppsFlyerTracker.shared().validateAndTrack(inAppPurchase: product.productIdentifier, price: "\(product.price)", currency: product.priceLocale.currencyCode, transactionId: trans.transactionIdentifier, additionalParameters: nil,success:{(result) in
print("Purchase succeeded And verified!!! response \(result)")
},failure:{(error,message) in
print("response = \(message)")
})
Untuk melihat daftar kemungkinan nilai balik untuk validasi penerimaan, silakan baca dokumentasi Apple di sini.
Anonymize
AppsFlyer provides you with a method to annonymize specific user identifiers in AppsFlyer analytics. This method complies with the latest privacy requirements and complies with Facebook data and privacy policies. Default is NO, meaning no anonymization is performed by default.
Use this API during the SDK Initialization to explicitly anonymize a user's installs, events and sessions:
AppsFlyerTracker.shared().deviceTrackingDisabled = true
[AppsFlyerTracker sharedTracker].deviceTrackingDisabled = YES;
Pengukuran dapat diulang dengan memanggil kembali deviceTrackingDisabled
dan mengaturnya ke false.
Peringatan
Anonymizing users SEVERELY impacts your attribution information.Use this option ONLY for regions which legally prevent you from collecting your users' information.
Mengganti Waktu Antar Sesi
Agar AppsFlyer menghitung dua sesi yang berbeda, waktu default antara sesi minimalnya 5 detik. Sesi dimulai ketika pengguna membuka aplikasi. Gunakan API berikut jika Anda ingin mengonfigurasi waktu yang berbeda antara sesi:
AppsFlyerTracker.shared().minTimeBetweenSessions = <your_custom_time_in_seconds>
[AppsFlyerTracker sharedTracker].minTimeBetweenSessions = <your_custom_time_in_seconds>;
Sesi Latar Belakang untuk Aplikasi Utilitas
Ekstensi Aplikasi iOS dan WatchKit
Ekstensi aplikasi ini memerlukan hak akses untuk menggunakan Internet:
- Silakan buka file info.plist ekstensi aplikasi Anda
- Pada
NSExtension
/NSExtensionAttributes
atur benderaRequestsOpenAccess
ke YES.
Tambahkan kode berikut ke UIViewController ekstensi aplikasi viewDidLoad
:
override func viewDidLoad() {
super.viewDidLoad()
AppsFlyerTracker.shared().appsFlyerDevKey = "MY_APPSFLYER_KEY"
// MY_APP_ID below stands for you app ID on iTunes Connect. Should be 9 or 10 digits.
AppsFlyerTracker.shared().appleAppID = "MY_APP_ID"
AppsFlyerTracker.sharedTracker().trackAppLaunch()
}
- (void)viewDidLoad {
[super viewDidLoad];
// Replace MY_APPSFLYER_KEY below by your AppsFlyer dev key
[AppsFlyerTracker sharedTracker].appsFlyerDevKey = @"MY_APPSFLYER_KEY";
// MY_APP_ID below stands for you app ID on iTunes Connect. Should be 9 or 10 digits.
[AppsFlyerTracker sharedTracker].appleAppID = @"MY_APP_ID";
[[AppsFlyerTracker sharedTracker] trackAppLaunch];
}
Untuk menerima data atribusi pada ekstensi aplikasi, ikuti instruksi di sini dan terapkan pada UIViewController
aplikasi Anda, bukan pada AppDelegate.
Opt Out
In some extreme cases you might want to shut down all SDK tracking due to legal and privacy compliance. This can be achieved with the isStopTracking API. Once this API is invoked, our SDK will no longer communicate with our servers and stop functioning.
AppsFlyerTracker.shared().isStopTracking = true
[AppsFlyerTracker sharedTracker].isStopTracking = true;
Collect Device Name
AppsFlyer SDK allows you to collect Device Name for your internal analysis. By default, this capability is turned off. To turn it on use the following API:
AppsFlyerTracker.shared().shouldCollectDeviceName = false`
[AppsFlyerTracker sharedTracker].shouldCollectDeviceName = NO;
Penting
Device Name might be considered Personal Data in certain regions. Only collect this information if you know you are legally allowed to and have received the user's explicit consent to do so.
Setting Additional Data
The setAdditionalData API is required to integrate on the SDK level with several external partner platforms, including Segment, Adobe and Urban Airship. Use this API only if the integration article of the platform specifically states setAdditionalData API is needed.
The following is a code example for implementing setAdditionalData on iOS for Objective-C or Swift
NSDictionary* CustomDataMap = [[NSDictionary alloc] initWithObjectsAndKeys:@"value_of_param_1", @"custom_param_1", nil];
[[AppsFlyerTracker sharedTracker] setAdditionalData:CustomDataMap];
let CustomDataMap: [AnyHashable: Any] = [
"custom_param_1" : "value_of_param_1"
]
AppsFlyerTracker.shared().customData = CustomDataMap
10. Menguji Integrasi Anda
Untuk informasi lebih lanjut tentang cara menguji integrasi Anda, klik di sini.
11. Mengirimkan Aplikasi ke App Store
Anda dapat melihat instruksi cara mengirimkan aplikasi Anda ke App Store di sini.