This article describes how to implement Contextual Commerce inline campaigns in your Android application.
Step 1: Add the GranifyInlineView to the layout
Adding a
GranifyInlineView requires the following steps:
-
Open your layout file. To support inline campaigns, you will need to add a
GranifyInlineViewto every position on a page where you want an inline to appear. -
The
GranifyInlineViewclass extendsFrameLayoutand can be added to your user interface in the same way. -
Set the
layout_heightto 0 so it is not initially visible.
XML example (recommended constraints):
XML |
<com.granifyinc.granifysdk.campaigns.inlineView.GranifyInlineView android:id="@+id/granifyInlineViewBelowProductImage" android:layout_width="match_parent" android:layout_height="0dp" app:layout_constraintBottom_toTopOf="@+id/colour_spinner" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/productPageImageView" /> |
Android
ListView layouts are not supported for inlines due to the remeasuring of the ListView and its items on every animation frame. RecyclerView can be used as an alternative.
Step 2: Set expand and collapse handlers
Contextual Commerce requires clients to pass in two handlers in the
onCreate() method of the current activity:
-
An expand handler of type
GranifyInlineViewExpanderthat will expand the view, allowing an inline campaign to appear. -
A collapse handler of type
GranifyInlineViewCollapserthat will collapse the view back to its initial state (height = 0px). -
Pass these handlers through
GranifyInlineView.setExpandHandlerandGranifyInlineView.setCollapseHandler.
Kotlin example:
Code |
|
The SDK handles the animation logic internally. Do not add any custom animation handling to the view or its parent layout.
Step 3: Configure the label
GranifyInlineViewLabel identifies unique locations on a page and must not be duplicated within the same page.
Product pages:
-
Set the
productIdfield. This is required when the GranifyInlineView is located on a product page. -
Set the
skufield (optional). This is required when the view is associated with a specific productID/sku combination.
Example:
Code |
GranifyInlineView(name="aboveProductPhoto", productId="Pants", sku="Green") |
Cart pages:
-
Set the
productIdfor any inline tied to a specific item. -
Use only the
namefield for areas not tied to a specific product (for example at the top of the page).
Step 4: Finalize integration
Follow these steps to complete the implementation process:
-
Compile a list of all
GranifyInlineViewLabellocations you have added to the application. - Send this list to your Contextual Commerce account manager to create inline campaigns.
Do not change these label names after this point without notifying your Contextual Commerce account manager, as doing so will break live campaigns.