Skip to content

Commit

Permalink
Use merchandising segment category with example
Browse files Browse the repository at this point in the history
  • Loading branch information
adam1929 authored Oct 10, 2024
1 parent f5e38d2 commit d0b7f3c
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Documentation/segmentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ To use real-time segments in your app, you must register one or more customized
Each instance must define the following three items:

1. A `exposingCategory` indicating your point of interest for segmentation:
* Possible values are `content`, `discovery`, or `merchandise`. You will get updates only for segmentation data assigned to the specified `exposingCategory`.
* Possible values are `content`, `discovery`, or `merchandising`. You will get updates only for segmentation data assigned to the specified `exposingCategory`.
2. A boolean flag `includeFirstLoad` to force a fetch of segmentation data:
* Setting this flag to `true` triggers a segmentation data fetch immediately.
* The SDK will notify this callback instance with the new data even if the data has not changed from the last known state.
Expand Down Expand Up @@ -148,7 +148,7 @@ Exponea.registerSegmentationDataCallback(object : SegmentationDataCallback() {
}
})
Exponea.registerSegmentationDataCallback(object : SegmentationDataCallback() {
override val exposingCategory = "merchandise"
override val exposingCategory = "merchandising"
override val includeFirstLoad = false
override fun onNewData(segments: List<Segment>) {
dataCollector.postValue(Pair(exposingCategory, segments))
Expand Down
49 changes: 48 additions & 1 deletion app/src/main/java/com/exponea/example/view/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,57 @@ import com.exponea.sdk.models.InAppMessage
import com.exponea.sdk.models.InAppMessageButton
import com.exponea.sdk.models.InAppMessageCallback
import com.exponea.sdk.models.PushNotificationDelegate
import com.exponea.sdk.models.Segment
import com.exponea.sdk.models.SegmentationDataCallback
import com.exponea.sdk.util.Logger
import com.exponea.sdk.util.isResumedActivity
import com.exponea.sdk.util.isViewUrlIntent
import kotlinx.android.synthetic.main.activity_main.navigation
import kotlinx.android.synthetic.main.activity_main.toolbar

class MainActivity : AppCompatActivity() {

private val contentSegmentsCallback = object : SegmentationDataCallback() {
override val exposingCategory = "content"
override val includeFirstLoad = false
override fun onNewData(segments: List<Segment>) {
Logger.i(
this@MainActivity,
"Segments: New for category $exposingCategory with IDs: $segments"
)
}
}

private val discoverySegmentsCallback = object : SegmentationDataCallback() {
override val exposingCategory = "discovery"
override val includeFirstLoad = false
override fun onNewData(segments: List<Segment>) {
Logger.i(
this@MainActivity,
"Segments: New for category $exposingCategory with IDs: $segments"
)
}
}

private val merchandisingSegmentsCallback = object : SegmentationDataCallback() {
override val exposingCategory = "merchandising"
override val includeFirstLoad = false
override fun onNewData(segments: List<Segment>) {
Logger.i(
this@MainActivity,
"Segments: New for category $exposingCategory with IDs: $segments"
)
}
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
setSupportActionBar(toolbar)
supportActionBar?.title = "Examples"

// Set log level before first call to SDK function
Exponea.loggerLevel = Logger.Level.DEBUG
Exponea.loggerLevel = Logger.Level.VERBOSE
Exponea.checkPushSetup = true
Exponea.handleCampaignIntent(intent, applicationContext)
Exponea.pushNotificationsDelegate = object : PushNotificationDelegate {
Expand Down Expand Up @@ -98,6 +134,10 @@ class MainActivity : AppCompatActivity() {
} else if (savedInstanceState == null) {
selectTab(BottomTab.Fetch)
}

Exponea.registerSegmentationDataCallback(discoverySegmentsCallback)
Exponea.registerSegmentationDataCallback(contentSegmentsCallback)
Exponea.registerSegmentationDataCallback(merchandisingSegmentsCallback)
}

override fun onNewIntent(intent: Intent?) {
Expand All @@ -110,6 +150,13 @@ class MainActivity : AppCompatActivity() {
}
}

override fun onDestroy() {
Exponea.unregisterSegmentationDataCallback(discoverySegmentsCallback)
Exponea.unregisterSegmentationDataCallback(contentSegmentsCallback)
Exponea.unregisterSegmentationDataCallback(merchandisingSegmentsCallback)
super.onDestroy()
}

private fun selectTab(tab: BottomTab) {
navigation.selectedItemId = when (tab) {
Anonymize -> id.actionAnonymize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,7 @@ internal open class FlushManagerImpl(
@WorkerThread
private fun onEventSentSuccess(exportedEvent: ExportedEvent) {
Logger.d(this, "onEventSentSuccess: ${exportedEvent.id}")
if (exportedEvent.route == Route.TRACK_CUSTOMERS) {
onEventUploaded(exportedEvent)
}
onEventUploaded(exportedEvent)
eventRepository.remove(exportedEvent.id)
}

Expand Down

0 comments on commit d0b7f3c

Please sign in to comment.