Adobe Air Native Extension for Amplitude analytics on the iOS and Android platforms.
This extension uses the Amplitude SDK version 5.1.0
for iOS and SDK version 2.25.1
for Android.
This extension requires iOS 7.0 or higher and Android 4.0 (API level 14) or higher.
When packaging your app for iOS, you need to use AIR 28+ or provide a path to iOS 11+ SDK (available in Xcode 9) using the -platformsdk
option in adt
or via corresponding UI of your IDE, for example:
-platformsdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.2.sdk
Download the ANE from the bin directory or from the releases page and add it to your app's descriptor:
<extensions>
<extensionID>com.digitalstrawberry.nativeExtensions.ANEAmplitude</extensionID>
</extensions>
On iOS, you may need to add the following ANE to be able to build your IPA:
com.distriqt.Core
(https://github.com/distriqt/ANE-Core)
If you are targeting Android, add the following dependency extensions:
androidx.core
(https://github.com/distriqt/ANE-AndroidSupport)com.distriqt.playservices.AdsIdentifier
(https://github.com/distriqt/ANE-GooglePlayServices)com.distriqt.playservices.Base
(https://github.com/distriqt/ANE-GooglePlayServices)com.distriqt.square.okhttp3
(https://github.com/distriqt/ANE-SquareLibs)
Credits to Distriqt for providing these extensions.
You will also need to add the following permissions to the Android manifest:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
And add the following meta data to the <application>
element inside manifest additions:
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
There is no additional code required for the iOS platform.
Start off by initializing the Amplitude extension with your API key:
Amplitude.initialize("YOUR_API_KEY");
You can set the client user id if you wish to identify specific users:
Amplitude.setUserId("USER_ID");
Alternatively you can also specify a user id when you initialize the extension:
Amplitude.initialize("YOUR_API_KEY", "USER_ID");
Session tracking is automatically handled for both iOS and Android. You do not need to call any methods for this to work correctly. To disable automatic tracking, pass in false
as a third parameter to the initialize
method:
Amplitude.initialize("YOUR_API_KEY", "USER_ID", false);
You can log a basic event with only a name:
Amplitude.logEvent("EVENT_NAME");
Or you can log complex events with multiple parameters:
Amplitude.logEvent("EVENT_NAME", {param1: "hello", param2: "world"});
You can set properties for the specific user:
Amplitude.setUserProperties({param1: "hello", param2, "world"});
You can assign user to a group. The second groupName
parameter accepts either a string or an array of strings:
Amplitude.setGroup("organizationId", "15");
Amplitude.setGroup("sport", ["tennis", "baseball"]);
Just like setting user properties, you can also set group properties:
Amplitude.setGroupProperties("company", "Amplitude", {members: 80});
Log a basic revenue event, with a quantity of one and a price of $1.99:
Amplitude.logRevenue("com.myproduct", 1, 1.99);
If you want to be able to use Amplitude's built-in revenue verification, you must extract the returned receipt data from your in app purchase extension that you are using. Use the following code for iOS:
Amplitude.logRevenue("com.myproduct", 1, 1.99, "INSERT_RECEIPT_DATA");
Android verification requires the IAP purchase data and data signature:
Amplitude.logRevenue("com.myproduct", 1, 1.99, "INSERT_PURCHASE_DATA", "INSERT_PURCHASE_SIGNATURE");
Note that the revenue must be converted to USD before it can be passed to Amplitude, as they do not currently offer currency conversion.
You can view the device indentifier Amplitude is using by calling the following:
var deviceId:String = Amplitude.getDeviceId();
By default Android uses a randomly generated UUID and iOS used the IDFV indentifier. If you would like Amplitude to use Google's Advertising ID on Android and Apple's IDFA on iOS, call the following method:
Amplitude.useAdvertisingIdForDeviceId();
You can learn more about the inner workings of the Amplitude system using the following resources:
You can compile the Air Native Extension from source by copying the build/build.config.template
file to build/build.config
updating it to match your development enviroment. Then run the ant
command in the build
folder to build the entire project.
Special thanks to the StickSports ANEs for the initial build script and testing code and the ANEZipFile project for the FRETypeUtils code for iOS.