Follow the instructions to implement Contextual Commerce inline campaigns in your Android application using Jetpack Compose.
Step 1: Add the composable to the layout
- Open the Composable where you want the inline view to appear.
-
Locate the specific position within the UI (such as inside a
LazyColumn) where you want the campaign to appear. -
Insert the
GranifyInlineComposableclass into the layout:
LazyColumn {
items(cartItems.intValue) { index ->
val product = Cart.items.keys.elementAt(index)
val quantity = Cart.items.values.elementAt(index)
key(product.sku) {
GranifyInlineComposable(
GranifyInlineViewLabel(
"aboveCartItem",
product.productId,
product.sku
)
)
}
Card(product, quantity, context, { removeItem(product) })
}
}
4. Repeat this for every position on the page where an inline campaign is desired.
Step 2: Initialize the label
-
Initialize the
GranifyInlineViewLabelparameter within the Composable. - Assign a name string to the label, for example:
Code |
GranifyInlineViewLabel(name = "aboveProductPhoto", ...) |
3. Ensure this name is unique for that specific page location.
Step 3: Configure product details
Product pages:
-
Set the
productIdfield. This is required for any inline campaign located on a Product Page. -
Set the
skufield (optional). Use this if the location is specific to a variant . For example"Green Pants".
productId is required if sku is used. However, a productId can be specified without a sku.
Multiple label example:
Code |
|
Cart pages:
-
Set the
productIdfor any inline tied to a specific item. Include theskuif the product has multiple variants. -
Use only the
namefield for areas not tied to a specific product (for example, top of the page).
Step 4: Finalize integration
-
Compile a list of all
GranifyInlineComposablelocations you have added to the application. - Send this list to your Contextual Commerce account manager to create the campaigns.