Last active
November 12, 2017 01:29
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
hyperloop: { | |
ios: { | |
xcodebuild: { | |
frameworks: [ | |
'iAd' | |
] | |
} | |
} | |
} | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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