Skip to content

mori1234/AppsFlyerCocos2dX

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

60 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cocos2dX AppsFlyer plugin for Android and iOS.


In order for us to provide optimal support, we would kindly ask you to submit any issues to [email protected]

When submitting an issue please specify your AppsFlyer sign-up (account) email , your app ID , production steps, logs, code snippets and any additional relevant information.


Table of content

1. Set your Dev_Key and enable AppsFlyer to detect installations, sessions (app opens) and updates.

This is the minimum requirement to start tracking your app installs and is already implemented in this plugin. You MUST modify this call and provide: -devKey - Your application devKey provided by AppsFlyer. -appId - (For iOS only) Your iTunes Application ID.

Add the following lines into applicationDidFinishLaunching and to applicationWillEnterForeground method to be able to initialize tracking with your own AppsFlyer dev key:

#include "AppsFlyer/AppsFlyerX.h"

bool AppDelegate::applicationDidFinishLaunching() {
  AppsFlyerX::setAppsFlyerDevKey("YOUR_DEV_KEY");

#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
    AppsFlyerX::setAppleAppID("942960987");
#endif
  
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
    AppsFlyerX::trackAppLaunch();
#endif
}

void AppDelegate::applicationWillEnterForeground() {
   //..
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
    AppsFlyerX::trackAppLaunch();
#endif
}

Also notify AppsFlyer SDK about background event:

void AppDelegate::applicationDidEnterBackground() {

    //...
    AppsFlyerX::didEnterBackground();
}

## API Methods


if true AppsFlyer SDK will run in debug mode

Example:

AppsFlyerX::setIsDebug(true);

trackEvent(eventName, eventValue): void (optional)

and

  • These in-app events help you track how loyal users discover your app, and attribute them to specific campaigns/media-sources. Please take the time define the event/s you want to measure to allow you to track ROI (Return on Investment) and LTV (Lifetime Value).
  • The trackEvent method allows you to send in-app events to AppsFlyer analytics. This method allows you to add events dynamically by adding them directly to the application code.
parameter type description
eventName string custom event name, is presented in your dashboard. See the Event list HERE
eventValues cocos2d::ValueMap event details

Example:

//basic implementation
AppsFlyerX::trackEvent(AFEventPurchase, {{ "key1", cocos2d::Value("value1")},
                                         { "key2", cocos2d::Value("value2")}});

//rich in-app-event implementation:
AppsFlyerX::trackEvent(AFEventPurchase, {
                        { AFEventParamContentId, Value({Value("12344"), Value("98844"), Value("39944")})},
                        { AFEventParamCurrency, Value({Value(20), Value(11), Value(61)})},
                        { AFEventParamPrice, Value({Value(25), Value(50), Value(10)})},
                        { AFEventParamContentType, Value("ELECTRONIC")},
                        { AFEventParamCurrency, Value("USD")},
                        {AFEventParamRevenue, cocos2d::Value("10.67")}
                });

More info about rich in-app-events you can find HERE

AppsFlyer allows you to access the user attribution data in real-time directly at SDK level. It enables you to customize the landing page a user sees on the very first app open after a fresh app install.

To access AppsFlyer's conversion data from the Android SDK implement the ConversionDataListener callback:

Examples:

static void onConversionDataReceived(cocos2d::ValueMap installData) {}

static void onConversionDataRequestFailure(cocos2d::ValueMap map) {
/*has signature {
                 {"status": "failure"},
                 {"data", "errorMessage"}
                 }*/
}

static void onAppOpenAttribution(cocos2d::ValueMap map) {}

static void onAppOpenAttributionFailure(cocos2d::ValueMap map) {
/*has signature {
                 {"status": "failure"},
                 {"data", "errorMessage"}
                 }*/
}

AppsFlyerX::setOnConversionDataReceived(onConversionDataReceived);
AppsFlyerX::setOnConversionDataRequestFailure(onConversionDataRequestFailure);
AppsFlyerX::setOnAppOpenAttribution(onAppOpenAttribution);
AppsFlyerX::setOnAppOpenAttributionFailure(onAppOpenAttributionFailure);

AppsFlyer enables you to report one or more of the device’s associated email addresses. You must collect the email addresses and report it to AppsFlyer according to your required encryption method. The following encryption methods are available: SHA1, MD5, SHA256 and plain.

parameter type Default description
userEmails std::vector<std::string> --- list of emails
type EmailCryptTypeX --- crypt type: None, sha1, sha256, md5

Examples:

AppsFlyerX::setUserEmails({"[email protected]"}, XEmailCryptTypeSHA256);

Setting your own Custom ID enables you to cross-reference your own unique ID with AppsFlyer’s user ID and the other devices’ IDs. This ID is available in AppsFlyer CSV reports along with postbacks APIs for cross-referencing with you internal IDs.

Note: The ID must be set during the first launch of the app at the SDK initialization. The best practice is to call this API during the deviceready event, where possible.

parameter type description
customerUserId const std::string&

Example:

AppsFlyerX::customerUserId("<USER_ID>");

parameter type Default description
currencyId const std::string& USD ISO 4217 Currency Codes

Examples:

AppsFlyerX::setCurrencyCode("<CURRENCY_ID>");

parameter type Default description
flag bool false disables Apple iAd Support Tracking

Examples:

AppsFlyerX::disableAppleAdSupportTracking(true);

parameter type Default description
flag bool false enables/disables device name tracking

Examples:

AppsFlyerX::setShouldCollectDeviceName(true);

parameter type Default description
appInviteOneLinkID std::string& Before calling startTracking in your app, set the OneLink which is invoked according to the OneLink ID. See additional info HERE

Examples:

AppsFlyerX::setAppInviteOneLink("8eOw");

parameter type Default description
flag bool false AppsFlyer provides you a method to opt-out specific users from AppsFlyer analytics. This method complies with the latest privacy requirements and complies with Facebook data and privacy policies. Default is false, meaning tracking is enabled by default. Warning Opting out users SEVERELY hurts your attribution information. Use this option ONLY on regions which legally bind you from collecting your users' information.

Examples:

AppsFlyerX::deviceTrackingDisabled(true);

parameter type Default description
flag bool false enables/disables iAD tracking

Examples:

AppsFlyerX::disableIAdTracking(true);

parameter type Default description
flag bool false enables Receipt Validation Sandbox

Examples:

AppsFlyerX::setUseReceiptValidationSandbox(true);

parameter type Default description
flag bool false enables Uninstall Sandbox mode

Examples:

AppsFlyerX::setUseUninstallSandbox(true);

parameter type Default description
publicKey const std::string&
signature const std::string&
purchaseData const std::string&
price const std::string&
currency const std::string&
additionalParameters cocos2d::ValueMap

Examples:

ValueMap test_map;
test_map["key1"] = "value1";
std::string base64EncodedPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA3dkBTr2pD2YSqSK2ewlEWwH9Llu0iA4PkwgVOyNRxOsHfrOlqi0Cm51qdNS0aqh/SMZkuQTAroqH3pAr9gVFOiejKRw+ymTaL5wB9+5n1mAbdeO2tv2FDsbawDvp7u6fIBejYt7Dtmih+kcu707fEO58HZWqgzx9qSHmrkMZr6yvHCtAhdBLwSBBjyhPHy7RAwKA+PE+HYVV2UNb5urqIZ9eI1dAv3RHX/xxHVHRJcjnTyMAqBmfFM+o31tp8/1CxGIazVN8HpVk8Qi2uqSS5HdKUu6VnIK8VuAHQbXQn4bG6GXx5Tp0SX1fKrejo7hupNUCgOlqsYHFYxsRkEOi0QIDAQAB";
std::string signature = "OaIdwQOcmrJrMKUx+URVy1I6aeKYiYzflkk1zIKVSs+dDv691neCbR+jlDDzVi3jfSkfirxQISxo7Pe1uzoYbpq9wBk/pMgVjjSbpvCojhA4d/Mwsf4mtAH2LJcVNjhMQdSWvGJlzva3OSt+KQ+9/pRJ15aYT2gFn3SpGSPxNxJmHPIOlM1Lr74MejVu9rnbcSjCB/oI0W4O58p9UWSt5MgmlpqlrK5YqTi1a1VnttY9r1IXFeltwZvmPbcWcYwRHFvemwYGX86huSOFBOYRfaYo9f+DinpoUoXKQEo0JrvKD2/dzFkbUTto1d2OPo1ddaYllgsb2UEV5wwFZFnemg==";
std::string purchaseData = "{\"orderId\":\"\",\"packageName\":\"com.appsflyer.testapp\",\"productId\":\"consumable\",\"purchaseTime\":1497531638107,\"purchaseState\":0,\"developerPayload\":\"2497525891514-5765886608164763986\",\"purchaseToken\":\"pfkalmpnnimamdllmincaida.AO-J1OymunlPCkDQZTf8bPcesoB0n1_ND3WFynoU91-v_R1Px46m3Q-DdRKNlxMVsP2pCTKpo1et1w1IpNVXQ8-zNpRo6a2nXP7a5fQWiDv2asL1dwJPCV8NghDHbstO084IlKo6xcgy\"}";
    
AppsFlyerX::validateAndTrackInAppPurchase(base64EncodedPublicKey, 
                                          signature, 
                        "3.00",
                      "ILS",
                      test_map);

parameter type Default description
productIdentifier const std::string&
price const std::string&
currency const std::string&
tranactionId const std::string&
params cocos2d::ValueMap
successBlock std::function<void(cocos2d::ValueMap)>
failureBlock std::function<void(cocos2d::ValueMap)>

Examples:

ValueMap test_map;
test_map["key1"] = "value1";
std::string productIdentifier = "com.mycomp.inapppurchase.cons";
std::string tr_id = "1000000256672208";
  
AppsFlyerX::validateAndTrackInAppPurchase(productIdentifier, 
                                          "1.99",
                                          "USD",
                                          tr_id
                      test_map, 
                      successBlock,
                      failureBlock);

Examples:

std::string appsflyerId = AppsFlyerX::getAppsFlyerUID();

  • void AppsFlyerX::handleOpenURL(const std::string& url, const std::string& sourceApplication)
  • void AppsFlyerX::handleOpenURL(std::string url, std::string sourceApplication, void* annotation)
  • void AppsFlyerX::handleOpenURL(std::string url, cocos2d::ValueMap options)

Examples:

TBD

For more Info see the DOCs

Open your Xcode project and locate the file AppController.mm under the iOS folder inside your project. Add the following code snippet under didFinishLaunchingWithOptions :

#import "AppsFlyerTracker.h"

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//...
UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert |
                                                    UIUserNotificationTypeBadge |
                                                    UIUserNotificationTypeSound);
    UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes
                                                                             categories:nil];
    [application registerUserNotificationSettings:settings];
    [application registerForRemoteNotifications];
//..
}

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {    
    [[AppsFlyerTracker sharedTracker] registerUninstall:deviceToken];
}

and method implementation:

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {    
    [[AppsFlyerTracker sharedTracker] registerUninstall:deviceToken];
}

parameter type Default description
host std::string& host name that should override appsflyer.com
Examples:
AppsFlyerX::setHost("mynewhost.com");

parameter type Default description
minTimeBetweenSessions unsigned long host name that should override appsflyer.com
Examples:
AppsFlyerX::setMinTimeBetweenSessions(9);

Enables app uninstall tracking. More Information

parameter type description
FCM/GCM ProjectNumber String GCM/FCM ProjectNumber
onSuccess (message: string)=>void Success callback - called after successfull register uninstall. (optional)
onError (message: string)=>void Error callback - called when error occurs during register uninstall. (optional)

Allows to pass GCM/FCM Tokens that where collected by third party plugins to the AppsFlyer server. Can be used for Uninstall Tracking.

parameter type description
token String GCM/FCM Token

In ver. >4.2.5 deeplinking metadata (scheme/host) is sent automatically TBD

TBD

About

AppsFlyer Cocos2dX plugin

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 54.3%
  • Objective-C++ 19.5%
  • Objective-C 15.0%
  • C 5.5%
  • CMake 3.9%
  • Java 0.9%
  • Makefile 0.9%