# Segmentify Android SDK > Send events and show recommendations, search results and push notifications in your Android app with the Segmentify Android SDK. import { Card, CardGrid, LinkCard } from '@astrojs/starlight/components'; ## What the SDK does Page and product views, basket and checkout steps, wishlist, search and user events, each with one method call. Event methods hand back the recommendation widgets set up in your Segmentify panel, ready for you to render. Instant search and faceted search results, with click tracking. Registers device tokens and reports views and clicks of push campaigns. ## Start here ## Related documentation --- # Installation > Add the Segmentify Android SDK to your project. The Segmentify Android SDK supports **Android 7.0 (API level 24)** and higher. ## Add the SDK Add Maven Central to your project-level `build.gradle`, if it is not there already: ```groovy buildscript { repositories { mavenCentral() } } ``` Then add the SDK to your app module's `build.gradle`. Replace `x.y.z` with the latest version on [Maven Central](https://mvnrepository.com/artifact/com.segmentify.sdk/android): ```groovy dependencies { implementation 'com.segmentify.sdk:android:x.y.z' } ``` The SDK needs the `INTERNET` and `ACCESS_NETWORK_STATE` permissions. Its own manifest declares them, so the manifest merger adds them to your app; you do not need to add them yourself. ## What you need from Segmentify Have these ready before you configure the SDK. The API key and data center are under **Settings > Integrations** in the Segmentify panel. | You need | Example | Used for | | --- | --- | --- | | API key | `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx` | Identifies your account. | | Data center URL | `https://gandalf-eu.segmentify.com` | The host your account lives on. | | Domain | `www.yourdomain.com` | The domain registered for your account. The SDK sends it with every request. | | Push data center URL | `https://gimli-eu.segmentify.com` | Only if you use push notifications. | Data centers by region: | Region | Data center URL | Push data center URL | | --- | --- | --- | | Türkiye | `https://per2.segmentify.com` | `https://psh2.segmentify.com` | | Europe | `https://gandalf-eu.segmentify.com` | `https://gimli-eu.segmentify.com` | | Latin America | `https://gandalf-br.segmentify.com` | `https://gimli-br.segmentify.com` | Use the one shown in your panel. An API key sent to another data center is not found. Next: [Configuration](/getting-started/configuration/). --- # Configuration > Initialise the Segmentify Android SDK, and set session length, logging and the fields every event shares. ## Initialise the SDK Configure the SDK once, when the app starts, before sending any event. ```kotlin import android.app.Application import com.segmentify.segmentifyandroidsdk.SegmentifyManager class MyApp : Application() { override fun onCreate() { super.onCreate() SegmentifyManager.config( this, "YOUR_API_KEY", "https://gandalf-eu.segmentify.com", // your data center URL "www.yourdomain.com" // the domain registered for your account ) } } ``` Register the class in `AndroidManifest.xml` with `android:name=".MyApp"` on the `` element. From Java, `SegmentifyManager` is a Kotlin object: call it as `SegmentifyManager.INSTANCE.config(...)`. | Parameter | Description | | --- | --- | | API key | Your Segmentify API key. | | Data center URL | The full URL of your data center, starting with `https://`. | | Domain | The domain registered for your Segmentify account. It is sent as the `Origin` of every request and must match the account, or requests are rejected. | - `config` does nothing and logs an error if any of the three values is blank. - Call `setSessionKeepSecond` and `logStatus` **after** `config`. Before it, they have no effect. ## Options ```kotlin SegmentifyManager.setSessionKeepSecond(86400) // session length in seconds; 86400 is the default SegmentifyManager.logStatus(true) // print SDK logs to Logcat SegmentifyManager.setAppVersion("3.2.1") // optional: your app version, sent with events ``` | Option | Default | Description | | --- | --- | --- | | Session length | `86400` seconds (24 hours) | How long a session ID is kept before a new one is created. | | Logging | off | Prints what the SDK does, including why an event was not sent. | ## User and session IDs You do not create user or session IDs. On first launch the SDK asks Segmentify for a user ID and a session ID and stores them in shared preferences. The user ID is kept; the session ID is replaced when the session length has passed. ## Fields every event shares Every event model has these properties. Set them on each event you send. ```kotlin val page = PageModel() page.category = "Home Page" page.lang = "EN" page.currency = "EUR" page.testMode = true // remove before going live ``` | Property | Description | | --- | --- | | `lang` | Language of the content, for example `EN`. Must be a language configured for your account. Set it on every event: when it is missing, `EN` is assumed, and accounts without English get no result. | | `currency` | Currency of the prices, for example `EUR`. Must be a currency configured for your account. | | `region` | Region of the user, if your account uses regions. | | `params` | Custom key-value pairs to send with the event. | | `testMode` | `true` marks a test event. Test events are answered by test-mode campaigns and kept apart from live data. | | `pageUrl` | URL or deep link of the screen. | ## Switching account at runtime If one app serves several Segmentify accounts (for example one per country), change the configuration when the user switches: ```kotlin SegmentifyManager.setConfig("OTHER_API_KEY", "https://gandalf-eu.segmentify.com", "www.otherdomain.com") ``` Next: [Your first integration](/getting-started/first-integration/). --- # Your first integration > A screen-by-screen plan for a first Segmentify Android SDK integration, with a checklist for going live. This page is the order to build things in. Each step links to the page with the code. ## How it works Your app tells Segmentify what the user does by calling one SDK method per action. Segmentify answers some of those calls with **recommendations**: lists of products to show on that screen, as set up in your Segmentify panel. So the same calls both collect data and fetch content. Methods that can return recommendations take `SegmentifyCallback`, an interface with a single `onDataLoaded(data: T)` method. Methods that only record something (basket changes, clicks, user events) return nothing. ## Step 1: Install and configure 1. [Install the SDK](/getting-started/installation/). 2. [Configure it](/getting-started/configuration/) at app start with your API key, data center URL and domain. 3. Turn on logs while you develop. ## Step 2: Send a page view from every screen Call `sendPageView` when a screen opens, with the screen's `category`. This is the minimum integration: it identifies visitors and lets campaigns target screens. ```kotlin import com.segmentify.segmentifyandroidsdk.model.PageModel import com.segmentify.segmentifyandroidsdk.model.RecommendationModel import com.segmentify.segmentifyandroidsdk.utils.SegmentifyCallback val page = PageModel() page.category = "Home Page" page.lang = "EN" page.currency = "EUR" SegmentifyManager.sendPageView(page, object : SegmentifyCallback> { override fun onDataLoaded(data: ArrayList) { // data holds the recommendation widgets to show on this screen } }) ``` See [Page View](/events/page-view/) for the category names. ## Step 3: Add the shopping events | When | Call | Page | | --- | --- | --- | | A product screen opens | `sendProductView` (and `sendPageView` with `Product Page`) | [Product View](/events/product-view/) | | A product is added to or removed from the basket | `sendAddOrRemoveBasket` | [Basket and Checkout](/events/basket-and-checkout/) | | The basket screen opens | `sendViewBasket` | [Basket and Checkout](/events/basket-and-checkout/) | | An order is completed | `sendPurchase` | [Basket and Checkout](/events/basket-and-checkout/) | These four are what recommendations and revenue reports are built on. Get them right before adding anything else. ## Step 4: Show recommendations Render the recommendations returned to your callbacks, and report when a widget is shown and when a product in it is tapped. See [Recommendations](/recommendations/). ## Step 5: Add what your app needs | Feature | Page | | --- | --- | | Sign-up, sign-in, profile and consent | [User Events](/events/user/) | | Wishlist | [Wishlist](/events/wishlist/) | | Search | [Search](/events/search/) | | Banners | [Interactions and Banners](/events/interactions/) | | Your own triggers | [Custom Event](/events/custom-event/) | | Push notifications | [Push Notifications](/push-notifications/) | ## Go-live checklist - `testMode` is removed, or `false`, on every event. - `lang` and `currency` are set on every event and match your account. - `sendProductView` sends the real price, stock status, product URL and image. - `sendPurchase` is called once per order, with `orderNo`. - Product IDs are the same ones as in your product catalogue and on your website. - Logging is off in release builds. If an event does not arrive, see [Troubleshooting](/troubleshooting/). --- # Basket and Checkout > Report basket changes and the steps of the checkout funnel, from viewing the basket to a completed order. ## Basket changes Call `sendAddOrRemoveBasket` when a product is added to or removed from the basket. ```kotlin import com.segmentify.segmentifyandroidsdk.model.BasketModel val basket = BasketModel() basket.step = "add" // or "remove" basket.productId = "SKU-1001" basket.quantity = 1.0 basket.price = 135.0 basket.lang = "EN" basket.currency = "EUR" SegmentifyManager.sendAddOrRemoveBasket(basket) ``` A shorter form takes the values directly; here all four are required: ```kotlin SegmentifyManager.sendAddOrRemoveBasket("add", "SKU-1001", 1.0, 135.0) ``` | Property | Required | Description | | --- | --- | --- | | `step` | Yes | `add` or `remove`. | | `productId` | Yes | The product. | | `quantity` | Yes | How many were added or removed. | | `price` | Recommended | Unit price. | Without `step`, `productId` or `quantity` the event is not sent. ## Checkout steps The checkout methods all take the basket's total and its products. ```kotlin import com.segmentify.segmentifyandroidsdk.model.CheckoutModel val item = ProductModel() item.productId = "SKU-1001" item.price = 135.0 item.quantity = 1.0 val checkout = CheckoutModel() checkout.totalPrice = 135.0 checkout.productList = arrayListOf(item) checkout.lang = "EN" checkout.currency = "EUR" ``` Pass a `CheckoutModel` to these methods, as shown. `sendViewBasket` and `sendPurchase` also have shorter overloads that take `totalPrice` and `productList` directly. Then call the method for the step the user is on: ```kotlin SegmentifyManager.sendViewBasket(checkout, callback) // basket screen SegmentifyManager.sendCustomerInformation(checkout, callback) // address / customer step SegmentifyManager.sendPaymentInformation(checkout, callback) // payment step checkout.orderNo = "ORDER-98765" SegmentifyManager.sendPurchase(checkout, callback) // order completed ``` | Method | When | | --- | --- | | `sendViewBasket` | The basket screen opens. | | `sendCustomerInformation` | The user is on the customer or address step. | | `sendPaymentInformation` | The user is on the payment step. | | `sendPurchase` | The order is completed. | | Property | Required | Description | | --- | --- | --- | | `totalPrice` | Yes | Total of the basket or order. | | `productList` | Yes | The products, each with `productId`, `quantity` and `price`. | | `orderNo` | For purchase | Your order number. | ## Rules - Call `sendPurchase` **once per order**. Calling it again on a screen refresh counts the revenue twice. - `totalPrice` and the product prices are in the currency named by `currency`. - All four methods return recommendations to their callback, for example "you may also like" on the basket screen. --- # Custom Event > Send an event of your own to trigger Segmentify campaigns. Use a custom event for anything the standard events do not cover, such as a newsletter sign-up or a store-locator search. Campaigns in the panel can be triggered by its `type`. ```kotlin import com.segmentify.segmentifyandroidsdk.model.CustomEventModel val event = CustomEventModel() event.type = "newsletter-signup" event.lang = "EN" SegmentifyManager.sendCustomEvent(event, callback) // or, without extra fields SegmentifyManager.sendCustomEvent("newsletter-signup", callback) ``` | Property | Required | Description | | --- | --- | --- | | `type` | Yes | Your name for the event. Must match the name used in the panel. | | `params` | No | Extra values to send with the event. | The callback receives recommendations if a campaign answers the event. --- # Interactions and Banners > Report when a recommendation widget is shown, seen and clicked, and track banners. Segmentify measures a campaign by its interactions. Without them, widgets show up in your app but their reports stay empty. ## Widget interactions ```kotlin // the widget was returned and placed on the screen SegmentifyManager.sendImpression(recommendation.instanceId!!, recommendation.actionId!!) // the widget became visible to the user SegmentifyManager.sendWidgetView(recommendation.instanceId!!, recommendation.actionId!!) // the user tapped a product of the widget SegmentifyManager.sendClickView(recommendation.instanceId!!, product.productId!!) ``` | Method | When | `interactionId` | | --- | --- | --- | | `sendImpression` | The widget was returned and placed on the screen. | The `actionId` of the recommendation. | | `sendWidgetView` | The widget scrolled into view. | The `actionId` of the recommendation. | | `sendClickView` | The user tapped a product in the widget. | The product ID. | | `sendSearchClickView` | The user tapped a product in search results. | The product ID. | `instanceId` is always the ID of the campaign, taken from the recommendation or search response. Send an impression once per widget per screen load, not on every scroll. ## Banners If you use Segmentify's banner tracking, report the banners your app shows and the taps on them. ```kotlin import com.segmentify.segmentifyandroidsdk.model.BannerGroupViewModel import com.segmentify.segmentifyandroidsdk.model.BannerOperationsModel import com.segmentify.segmentifyandroidsdk.model.InternalBannerModel val banner = BannerOperationsModel() banner.group = "Home Page Slider" banner.title = "Summer Sale" banner.order = 1 SegmentifyManager.sendBannerImpressionEvent(banner) SegmentifyManager.sendBannerClickEvent(banner) val slide = InternalBannerModel() slide.title = "Summer Sale" slide.image = "https://cdn.yourdomain.com/banners/summer.jpg" slide.order = 1 slide.urls = arrayListOf("https://www.yourdomain.com/summer") val group = BannerGroupViewModel() group.group = "Home Page Slider" group.banners = arrayListOf(slide) SegmentifyManager.sendBannerGroupViewEvent(group) ``` | Method | When | | --- | --- | | `sendBannerGroupViewEvent` | A banner group (for example a slider) is shown, with the banners in it. | | `sendBannerImpressionEvent` | One banner became visible. | | `sendBannerClickEvent` | The user tapped a banner. | | `sendBannerUpdateEvent` | A banner's content changed. | `group` is the name of the banner area and must be the same in every event for that area. --- # Page View > Report every screen the user opens with sendPageView, and receive the recommendations for that screen. Send a page view each time a screen opens. The `category` says what kind of screen it is. ```kotlin import com.segmentify.segmentifyandroidsdk.model.PageModel import com.segmentify.segmentifyandroidsdk.model.RecommendationModel import com.segmentify.segmentifyandroidsdk.utils.SegmentifyCallback val page = PageModel() page.category = "Home Page" page.lang = "EN" page.currency = "EUR" SegmentifyManager.sendPageView(page, object : SegmentifyCallback> { override fun onDataLoaded(data: ArrayList) { // data holds the recommendation widgets to show on this screen } }) ``` ## Categories Use these names for the standard screens. They are what campaigns in the panel target. | `category` | Screen | | --- | --- | | `Home Page` | Home screen | | `Category Page` | A product listing. Also set `subCategory`. | | `Product Page` | A product's detail screen. Also send [Product View](/events/product-view/). | | `Search Page` | Search results | | `Basket Page` | Basket | | `Checkout Success Page` | Order confirmation | | `404 Page` | Content not found | For any other screen, use your own name, for example `Account Page`. ## Category screens ```kotlin val page = PageModel() page.category = "Category Page" page.subCategory = "Shoes > Sneakers" page.lang = "EN" page.currency = "EUR" SegmentifyManager.sendPageView(page, callback) ``` ## Properties | Property | Required | Description | | --- | --- | --- | | `category` | Yes | The screen type. Without it the event is not sent. | | `subCategory` | No | The category shown on a category screen. | Plus the [shared fields](/getting-started/configuration/#fields-every-event-shares). ## The result The callback receives a list of recommendation widgets for the screen. It is empty when no campaign targets it. See [Recommendations](/recommendations/). --- # Product View > Report a product detail screen with sendProductView. Keeps the product catalogue current and returns product-page recommendations. Send a product view when a product's detail screen opens. It does two jobs: it records the user's interest, and it updates the product (price, stock, image) in your Segmentify catalogue. ```kotlin import com.segmentify.segmentifyandroidsdk.model.ProductModel val product = ProductModel() product.productId = "SKU-1001" product.title = "Runner Sneakers" product.url = "https://www.yourdomain.com/runner-sneakers" product.image = "https://cdn.yourdomain.com/img/sku-1001.jpg" product.categories = arrayListOf("Shoes", "Sneakers") product.price = 135.0 product.oldPrice = 160.0 product.brand = "Acme" product.inStock = true product.lang = "EN" product.currency = "EUR" SegmentifyManager.sendProductView(product, object : SegmentifyCallback> { override fun onDataLoaded(data: ArrayList) { // recommendations for the product screen } }) ``` Send a [page view](/events/page-view/) with category `Product Page` for the same screen as well. ## Properties | Property | Type | Required | Description | | --- | --- | --- | --- | | `productId` | `String` | Yes | Your ID of the product. | | `title` | `String` | Yes | Product name. | | `url` | `String` | Yes | Product page URL. | | `image` | `String` | Yes | Main image URL. | | `price` | `Double` | Yes | Current price. | | `category` | `String` | One of the two | A single category. | | `categories` | `ArrayList` | One of the two | The category path. Set either `category` or `categories`, not both. | | `oldPrice` | `Double` | No | Price before discount. | | `brand` | `String` | No | Brand name. | | `inStock` | `Boolean` | No | Whether the product can be bought. | | `mUrl` | `String` | No | Mobile product page URL. | | `imageXS`, `imageS`, `imageM`, `imageL`, `imageXL` | `String` | No | Image URLs in other sizes. | | `gender` | `String` | No | Target gender. | | `colors`, `sizes`, `labels` | `ArrayList` | No | Product attributes. | | `noUpdate` | `Boolean` | No | `true` sends the view without updating the product in the catalogue. | Plus the [shared fields](/getting-started/configuration/#fields-every-event-shares). ## Rules - The event is **not sent** if `productId`, `title`, `url`, `image` or `price` is missing, if both `category` and `categories` are set, or if neither is. The SDK logs which one. - `productId` must be the same ID your product feed and website use for the product. - `oldPrice` is only used when it is greater than `price`. - Send `currency` with the price. --- # Search > Get instant and faceted search results from Segmentify and report clicks on them. Segmentify Search has two modes. **Instant search** answers while the user types, in the search box. **Faceted search** returns a full results screen with filters, sorting and paging. ## Instant search Send the current text each time it changes. Send an empty `query` when the search box opens, to get the "before search" content such as popular products and last searches. ```kotlin import com.segmentify.segmentifyandroidsdk.model.SearchPageModel import com.segmentify.segmentifyandroidsdk.model.SearchResponseModel val search = SearchPageModel() search.query = "sneak" // empty string before the user types search.lang = "EN" search.currency = "EUR" SegmentifyManager.sendSearchPageView(search, object : SegmentifyCallback { override fun onDataLoaded(data: SearchResponseModel) { // data.products, data.keywords, data.categories, data.brands, data.lastSearches } }) ``` The response holds `products`, plus `keywords`, `categories`, `brands`, `categoryProducts`, `brandProducts` and `lastSearches` to build the search box's sections. ## Faceted search ```kotlin import com.segmentify.segmentifyandroidsdk.model.faceted.Filter import com.segmentify.segmentifyandroidsdk.model.faceted.Ordering import com.segmentify.segmentifyandroidsdk.model.faceted.SearchFacetedPageModel import com.segmentify.segmentifyandroidsdk.model.faceted.SearchFacetedResponseModel val search = SearchFacetedPageModel() // type is "faceted", trigger is "page" by default search.query = "sneakers" search.trigger = "keyword" // what caused the search: keyword, filter, order or page search.ordering = Ordering("SMART_SORTING", 1) search.filters = listOf(Filter("brand", listOf("Acme"))) search.lang = "EN" search.currency = "EUR" SegmentifyManager.sendFacetedSearchPageView(search, object : SegmentifyCallback { override fun onDataLoaded(data: SearchFacetedResponseModel) { // data.products, data.facets, data.meta, data.banners, data.instanceId } }) ``` | Property | Description | | --- | --- | | `query` | The text searched. | | `trigger` | What caused this request: `keyword` (a new search), `filter` (a filter changed), `order` (the sort changed) or `page` (another page). | | `ordering` | The page number, starting at 1, and the sort. | | `filters` | The selected filters, each a facet name and its selected values. | The response holds `products`, `facets` (the available filters and their values), `meta` (paging and totals), `banners` and the `instanceId` of the search campaign. ## Report clicks When the user taps a product in search results, report it with the search campaign's `instanceId` and the product ID: ```kotlin SegmentifyManager.sendSearchClickView(instanceId, "SKU-1001") ``` Report when the results are shown with `sendImpression` and `sendWidgetView`, as for recommendation widgets. See [Interactions and Banners](/events/interactions/). ## Clear a last search When the user deletes an entry from their last searches: ```kotlin SegmentifyManager.clearLastSearchHistory("sneakers") ``` --- # User Events > Tell Segmentify who the user is: sign-up, sign-in, profile changes, consent and channel subscriptions. There are two sets of user methods. Use the **CDP user events** in new integrations. The older **user operations** are still supported. ## CDP user events Each method takes the user's profile. ```kotlin import com.segmentify.segmentifyandroidsdk.model.CdpEventsPayload import com.segmentify.segmentifyandroidsdk.model.Consent val profile = CdpEventsPayload( email = "jane@example.com", phone = "905551234567", username = "jane", fullName = "Jane Doe", gender = "female", emailConsent = Consent.SUBSCRIBED, custom = mapOf("loyaltyLevel" to "gold") ) SegmentifyManager.registerUser(profile) // after sign-up SegmentifyManager.loginUser(profile) // after sign-in SegmentifyManager.identityUser(profile) // when the profile is known or has changed SegmentifyManager.userTraits(profile) // to update traits SegmentifyManager.logoutUser(profile) // after sign-out ``` | Property | Type | Description | | --- | --- | --- | | `email`, `phone`, `username` | `String?` | Identifiers of the user. | | `fullName`, `gender` | `String?` | Profile fields. | | `source` | `String?` | Where the data came from. | | `emailConsent`, `smsConsent`, `whatsappConsent`, `callConsent` | `Consent?` | `SUBSCRIBED`, `UNSUBSCRIBED` or `NOT_SET`. | | `custom` | `Map?` | Your own attributes. | | Method | When | | --- | --- | | `registerUser` | The user completed sign-up. | | `loginUser` | The user signed in. | | `identityUser` | The app knows who the user is, or the profile changed. Sent only when the profile differs from the last one sent, so it is safe to call often. | | `userTraits` | To update profile traits. | | `logoutUser` | The user signed out. | Behaviour to know: - An empty profile is not sent. - If you set at least one consent field, the others are sent as `NOT_SET`. If you set none, no consent is sent and stored consents are left as they are. ## Channel subscriptions Report when a user subscribes to, or unsubscribes from, a channel. ```kotlin import com.segmentify.segmentifyandroidsdk.model.Channel import com.segmentify.segmentifyandroidsdk.model.Purpose import com.segmentify.segmentifyandroidsdk.model.SubscribeProperties import com.segmentify.segmentifyandroidsdk.model.UnsubscribePayload SegmentifyManager.subscribeUser(SubscribeProperties.Email("jane@example.com", listOf(Purpose.MARKETING))) SegmentifyManager.subscribeUser(SubscribeProperties.Sms("905551234567", listOf(Purpose.MARKETING))) SegmentifyManager.subscribeUser(SubscribeProperties.Whatsapp("905551234567", listOf(Purpose.MARKETING))) SegmentifyManager.subscribeUser(SubscribeProperties.Call("905551234567", listOf(Purpose.MARKETING))) SegmentifyManager.subscribeUser(SubscribeProperties.AppPush(fcmToken)) SegmentifyManager.unsubscribeUser(UnsubscribePayload(channel = Channel.EMAIL, email = "jane@example.com")) SegmentifyManager.unsubscribeUser(UnsubscribePayload(channel = Channel.SMS, phone = "905551234567")) ``` `Purpose` is `MARKETING`, `TRANSACTIONAL`, `PERSONALISATION` or `ALL`. ## User operations (legacy) ```kotlin import com.segmentify.segmentifyandroidsdk.model.UserModel val user = UserModel() user.email = "jane@example.com" user.externalId = "jane" // your username or user ID user.fullName = "Jane Doe" SegmentifyManager.sendUserRegister(user) // sign-up SegmentifyManager.sendUserLogin(user) // sign-in SegmentifyManager.sendUserUpdate(user) // profile change SegmentifyManager.sendUserLogout("jane", "jane@example.com") // sign-out ``` `sendUserRegister`, `sendUserLogin` and `sendUserUpdate` need `email`; without it they log an error and send nothing. Do not send both sets for the same action. Pick one per integration. --- # Wishlist > Report wishlist additions, removals and views. ```kotlin SegmentifyManager.sendWishlistAdd("SKU-1001") SegmentifyManager.sendWishlistRemove("SKU-1001") SegmentifyManager.sendWishlistDetail("SKU-1001") SegmentifyManager.sendWishlistViewFavorites(listOf("SKU-1001", "SKU-2002")) ``` To set `lang`, `currency` or `params`, build a `WishlistModel` and call `sendWishlist`: ```kotlin import com.segmentify.segmentifyandroidsdk.model.WishlistModel val wishlist = WishlistModel() wishlist.step = "add" // add, remove, detail or view-favorites wishlist.productId = "SKU-1001" wishlist.lang = "EN" SegmentifyManager.sendWishlist(wishlist) ``` | Step | Method | Needs | | --- | --- | --- | | `add` | `sendWishlistAdd` | `productId` | | `remove` | `sendWishlistRemove` | `productId` | | `detail` | `sendWishlistDetail` | `productId`. The user opened a product from the wishlist. | | `view-favorites` | `sendWishlistViewFavorites` | `favoritesList`, the product IDs in the wishlist. May be empty. | The event is not sent when the step is not one of the four, or when the field it needs is missing. --- # Push Notifications > Register the device with Segmentify and report views and clicks of push campaigns. Segmentify sends push campaigns through Firebase Cloud Messaging (FCM). Your app receives and displays the notifications; the SDK registers the device and reports what happens to each notification. ## Set up Set the push data center **before** `config`: ```kotlin SegmentifyManager.setPushConfig("https://gimli-eu.segmentify.com") // your push data center URL SegmentifyManager.config(this, "YOUR_API_KEY", "https://gandalf-eu.segmentify.com", "www.yourdomain.com") ``` Add Firebase Cloud Messaging to your app as described in the [Firebase documentation](https://firebase.google.com/docs/cloud-messaging/android/client). The SDK does not include Firebase; your app receives the messages and passes them on. ## Register the device token Send the token to Segmentify whenever you receive or refresh it. ```kotlin import com.segmentify.segmentifyandroidsdk.model.NotificationModel import com.segmentify.segmentifyandroidsdk.model.NotificationType override fun onNewToken(token: String) { val model = NotificationModel() model.type = NotificationType.PERMISSION_INFO model.deviceToken = token SegmentifyManager.sendNotification(model) } ``` Send the token again on app start as well, so a token issued before the SDK was configured is not lost. Without a registered token the user cannot be targeted by push campaigns. ## Report views and clicks Build a `SegmentifyPushPayload` from the incoming message and hand it to the SDK. ```kotlin import com.google.firebase.messaging.FirebaseMessagingService import com.google.firebase.messaging.RemoteMessage import com.segmentify.segmentifyandroidsdk.model.SegmentifyPushPayload class MyFirebaseMessagingService : FirebaseMessagingService() { override fun onMessageReceived(remoteMessage: RemoteMessage) { if (remoteMessage.data.isEmpty()) return val payload = SegmentifyPushPayload.from(remoteMessage.data) if (payload.title.isNotEmpty() || payload.message.isNotEmpty()) { showNotification(payload) // your own code: build and show the notification } SegmentifyManager.handlePushReceived(payload) } } ``` When the user taps the notification, report the click from the activity that opens: ```kotlin SegmentifyManager.handlePushClicked(payload) ``` Keep the values you need (at least `instanceId`) in the notification's intent extras so you can rebuild the payload there, for example with `SegmentifyPushPayload.from(mapOf("instanceId" to instanceId))`. `handlePushReceived` reports a view and `handlePushClicked` reports a click. Both need the payload's `instanceId`; a message without one is not a Segmentify campaign and is ignored. ## The payload | Property | Type | Description | | --- | --- | --- | | `title`, `message` | `String` | Text of the notification. Empty when not sent. | | `image`, `icon` | `String?` | Image and icon URLs. | | `deeplink`, `redirectUrl` | `String?` | Where a tap should lead. | | `targetUrl` | `String?` | `deeplink` if present, otherwise `redirectUrl`. | | `instanceId` | `String?` | ID of the push campaign. Needed to report views and clicks. | | `tag` | `String?` | Notification tag. | | `actions` | `List` | Action buttons, each with `action`, `title`, `icon`, `redirectUrl`, `deeplink`. | | `isV2` | `Boolean` | Whether the message uses the current payload format. | ## Attribute what happens next After a click, the SDK remembers the campaign so you can attribute the visit that follows: ```kotlin val utm = SegmentifyManager.getTrackingParameters() // utm.utm_source = "segmentify", utm.utm_medium = "push", utm.utm_campaign = the campaign's instanceId ``` Add these to the deep link or to your own analytics events if you track campaign sources. ## Checklist - The push data center URL is set. - The token is sent on first launch and on every refresh. - Views are reported when a notification arrives, and clicks when it is tapped. - The notification opens `targetUrl` when one is present. --- # Recommendations > Render the recommendation widgets the SDK returns, and report their impressions and clicks. Event methods with a callback return the recommendation campaigns that apply to the event. Which campaigns, with which products, is set up in your Segmentify panel; the app only renders what comes back. ## What you receive A list of recommendations, one per campaign. It is empty when no campaign applies. | Property | Description | | --- | --- | | `notificationTitle` | The title of the widget, as set in the panel. | | `products` | The products to show, in order. | | `instanceId` | ID of the campaign. Use it when reporting interactions. | | `actionId` | ID of this response. Use it as `interactionId` for impressions and widget views. | | `errorString` | Set when the response could not be read. | Each product has, among others: | Property | Description | | --- | --- | | `productId` | Your ID of the product. | | `name` | Product name. | | `url`, `mUrl` | Product page URLs. | | `image`, `imageXS` ... `imageXL` | Image URLs. | | `price`, `oldPrice`, `specialPrice` | Prices as numbers. | | `priceText`, `oldPriceText`, `specialPriceText` | Prices formatted for display. | | `brand`, `category`, `categories` | Brand and categories. | | `inStock`, `stockCount` | Availability. | | `params` | Custom product fields from your catalogue. | ## Render and report ```kotlin override fun onDataLoaded(data: ArrayList) { for (recommendation in data) { val title = recommendation.notificationTitle val products = recommendation.products ?: continue showWidget(title, products) // your own UI code SegmentifyManager.sendImpression(recommendation.instanceId!!, recommendation.actionId!!) } } ``` The callback is delivered by the networking layer. Switch to the main thread before touching views if your UI code needs it. 1. Render each recommendation as a widget: its title and its products. 2. Call `sendImpression` when you place the widget. 3. Call `sendWidgetView` when it becomes visible. 4. Call `sendClickView` with the product ID when a product is tapped. See [Interactions and Banners](/events/interactions/) for the three calls. ## Where recommendations come from | Screen | Call that returns them | | --- | --- | | Home, category and other screens | `sendPageView` | | Product | `sendProductView` | | Basket | `sendViewBasket` | | Order confirmation | `sendPurchase` | | Anything else | `sendCustomEvent` | If you get an empty list, check in the panel that a campaign is active for that page type and that test mode matches: a campaign in test mode only answers events sent with `testMode` on. --- # Troubleshooting > What to check when an event is not sent, recommendations are empty or push notifications are not reported. ## Turn on logs Turn on logs with `SegmentifyManager.logStatus(true)` (after `config`) and filter Logcat by `Segmentify`. The SDK logs an error whenever it refuses to send an event, naming the missing field. ## The event is not sent The SDK checks required fields before sending. If one is missing it logs an error and **does not send the event**; no exception is thrown. | Method | Not sent when | | --- | --- | | `sendPageView` | `category` is missing. | | `sendProductView` | `productId`, `title`, `url`, `image` or `price` is missing; or both or neither of `category` and `categories` are set. | | `sendAddOrRemoveBasket` | `step`, `productId` or `quantity` is missing. | | `sendViewBasket`, `sendPurchase` and the other checkout methods | `totalPrice` or `productList` is missing. | | `sendWishlist` | The step is unknown, or its `productId` or `favoritesList` is missing. | | Push methods | The push data center URL is not set, or the token or `instanceId` is missing. | ## The event is sent but nothing happens | Symptom | Likely cause | | --- | --- | | Nothing arrives in the panel | Wrong API key or data center URL, or the domain passed to the SDK is not the one registered for the account. | | Events arrive, recommendations are empty | No active campaign for that page type, or the campaign is in test mode and the event is not (or the other way round). | | No result for some users | `lang` or `currency` is missing or not configured for the account. | | Product recommendations show wrong prices | `sendProductView` sends a different price or currency than your product feed. | | Revenue is counted twice | `sendPurchase` is called more than once for an order. | | Every launch looks like a new visitor | App data is cleared between launches, so the stored user ID is lost. | ## Push notifications | Symptom | Likely cause | | --- | --- | | Users are not reachable | The token was never sent: check the registration call runs after the SDK is configured. | | Sends are reported, views and clicks are not | `handlePushReceived` and `handlePushClicked` are not called, or the payload has no `instanceId`. | | Nothing is reported at all | The push data center URL is not set or belongs to another region. | ## Check the request itself The SDK calls the Segmentify Events API. To see exactly what a correct request and response look like, and to send one by hand, use the [API Docs](https://api-docs.segmentify.com/): the [status codes](https://api-docs.segmentify.com/events/responses-and-errors/) explain every rejection. ## Still stuck Send the Segmentify support team the SDK version, the log lines around the event, and the time of the test. --- # Copy for LLMs > Give this documentation, or a Google Doc, to an LLM as clean Markdown LLMs such as Claude or ChatGPT read Markdown far better than a copied web page or a Word-style document: headings, lists, tables and code blocks keep their structure, and no navigation, styling or long URLs waste the context window. This site, and the Google Docs we write alongside it, can both be handed to an LLM as Markdown. ## Copy a page of this site - **Copy for LLMs**: the button under the title of every page copies the page as Markdown (title, description and content). Paste it into the LLM. - **View as Markdown**: every page is also served as a Markdown file: replace the trailing slash of the page address with `.md`, so `…/some-page/` becomes `…/some-page.md`. - **llms.txt**: [`llms.txt`](../llms.txt) lists every page of the site with a link to its Markdown file, following the [llms.txt](https://llmstxt.org/) convention. Give its address to an LLM or agent that can browse. - **llms-full.txt**: [`llms-full.txt`](../llms-full.txt) is the whole site in one Markdown file, for a tool that should read all of it at once. ## Export a Google Doc as Markdown (Google Docs Copy for LLMs) Specs, analyses and meeting notes often start in Google Docs. To give one to an LLM, or to move it into this documentation, export it as Markdown with the **Better Google Docs Copy** Chrome extension (its project is called "Google Docs Copy for LLMs"): 1. Install it from the [Chrome Web Store](https://chromewebstore.google.com/detail/better-google-docs-copy/faciokbjemdddkjokcajndenapikgcml). 2. Open the Google Doc and click **Copy for LLM**. 3. The first time, sign in with your Google account and allow access. The extension reads the document through the Google Docs API and its comments through the Google Drive API. 4. Choose whether to copy the selected text or the whole document, then paste the Markdown where you need it. What it adds over a plain copy: - **Comments**: comment threads come along with the passage they were left on, so the LLM sees the review discussion too. - **Images**: Google's very long image URLs are replaced with short references, so they do not fill the context window. - **Options** (right-click the extension icon, then Options): heading style (ATX `# Heading` or Setext), comment format (XML tags, blockquote or quoted context) and whether resolved comments are included. The extension runs in the browser and only talks to Google's APIs. Before pasting a document into an external LLM, check that it holds no customer data, credentials or other information that must not leave the company. ### Without the extension Google Docs can export Markdown itself, without comments: - **Whole document**: File → Download → Markdown (.md). - **A selection**: turn on Tools → Preferences → Enable Markdown, then use Edit → Copy as Markdown. ## Move a Google Doc into this documentation 1. Export the doc as Markdown as described above (leave comments out, or resolve them first). 2. Save it as a new `.md` file under `src/content/docs/`, with `title` and `description` front matter. 3. Add the page to the `sidebar` in `astro.config.mjs`, and open a pull request.