Test inline campaigns (Jetpack Compose)

This section describes how to validate your integration by forcing inline campaigns to appear in specific locations, ensuring that the component's expansion and collapse behavior does not interfere with your existing UI layouts. 

he Contextual Commerce SDK provides a method Granify.overrideGranifyInlineView which forces the SDK to use specific locations for display during testing.

Step 1: Translate labels to JSON

  1. Use snake_case keys. Convert Kotlin parameters (productId) to snake_case JSON keys (product_id). 
  2. Target specific products. Include exact product_id and sku values to test specific items.
  3. Use wildcards for general testing. Set product_id and sku to null to match any label by name, regardless of the product.
  4. Verify dependencies. Ensure product_id is included whenever a sku is provided. 
Note: You can also use a partial wildcard by setting sku to null while providing a specific product_id. This targets any label on that product, regardless of the specific SKU.

Conversion example:

Kotlin label
Code
GranifyInlineViewLabel(name="aboveProductPhoto", productId="Pants", sku="Green")

JSON equivalent (specific):

JSON
[JSON]  {"name": "aboveProductPhoto", "product_id": "Pants", "sku": "Green"}

JSON equivalent (wildcard): 

JSON
{"name": "aboveProductPhoto", "product_id": null, "sku": null}

Step 2: Format the JSON array

The SDK expects the input to be an array of labels. To do this follow these instructions: 
  1. Enclose objects in brackets. Wrap the input in [] to form a JSON array, even when testing a single location.
  2. Order labels by priority. Place the highest priority label first. The SDK selects the first match found on the page.
  3. Format as a String. Escape quotes or use Kotlin raw strings to ensure valid JSON formatting.
Code example:
Code
val overrideLabelString: String = """
  [
      {"name": "aboveProductPhoto", "product_id": null, "sku": null},
      {"name": "belowProductPhoto", "product_id": null, "sku": null},
      {"name": "belowAddToCartButton", "product_id": null, "sku": null}
  ]
"""

Step 3: Call the override method

Follow these steps to pass your JSON string to the override method and lock the SDK into testing mode:

  1. Pass the JSON string to the SDK. Call Granify.overrideGranifyInlineView(label: String?)with your formatted string.
  2. Add a text box to your debug menu to pass input to this method. This enables testing different locations without recompiling.
Method call:
Code
Granify.overrideGranifyInlineView(overrideLabelString)

Step 4: Verify the UI

After the override is set, verify the behavior in the app by following these steps:
  1. Force a campaign match. Trigger a specific inline campaign using the ID provided by Contextual Commerce during installation.
  2. Navigate to the target page. Open the page containing the added composable.
  3. Observe the behavior. Verify the campaign appears in the first matching location from the JSON list and that the UI handles the insertion gracefully.
Inline campaigns are not affected by restricted states. They will not be hidden while in a restricted state. 

Step 5: Reset testing mode

When testing is complete, you must disable the override to return to standard SDK behavior by following this instruction:

Call the override method with null. Passing null resets the SDK to its default behavior, where Contextual Commerce automatically selects the best location.

Reset call:
Code
Granify.overrideGranifyInlineView(null)
  
Provide feedback button