プレースメントの追加
Roktのパートナーの場合、Android SDKを使用してAndroidアプリ内にオーバーレイまたは埋め込みプレースメントを表示することができます。
開始する前に
Rokt Android SDKがすでにアプリケーションに統合されていることを確認してください。
オーバーレイプレースメント
SDKを適切なアクティビティ/フラグメントで実行し、適切なカスタマーアトリビュートとプレースメントマッピングを追加します。例のコードでは、onCreate
メソッドを使用してプレースメントを起動します。
Roktウィジェットビューは、Roktプラットフォームで設定可能な短い遅延後に表示されます。SDKは、ビューの読み込みとアンロード時のオプションのコールバックイベントを提供します。
Roktの統合に含めるカスタマーアトリビュートを指定することができます。利用可能なデータフィールドの詳細については、attributesページを参照してください。さらに属性を統合する場合は、以下のサンプルに新しい属性ごとに追加のコード行を追加できます。
- Java
- Kotlin
kotlin
import com.rokt.roktsdk.Rokt
class ConfirmationActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
...
// 適切な消費者属性を含める
val attributes = hashMapOf(
Pair("email", "j.smith@example.com"),
Pair("firstname", "Jenny"),
Pair("lastname", "Smith"),
Pair("mobile", "(323) 867-5309"),
Pair("postcode", "90210"),
Pair("country", "US"))
Rokt.execute("RoktExperience",
attributes,
object : Rokt.RoktCallback {
override fun onUnload(reason: Rokt.UnloadReasons) {
}
override fun onLoad() {
}
override fun onShouldHideLoadingIndicator() {
}
override fun onShouldShowLoadingIndicator() {
}
}
)
...
}
}
import com.rokt.roktsdk.Rokt;
class ConfirmationActivity : Activity() {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
Map<String,String> attributes = new HashMap<String, String>();
attributes.put("email", "j.smith@example.com");
attributes.put("firstname", "Jenny");
attributes.put("lastname", "Smith");
attributes.put("mobile", "(323) 867-5309");
attributes.put("postcode", "90210");
attributes.put("country", "US");
Rokt.INSTANCE.execute("RoktExperience",
attributes,
new Rokt.RoktCallback() {
@Override
public void onLoad() {
}
@Override
public void onUnload(Rokt.UnloadReasons unloadReasons) {
}
@Override
public void onShouldHideLoadingIndicator() {
}
@Override
public void onShouldShowLoadingIndicator() {
}
}
)
...
}
}
オプションの機能
機能 | 目的 |
---|---|
Rokt.close() | オーバーレイプレースメントを自動的に閉じるために使用されます。 |
埋め込みプレースメント
レイアウトのXMLファイルの更新
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.rokt.roktsdk.Widget
android:id="@+id/roktWidget"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Roktの埋め込みプレースメントは、コード内で作成し、レイアウトに動的に含めることもできます。
SDKの実行
SDKを実行し、適切な顧客属性とプレースメントマッピングを追加して、目的のアクティビティ/フラグメントで実行します。例のコードでは、onCreate
メソッドを使用してプレースメントを起動します。
Roktのプレースメントは、Roktプラットフォームを介して設定可能な短い遅延後に表示されます。
プレースメントの高さをwrap_content
に設定することをお勧めします。これにより、プレースメントが動的に高さを設定できます。
SDKには、ビューの読み込みとアンロードのためのオプションのコールバックイベントが用意されています。
Roktの統合に含める顧客属性を選択できます。使用可能なデータフィールドの詳細については、attributesページを参照してください。追加の属性を追加する場合は、以下のサンプルコードに新しい属性ごとに追加のコード行を追加できます。
- Java
- Kotlin
import com.rokt.roktsdk.Widget
import com.rokt.roktsdk.Rokt
class ConfirmationActivity : Activity() {
private val roktCalllback = object : Rokt.RoktCallback {
override fun onLoad() {
}
override fun onShouldShowLoadingIndicator() {
}
override fun onShouldHideLoadingIndicator() {
}
override fun onUnload(reason: Rokt.UnloadReasons) {
}
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
...
// 適切な顧客属性を含める
val attributes = hashMapOf(
Pair("email", "j.smith@example.com"),
Pair("firstname", "Jenny"),
Pair("lastname", "Smith"),
Pair("mobile", "(323) 867-5309"),
Pair("postcode", "90210"),
Pair("country", "US")
)
// プレースホルダービューとプレースメントの場所の設定をマッピングするウィジェット
val widget = findViewById<Widget>(R.id.roktWidget)
val placeHolders = hashMapOf(
Pair("RoktEmbedded1", WeakReference(widget))
)
Rokt.execute(
viewName = "RoktExperience",
attributes = attributes,
callback = roktCalllback,
placeholders = placeHolders
)
...
}
}
import com.rokt.roktsdk.Widget;
import com.rokt.roktsdk.Rokt;
class ConfirmationActivity : Activity() {
private Rokt.RoktCallback roktCallback = new Rokt.RoktCallback() {
@Override
public void onLoad() {
}
@Override
public void onShouldShowLoadingIndicator() {
}
@Override
public void onShouldHideLoadingIndicator() {
}
@Override
public void onUnload(@NotNull Rokt.UnloadReasons unloadReasons) {
}
};
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
...
Map<String, String> attributes = new HashMap<String, String>();
attributes.put("email", "j.smith@example.com");
attributes.put("firstname", "Jenny");
attributes.put("lastname", "Smith");
attributes.put("mobile", "(323) 867-5309");
attributes.put("postcode", "90210");
attributes.put("country", "US");
// ウィジェットのプレースホルダーと配置場所の設定をマッピングする
Widget widget = findViewById(R.id.roktWidget);
Map<String, WeakReference<Widget>> placeHolders = new HashMap<>();
placeHolders.put("RoktEmbedded1", new WeakReference<>(widget));
Rokt.INSTANCE.execute("RoktExperience",
attributes,
roktCallback,
placeHolders);
...
}
}
もしRoktExperience
というビュー名やRoktEmbedded1
というプレースホルダー名を別の値に更新したい場合は、Roktのアカウントマネージャーに連絡して、Roktの配置が一貫して設定されていることを確認してください。