LoginSignup
11
5

More than 5 years have passed since last update.

FirebaseとiAd.frameworkの連携についてわかったことメモ

Last updated at Posted at 2019-04-11

やりたいこと

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.sourceAppleと入ってきてくれるはず

スクリーンショット 2019-03-04 17.41.43.png

スクリーンショット 2019-03-05 17.28.35.png

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.

AppleのiAd.frameworkのドキュメント

ドキュメントに従いtargetの Generalを選択し、Linked Frameworks and Librariesの項目の下の方のプラスボタンを押して,iAd.frameworkを導入する

問題点

iAd.frameworkを導入するだけで、本当にFirebaseが集計してくれるのか不安、Search Adsに課金しない限り調べる方法はないのか探していた

改善策

Xcode デバックコンソールでログを見る

image.png
image.png

ドキュメントリンク

Firebase Debug Viewで送信されている
イベントを確認する

image.png

気になるログを発見した

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):

アプリ流入比率変えた.032.jpeg

結果

無事にFirebaseで送られてBigQuery内で確認することができた

アプリ流入比率変えた.034.jpeg

(おまけ)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

11
5
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
5