Skip to content

Instantly share code, notes, and snippets.

@jkotchoff
Last active November 12, 2017 01:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jkotchoff/d699263221231d59cadd6eb8212cc64e to your computer and use it in GitHub Desktop.
Save jkotchoff/d699263221231d59cadd6eb8212cc64e to your computer and use it in GitHub Desktop.
This Titanium code can be used in an appcelerator project (with Hyperloop enabled) to determine if an iOS advertisement was the cause of the current installation
module.exports = {
hyperloop: {
ios: {
xcodebuild: {
frameworks: [
'iAd'
]
}
}
}
};
var ios_ads_attribution_requested = Ti.App.Properties.getBool('IOS_ADS_ATTRIBUTION_REQUESTED', false );
if(!ios_ads_attribution_requested) {
var ADClient = require("iAd/ADClient");
ADClient.sharedClient().requestAttributionDetailsWithBlock(function(attributionDetailsDictionary, errorNsError){
if(errorNsError != null){
if(errorNsError.code == 0){
console.log("ADClientErrorUnknown");
} else if(errorNsError.code == 1){
console.log("ADClientErrorLimitAdTracking");
}
console.log("ADC error: " + errorNsError.description); // I haven't tested this yet
} else {
var data = String(attributionDetailsDictionary);
if(data != null || data.length > 0){
// Save #data
// Note:
// This isn't a valid JSON structure. Here is the server-side ruby I used to extract the campaign name:
// campaign_name = data.split("iad-campaign-name").last.split("\;").first.split("=").last.strip rescue nil
}
}
});
Ti.App.Properties.setBool('IOS_ADS_ATTRIBUTION_REQUESTED', true);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment