0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

MarketingCloudSDK iOSでpush通知からGAにカスタムパラメータを送信する

Posted at

環境

・xcode Version 11.3.1 (11C504)
・swift Version 5.1.3
・MarketingCloudSDK iOS (v7.2.1)
・Mac OS 10.14.6(Mojave)

準備

1.MarketingCloudSDK iOSでシンプルなpush通知を送信する
2.[MarketingCloudSDK iOSでリッチPush通知を送信する]
(https://qiita.com/techman/items/06267ff52a2531264cac)
の続きとなります。

Firebaseをアプリに組み込む

  1. firebaseのコンソールからプロジェクトを作成する
    ※googleAnalyticsの設定をONにする

  2. アプリをFirebaseに登録する

  3. Firebaseコンソールの中央にあるiosアイコンをクリックする
    test-app_-test-app-_Firebase_コンソール.png

  4. 指示通り①〜⑤まで進めていく
    スクリーンショット 2020-08-16 11.04.45.png

 ① Apple Developer Programにて登録したアプリのバンドルIDを入力。他は省略可能
 ② GoogleService-Info.plistをダウンロードし、AppDelegate.swiftなどと同じフォルダに追加する
 ③ podfileにFirebaseSDKの設定を追加し、pod installする
  ※cocoapodsをインストールしていない場合はMarketingCloudSDK iOSでシンプルなpush通知を送信するSDK追加を参照してください
 ④ didFinishLaunchingWithOptionsメソッドに初期化コードを追加する
 ⑤ アプリを実行してインストールされたかを確認(かなり時間かかります)

カスタムキーの設定をアプリに追加

SMC側からカスタムキーと呼ばれるパラメータをpush通知と一緒に送信することができます。
 ※mobliePUsh > 管理 > 設定でカスタムキーを有効にする必要があります。

以下実装サンプルとなります

AppDelegate.swift
// このメソッドは、ユーザーがアプリケーションを開くか、通知を破棄するか、UNNotificationActionを選択することで通知に応答したときに、デリゲートで呼び出される
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
    // tell the MarketingCloudSDK about the notification
    MarketingCloudSDK.sharedInstance().sfmc_setNotificationRequest(response.notification.request)
    // the dictionary containing custom keys    
    let userInfo = response.notification.request.content.userInfo
    let someValue = userInfo["SMCで設定した任意のキー"] as? String
    if someValue != nil {
       Analytics.logEvent("イベントの名前を設定", parameters: [
         "SMCで設定した任意のキー": someValue!
       ])
    }
    // application-specific usage follows
    print(someValue ?? "someValue is nil")
    completionHandler()
}
AppDelegate.swift
Analytics.logEvent("イベントの名前を設定", parameters: [
         "SMCで設定した任意のキー": someValue!
])

上記部分でカスタムイベントの名前を設定し、SMC側で設定したキーと値をGAに送信します。

GA側で確認する

  1. 実機にビルドし、SMC側でカスタムキーとパラメータを送信し、デバイスに来たpush通知をタップする
  2. firabaseのダッシュボードからGoogle アナリティクスでデータを確認するをクリックする
    test-app-ios_-Dashboard-_Firebase_コンソール_と_メモ.png
  3. ホームのダッシュボードに反映されるまで24時間ほどかかるので、リアルタイムでデータを確認できるDebugViewで確認する(今はなにも表示されてないですが、正しく送信されていればパラメータを確認できます)アナリティクス.png

参考リンク(公式)

https://salesforce-marketingcloud.github.io/MarketingCloudSDK-iOS/push-notifications/custom-keys.html
https://firebase.google.com/docs/analytics/android/events?hl=ja

0
0
0

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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?