To integrate Bazaarvoice Contextual Commerce into your Android app, you will install, initialize, and configure the Contextual Commerce SDK to establish a connection between your app and Bazaarvoice. This article describes how to prepare the Contextual Commerce SDK to ensure basic functionality before proceeding with the full implementation.
In this phase, you will:
- Include the SDK framework
- Start the SDK using your site's configuration
- Send page view and order data to Bazaarvoice
- Send group assignment data to your analytics platform
Install the SDK
Add the GranifySDK library to your Android Studio project so it can interact with your app. This ensures the SDK is included in your build, authorized to run on Android devices, and ready to be activated in the next step.
-
Configure your project's repository
-
Open the Project-level
build.gradlefile -
Locate the
allprojectsblock -
Add a local Maven repository that points at your unzipped
GranifyAndroidSDKfolder:
Groovyallprojects { repositories { maven { url "<path to GranifyAndroidSDK folder>" } ... } }
-
Open the Project-level
-
Add the Granify SDK dependency
-
Open the app-level
build.gradlefile -
In the dependencies section, add the following:
Groovydependencies { ... implementation 'com.granifyinc:granifysdk:<current_version>' ... }
-
Replace the placeholder with the specific SDK version folder name. Go to
GranifyAndroidSDK/com/granifyinc/granifysdk/and locate the folder named in theX.Y.Zformat. You can also openmaven-metadata-local.xmland locate the version string within the<release>tags:<release>X.Y.Z</release>
-
Open the app-level
-
Sync your project
- Open Android Studio
- Select Sync Now when prompted, or select File>Sync Project with Gradle Files
- Download the SDK and integrate it into your app
Activate the SDK
The GranifySDK stays inactive until you turn it on. This gives you the control to activate or disable Contextual Commerce without making any major code changes. In this step, you will collect the configuration details that define how the SDK should recognize your app and direct shoppers to the right screen. Then, pass that configuration to the SDK to activate it.
-
Collect required information
Before you can activate the SDK, collect the following data points that will define how the SDK will recognize and interact with your app:
-
Site ID
The unique identifier for your site within the Contextual Commerce system. To obtain your site's identifier, reach out to your account manager.
-
Child site ID (Optional)
If you manage multiple brands or sites within your app, child site IDs let Contextual Commerce separate data and perform site-specific configuration overrides.
-
Application context
Your application context that will be used to generate a preference file named Granify.
-
Code version
Your application's version string, for example
1.3.0.
-
For more information about the required information, refer to Configuring Granify.
-
Create a configuration object
Once you have collected the required information above, gather it into a configuration object. This object tells the SDK how your app is structured and how to handle navigation between screens.
The following is an example of a configuration object with placeholder values:
Codeval config = GranifyConfiguration( applicationContext = activity, siteId = SiteIdentifier("ABC12"), childSiteId = SiteIdentifier("XYZ12"), codeVersion = "1.3.0" ) -
Call the Activate method
Activate the SDK by calling the
activateGranifymethod in your application's startup flow. For more information about the Activate method, refer to the activateGranify article.
CodeGranify.activateGranify(config)
Set up the Group Assignment event handler
In this step, you will register an event handler that is triggered every time a shopper is assigned a group and then send the group assignment directly to your analytics platform without any modifications.
subscribeGroupAssigned before you call activateGranify.If the SDK activates and assigns a group before the client subscribes, the client will miss the group assignment event.
The Group Assignment event categorizes every shopper into one of two groups:
-
Test group
Shoppers who are eligible to receive campaigns
-
Control group
Shoppers who are not eligible to receive campaigns and create a baseline for performance metrics
-
Subscribe to Group Assigned event
Notify your app every time Contextual Commerce assigns a shopper to a group. Call the
subscribeGroupAssigned(handler:)method to register the callback that will capture group assignment data. For more information, refer to the subscribeGroupAssigned article. -
Forward group assignment data to your analytics
Forward the raw group assignment data directly to your analytics platform without any modifications to ensure your performance metrics are based on unaltered data. Since every client's analytics setup can be unique, this step is intentionally flexible.
-
Identify your analytics platform and refer to their documentation to determine which method or API call they use to track events.
-
Within your callback function, insert the code that will forward the group assignment data to your analytics platform.
-
Test your integration to ensure group assignment data is correctly flowing into your analytics platform.
-
Implement basic tracking functionality
For Contextual Commerce to make accurate decisions and deliver the right messages at the right time, it must know exactly what the shopper is viewing as they move through your application and whether they are placing orders.
In this step, you will set up the following methods that will enable basic tracking functionality needed to prepare your SDK setup for QA review:
-
trackPageView
Notifies Contextual Commerce every time the shopper navigates to a new page or view within your app
-
trackOrder
Captures every order shoppers successfully place which is essential for measuring Contextual Commerce performance
Track page views
The Contextual Commerce SDK cannot automatically detect in-app page changes. Track the active page to ensure Contextual Commerce can show the right campaigns on the right pages.
Call the trackPageView
method to notify Contextual Commerce every time:
- The application starts
- The application resumes from background
- A session starts
- A screen is presented to the user, on any navigation path change
Window.Callback must be made before calling trackPageView, or Contextual Commerce won't capture touch events.
The method requires you to provide information about the page being viewed:
pageIdentifier: The type of page being viewed and its unique pathactivity: Your currentFragmentActivity, required for displaying campaign fragments and capturing touch eventsnavigator: An implementation of theNavigatorthat the SDK uses to invoke in-app navigationsafeArea: A main-thread closure returningSliderMarginsto define a safe slider rendering area that automatically updates during orientation or activity changes to prevent UI obstruction
scrollableView: The scrollable area that shows what part of the page the shopper is viewing, if using a views-based UI-
pageRestrictionState: A RestrictionState indicating whether or not the page is eligible to have a slider displayed on it. This parameter is not required, and defaults toUNRESTRICTED - home: The home page of the app.
- product: A page that represents a single product that might have multiple variations.
- collection: A page that contains multiple products or child categories that users can select.
- ensemble: A page that lists a small group of products, similar to a collection or a complete outfit, but allows for the products to be added to the cart.
- search: A page that allows search (if that is a dedicated page) and the page that displays the search results.
- blog: A topical, informational article that is not specifically related to purchasing products.
- cart: A page that lists the contents of the cart, allows the shopper to manage their cart and continue to complete their purchase.
- checkout: A page that allows the shopper to complete their purchase.
- flights: A special form of the product page used specifically for flight booking sites.
- account: An admin page that allows the shopper to view past purchases and manage their account.
- login: A page that allows the user to sign in or sign out.
- info: A permanent, informational page about the site, such as "About Us."
- guide: A page that helps or guides shoppers through the purchase journey.
- video: A page that is dedicated to video content.
- other: Any page to which a specific page type does not apply.
- receipt: A page that is shown after a completed checkout.
- wishlist: A page that shows a current wishlist, or list of wishlists.
Contextual commerce recognizes the following types of pages:
For more information about the trackPageView method, refer to the trackPageView section of the class reference article.
The following is an example of the trackPageView method for a cart page:
Code |
|
Track orders
Accurate order tracking is necessary for testing campaign functionality and calculating performance metrics. Given some apps have non-standard checkout flows, integrate this method in a way that fits your app so that every order event is forwarded.
-
Determine all the points in your order process where an order is finalized.
-
Call the
trackOrdermethod at these points to ensure every order is tracked. -
Verify that order data accurately reflects your internal metrics.
trackOrder method is only called after the order is fully confirmed.
The method requires you to provide information about the product(s) being ordered:
sku: The unique identifier for the specific product variantproductId: The unique identifier for the parent product groupingtitle: The display name of the productprice: The product's current selling price, including any discountsregularPrice: The product's standard price before any discounts are appliedimage: The URL pointing to the product's primary image
To learn more about optional parameters, refer to the Product topic.
For more information about tracking orders, refer to the trackOrder article.
The following is an example of the trackOrder method:
Code |
|