---
title: "Prepare to test campaigns (Android)"
id: "android-test-campaigns"
project: "Contextual Commerce"
url: "https://docs.bazaarvoice.com/articles/contextual-commerce/android-test-campaigns"
updated: 2026-10-15T09:12:58Z
---

# Prepare to test campaigns \(Android\)

In this phase, you will:

* Implement all required API methods to support campaign testing
* Create a hidden debug menu that enables internal testing and troubleshooting
* Learn how to interpret Contextual Commerce logs

## Set up required methods

Preparing your SDK for data validation included setting up methods to track page views and orders.

To enable and test campaign functionality, you must implement the following additional methods:

* [Track product](/articles/contextual-commerce/android-test-campaigns/a/h3__2121860558) (`trackProduct`)
* [Track cart state](/articles/contextual-commerce/android-test-campaigns/a/h3_335128847) (`trackCart`)
* [Set the currently viewed product](/articles/contextual-commerce/android-test-campaigns/a/h3_1624260497)​ (`setCurrentProduct`)
* [Show campaigns](/articles/contextual-commerce/android-test-campaigns/a/h3_1643826900) (`showCampaign`)

###  Track product

Track the products shoppers view, and all their available variations, to ensure campaigns match them with the most relevant products and promotions.

The `trackProduct` method should be called immediately after `trackPageView` on any product page load, for example:

* On application launch to a product page
* On application resume to a product page
* On any in-app navigation that presents a product page

The method requires you to provide information about the products being viewed:

* `products`: A list of products
* `carter`: This interface includes the `addCurrentProductToCart` function. You must implement this function to enable widgets to add products to a customer's cart when a user selects **Add to cart**.

For more information about the `trackProduct` method, refer to the `trackProduct`  [class reference article.](/articles/contextual-commerce/packages/a/TrackProduct)

The following is an example of the `trackProduct` method:
 
Code

```
class ProductCarter(public var currentProduct: Product) : Carter {
    override fun addCurrentProductToCart() {
        Cart.addToCart(currentProduct) // example code for adding product to your cart
        // make sure to also call `Granify.trackCart` to keep our SDK in sync with your cart contents
    }
}

val currentProductCarter = ProductCarter(currentlySelectedProduct)
Granify.trackProduct(
  products = listOf(
    Product(...),
    ... // other variants of the product
  ),
  carter = currentProductCarter
)

// When selecting a new variant:
currentProductCarter.currentProduct = newlySelectedProduct
Granify.setCurrentProduct(
  newlySelectedProduct.sku,
  newlySelectedProduct.productId
)
```


###  Track cart state

Track products in the shopper's cart to enable cart-specific campaigns types, like abandoned cart reminders.

The `trackCart` method should be called:

* On application launch, even if the cart is empty
* After any cart update
    * Item added, removed, or quantity changed
    * Purchase complete and cart cleared
    * Cart synced from another device

The method requires you to provide information about the products currently in the shopper's cart:

* `items`: A map of all items in the shopper's cart and their quantities.

For more information about the `trackCart` method, refer to the `trackCart` [class reference article.](/articles/contextual-commerce/packages/a/TrackCart)

The following is an example of the `trackCart` method:
 
Code

```
Granify.trackCart(
    mapOf(
        product1 to 1,
        product2 to 4,
        product3 to 2
    )
)
```


###  Set the currently viewed product 

Track the precise product variation the shopper has chosen to ensure campaigns make personalized product recommendations based on the exact SKU the shopper is viewing.

The `setCurrentProduct` method should be called immediately after each `trackProduct` and whenever the shopper changes the chosen item on a product page, for example:

* On application launch to a product page
    * Pass the default selected product SKU
* On application resume on a product page
    * Pass the selected product SKU when the view loads
* From navigation to a product page
    * Pass the default selected product SKU
* On user changing the selected product variation like size or color
    * Pass the new selected product SKU

The method requires you to provide information about the product variation the shopper has selected:

* sku: The SKU of the currently selected product variation. Must match one of the `sku` values in your `trackProduct` call.
* `productId`: The parent product ID. Must match the `productId` from your `trackProduct` call.

For more information about the `setCurrentProduct` method, refer to the `setCurrentProduct` [class reference article.](/articles/contextual-commerce/packages/a/SetCurrentProduct)

The following is an example of the `setCurrentProduct` method:
 
Code

```
Granify.setCurrentProduct(sku = "myprod_001", productId = "myprod")
```


###  Show campaigns

Set up the `showCampaign` method to enable internal campaign testing in your app. This method requests a specific campaign to display within your environment so you and the Contextual Commerce QA team can preview and validate campaigns before they go live. The `showCampaign` method can be called any time from your debug menu after you call `activateGranify`.

The method requires you to provide information about the products currently in the shopper's cart:

* ```campaignId`: The id of the campaign to display. Reach out to your Account Manager for your specific campaign ID.

For more information about the `showCampaign` method, refer to the `showCampaign` [class reference article.](/articles/contextual-commerce/packages/a/ShowCampaign)

The following is an example of the `showCampaign` method:


Code

```
Granify.showCampaign(campaignId = "1234")
```


##  Create a debug menu

A hidden debug menu allows the Contextual Commerce QA team, and your internal testers, to trigger specific tests directly within your app without disrupting users or modifying production code. This menu is intended exclusively for internal testing and should be hidden from shoppers.

### Recommended implementation

Your debug menu should be:

* Available within **QA** or **Test** builds of your app
* Accessible through a special gesture or interaction
    * For example, triple-tap on a particular screen or hold down a button for five seconds before the "developer" UI appears
* Clearly distinguished from any regular app operations

Your debug menu UI should include:

* A text field for entering the specific Campaign ID associated with the test campaign
* A way to manually trigger the `showCampaign` method

### Analyze logs

The Contextual Commerce SDK generates logs at various levels (debug, info, call, warn, and error) during its operation. To simplify log analysis, logs will always start with the prefix `[Granify]` so you can filter to relevant entries.

The following log entry example displays in your logs. Review the entry for error codes:

Code

```
[Granify] 🟡 warn [consume(data:):65] Force Matching Failure: CampaignFilter::7641 failed has_cart: ["+"] for value: false
```
 
Interpreting this example:

* Campaign ID `7641` was triggered using the `showCampaign` method, but the SDK couldn't display it.
* The campaign has an unmet requirement that the shopper must have items in their cart.
* Specifically, `has_cart: ["+"]` means "requires at least one cart item," and `value: false` indicates the current shopper's cart was empty when the campaign was triggered.
[![Provide feedback button](/resources/Storage/contextual-commerce/bv-global/topic-footer-2026/provide-feedback-button.png)](https://docs.google.com/forms/d/1qGZ5rApqDrXO_j6vNzcDihDAOPMEjmUr1alHvcEIbQU/edit)