広告を連携する方法

    広告を連携する方法


    記事の要約

    複数の広告チャネルを経由する場合、ディープリンクまたはウェブリンクのアドレスにクエリパラメータを追加することで、広告のトラッキングを継続的に行うことができます。

    以下の例では、ディープリンクからの流入を想定しています。

    ディープリンクの AndroidManifest.xml 設定

    <activity android:name=".DeepLinkActivity">
        <intent-filter android:autoVerify="true">
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data
                android:scheme="https"
                android:host="xxxx"
                android:path="/yyyy" />
        </intent-filter>
    </activity>

    ShopLive SDK でのクエリパラメータ設定

    class DeepLinkHandlerActivity : AppCompatActivity() {
        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
            val uri = intent?.data
            uri?.let {
                for (paramName in it.queryParameterNames) {
                    val paramValue = it.getQueryParameter(paramName) ?: continue
                    // 広告用のクエリパラメータを追加 {key, value} 
                    ShopLive.addParameter(paramName, paramValue)
                }
                val intent = Intent(this, MainActivity::class.java)
                startActivity(intent)
            } ?: run {
                Log.e("DeepLink", "URI is null")
            }
            finish()
        }
    }