やりたいこと
BigQuery内でSearch Adsのコンバージョンを集計させたい
FirebaseのApple Search Adsに関するドキュメント
Firebaseの集計データはBigQueryのデータをいい感じに集計して表示してくれている。Google広告と連携させていれば、どの広告をタップしてインストールしてくれたのかということがわかる。しかしAppleのSearch Adsに関しては、iOSアプリ側から何かしら入れてあげないと集計できていないことがわかった。
具体的に送られるイベントや、何が送られるのかはこちらを参照する
https://support.google.com/firebase/answer/6317518?hl=ja
Apple Search Adsに関して引用すると
Apple Search Ads
Apple Search Ads のクリックによってアプリがインストールされた場合、firebase_campaign イベントが上記のパラメータとともに記録され、キャンペーン関連のイベントについては次のデータが表示されます。
参照元 = Apple
メディア = search
キャンペーン = <iad キャンペーン名>
Apple Search Ads をトラッキングするには、アプリ用の Xcodeプロジェクトファイルに iAd フレーム ワークを追加する必要があります。
このようにAppleに関しても集計できそうということがわかる
iAd.frameworkを入れればFirebaseがいい感じに集計してくれそうということがわかる
BigQueryの調べ方
具体的にBigQueryに何が送られてくるのかは、こちらを参照する
https://support.google.com/firebase/answer/7029846?hl=ja&ref_topic=7029512
traffic_sourceを調べる具体例
traffic_sourceとは ユーザーを最初に獲得したトラフィック ソースの名前。このフィールドは当日テーブルでは使用されません。
叩くクエリ例
SELECT traffic_source.source, COUNT(*)
FROM `{テーブル名}`
GROUP BY traffic_source.source
LIMIT 100
下記のような感じで、データの結果が帰ってくる。この例では、テーブルを検索し、どの流入元が一番多いのか調べるために、数を数えた
おそらくSearch Adsで広告を打った場合、traffic_source.sourceにAppleと入ってきてくれるはず
iAd.framework 導入について
iAd.frameworkのドキュメントには下記のようにフレームワークを入れると書いてある
iAd framework
The iAd framework is bundled with Xcode. Follow these steps to add the iAd framework to the Xcode project file for your app:
1. Go to your target view and select General.
2. Scroll down to a section called Linked Frameworks and Libraries and click the plus (+) icon.
3. In the dropdown menu, search for iAd.
4. Select iAd.framework and click the Add button.
ドキュメントに従いtargetの Generalを選択し、Linked Frameworks and Librariesの項目の下の方のプラスボタンを押して,iAd.frameworkを導入する
問題点
iAd.frameworkを導入するだけで、本当にFirebaseが集計してくれるのか不安、Search Adsに課金しない限り調べる方法はないのか探していた
改善策
Xcode デバックコンソールでログを見る
ドキュメントリンク
Firebase Debug Viewで送信されている イベントを確認する
気になるログを発見した
iAd.frameworkを導入するとログが変わっていることがわかった
導入前
xxxxApp[00000:000000] Ad framework is not linked. Search Ad Attribution Reporter is disabled.
xxxxApp[00000:000000] No data to upload. Upload task will not be scheduled
xxxxApp[00000:000000] Analytics enabled
導入後
xxxxApp[00000:000000] Scheduling Search Ad Report timer
xxxxApp[00000:000000] Search Ad campaign report alarm scheduled to fire in approx. (s):
結果
無事にFirebaseで送られてBigQuery内で確認することができた
(おまけ)iAd.framework 導入によってアプリ内に、端末がどのキャンペーン経由でインストールされたのか取得する
Firebaseの連携とは全く関係ないのだが一応、必要な人もいるかも知れないので共有
iAd.frameworkを導入すると利用できるようになる関数ADClient.shared().requestAttributionDetailsを用いて,
辞書 attributionDetails の中に広告の情報が入っている。ここでとりだして、各自データを集計しているサーバーにおくればいいのではないかと思う
詳細に関してはAppleのiAd.frameworkのドキュメントに書いてある
import iAd
import UIKit
class TestViewController: UIViewController{
override func viewDidLoad() {
super.viewDidLoad()
ADClient.shared().requestAttributionDetails({ (attributionDetails, error) in
if error == nil {
for (type, adDictionary) in attributionDetails! {
var attribution = adDictionary as? Dictionary<AnyHashable, Any>;
let params = [
"appID": "self.appData.appID",
"iadAdgroupId": attribution?["iad-adgroup-id"] as? String as Any,
"iadAdgroupName": attribution?["iad-adgroup-name"] as? String as Any,
"iadAttribution": attribution?["iad-attribution"] as? String as Any,
"iadCampaignId": attribution?["iad-campaign-id"] as? String as Any,
"iadCampaignName": attribution?["iad-campaign-name"] as? String as Any,
"iadClickDate": attribution?["iad-click-date"] as? String as Any,
"iadConversionDate": attribution?["iad-conversion-date"] as? String as Any,
"iadCreativeId": attribution?["iad-creative-id"] as? String as Any,
"iadCreativeName": attribution?["iad-creative-name"] as? String as Any,
"iadKeyword": attribution?["iad-keyword"] as? String as Any,
"iadLineitemId": attribution?["iad-lineitem-id"] as? String as Any,
"iadLineitemName": attribution?["iad-lineitem-name"] as? String as Any,
"iadOrgName": attribution?["iad-org-name"] as? String as Any
]
print("////////////////////")
print(params)
}
}
})
}
}
参考文献
iAd frameworkをいれるだけでいいということに気がついた記事
https://groups.google.com/forum/#!topic/firebase-talk/dUxH5VfHG2k





