{"id":3685,"date":"2017-09-14T13:40:31","date_gmt":"2017-09-14T13:40:31","guid":{"rendered":"http:\/\/www.nikola-breznjak.com\/blog\/?p=3685"},"modified":"2017-09-14T13:46:02","modified_gmt":"2017-09-14T13:46:02","slug":"cordova-ionic-plugin-search-ads-app-attribution-api","status":"publish","type":"post","link":"https:\/\/nikola-breznjak.com\/blog\/javascript\/ionic\/cordova-ionic-plugin-search-ads-app-attribution-api\/","title":{"rendered":"Cordova Ionic Plugin for Search Ads App Attribution API"},"content":{"rendered":"<h2>TL;DR<\/h2>\n<p>Cordova plugin for reading Search Ads App Attribution on <strong>iOS 10.0+ only<\/strong> with an Ionic demo showcasing its usage.<\/p>\n<p>The Search Ads API plugin for Cordova\/Ionic didn&#8217;t exist, so I created it. You can <a href=\"https:\/\/github.com\/Hitman666\/cordova-plugin-searchads\">check out the plugin code on Github<\/a>, view the <a href=\"https:\/\/github.com\/Hitman666\/ionicDemoCordovaPluginSearchAds\">Ionic demo app code on Github<\/a> or read onward for an example on how to use it.<\/p>\n<blockquote><p>\n  You can also check out the step by step tutorial about <a href=\"http:\/\/www.nikola-breznjak.com\/blog\/ios\/create-native-ios-app-can-read-search-ads-attribution-api-information\/\">How to create a <strong>native iOS app<\/strong> that can read Search Ads Attribution API information<\/a> if you&#8217;re not into hybrid solutions ?\n<\/p><\/blockquote>\n<h2>What is Search Ads App Attribution?<\/h2>\n<p>From <a href=\"https:\/\/searchads.apple.com\/help\/pdf\/attribution-api.pdf\">Apple&#8217;s documentation<\/a>:<\/p>\n<blockquote><p>\n  Search Ads App Attribution enables developers to track and attribute app downloads that originate from Search Ads campaigns. With Search Ads App Attribution, iOS developers have the ability to accurately measure the lifetime value of newly acquired users and the effectiveness of their advertising campaigns.\n<\/p><\/blockquote>\n<h2>How to use the plugin<\/h2>\n<p>If you want to test this on a blank project, you can create a new Ionic project like this:<\/p>\n<p><code>ionic start ionicSearchAdsDemo tabs<\/code><\/p>\n<p>Since the plugin has been added to <a href=\"https:\/\/www.npmjs.com\/package\/cordova-plugin-searchads\">npm repository<\/a>, you can simply add it like this:<\/p>\n<p><code>ionic plugin add cordova-plugin-searchads<\/code><\/p>\n<p>Add the following code in the <code>controllers.js<\/code> file under the <code>DashCtrl<\/code> controller:<\/p>\n<pre><code>.controller('DashCtrl', function($scope, $ionicPlatform) {\n    $scope.data = 'no data';\n\n    $ionicPlatform.ready(function() {\n        if (typeof SearchAds !== \"undefined\") {\n            searchAds = new SearchAds();\n\n            searchAds.initialize(function(attribution) {\n                console.dir(attribution); \/\/ do something with this attribution (send to your server for further processing)\n                $scope.data = JSON.stringify(attribution);\n            }, function (err) {\n                console.dir(err);\n            });\n        }\n    });\n})\n<\/code><\/pre>\n<p>Replace the content of the <code>templates\/tab-dash.html<\/code> file with this:<\/p>\n<pre><code>&lt;ion-view view-title=\"Dashboard\"&gt;\n  &lt;ion-content class=\"padding\"&gt;\n    &lt;div class=\"card\"&gt;\n      &lt;div class=\"item item-text-wrap\"&gt;\n        {{data}}\n      &lt;\/div&gt;\n    &lt;\/div&gt;\n  &lt;\/ion-content&gt;\n&lt;\/ion-view&gt;\n<\/code><\/pre>\n<p>Prepare the project by executing the following command in your terminal:<\/p>\n<p><code>ionic prepare ios &amp;&amp; open platforms\/ios<\/code><\/p>\n<p>After this, open up the XCode project (<code>*.xcodeproj<\/code>) file:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/i.imgur.com\/jqxYHFs.png\" alt=\"\" \/><\/p>\n<p>Make sure the <code>iAd.framework<\/code> has been added to Linked Frameworks and Libraries:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/i.imgur.com\/fvRkNQU.png\" alt=\"\" \/><\/p>\n<p>This should have happened automatically when you&#8217;ve added the plugin, but it&#8217;s good to make sure. Add it yourself if you don&#8217;t see it here.<\/p>\n<p>Run the project on your device, and you should get something like this:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/i.imgur.com\/tdnkgqb.png\" alt=\"\" \/><\/p>\n<p>Hope this proves to be useful to someone! ?<\/p>\n<blockquote class=\"twitter-tweet\" data-width=\"550\">\n<p lang=\"en\" dir=\"ltr\"><a href=\"https:\/\/twitter.com\/hashtag\/Cordova?src=hash\">#Cordova<\/a> <a href=\"https:\/\/twitter.com\/hashtag\/Ionic?src=hash\">#Ionic<\/a> Plugin for Search Ads App Attribution API <a href=\"https:\/\/t.co\/D4yMevINOf\">https:\/\/t.co\/D4yMevINOf<\/a><\/p>\n<p>&mdash; Nikola Bre\u017enjak (@HitmanHR) <a href=\"https:\/\/twitter.com\/HitmanHR\/status\/908325418763259909\">September 14, 2017<\/a><\/p><\/blockquote>\n<p><script async src=\"\/\/platform.twitter.com\/widgets.js\" charset=\"utf-8\"><\/script><\/p>\n","protected":false},"excerpt":{"rendered":"<p>TL;DR Cordova plugin for reading Search Ads App Attribution on iOS 10.0+ only with an Ionic demo showcasing its usage. The Search Ads API plugin for Cordova\/Ionic didn&#8217;t&hellip;<\/p>\n","protected":false},"author":1,"featured_media":3681,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[43],"tags":[],"class_list":["post-3685","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ionic"],"_links":{"self":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts\/3685","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/comments?post=3685"}],"version-history":[{"count":2,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts\/3685\/revisions"}],"predecessor-version":[{"id":3688,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts\/3685\/revisions\/3688"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/media\/3681"}],"wp:attachment":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/media?parent=3685"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/categories?post=3685"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/tags?post=3685"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}