Skip to main content

Adding a placement

For Rokt partners, the Android SDK can be used to display overlay or embedded placements in your android app.

Before you begin#

Ensure that the Rokt Android SDK has already been integrated into your application following the steps listed here.

Overlay placements#

Execute the SDK in your desired activity/fragment, adding any appropriate customer attributes and the placement mapping. The example code uses the onCreate method to launch the placement.

The Rokt widget view displays after a short delay, configurable via the Rokt platform. The SDK provides optional callback events for when the view loads and unloads.

You can dictate what customer attributes are included in your Rokt integration. More information on available data fields can be found on the attributes page. If you want to integrate more attributes, you can add additional lines of code for each new attribute to the samples below.

import com.rokt.roktsdk.Rokt;
class ConfirmationActivity : Activity() {    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");
        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() {                }            }        )        ...    }}

Embedded placements#

Updating your layout XML file#

<?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>
note

The Rokt embedded placement can also be created in your code and included in the layout dynamically.

Executing the SDK#

Execute the SDK in your desired activity/fragment, adding any appropriate customer attributes and the placement mapping. The example code uses the onCreate method to launch the placement.

The Rokt placement displays after a short delay, configurable via the Rokt platform.

We advise setting the height of the placement to wrap_content so that the placement can set its height dynamically.

The SDK provides optional callback events for when the view loads and unloads.

You can dictate what customer attributes are shared with Rokt. More information on available data fields can be found on the attributes page. If you want to share more attributes, you can add additional lines of code for each new attribute to the samples below.

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 placeholder mapping the placeholder view with placement location configuration        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);        ...    }}
note

If you want to update the view name RoktExperience or placeholder name RoktEmbedded1 with a different value, contact your Rokt account manager to ensure Rokt placements are configured consistently.

Was this article helpful?