📖 PrzeglądOverview
Moduł Segments automatycznie kategoryzuje użytkowników na podstawie ich
zachowania, czasu od instalacji, wydatków i zaangażowania.The Segments module automatically categorizes users based on their behavior, time since installation, spending, and engagement.
// Sprawdź segment
if (ADict.Segments.isIn(Segment.PAYING_USER)) {
// Mniej reklam dla płacących
showLessAds()
}
// Sprawdź wiele segmentów
if (ADict.Segments.isInAny(Segment.WHALE, Segment.SUBSCRIBER)) {
showVIPContent()
}
📊 Predefiniowane segmenty
Czasowe
| Segment | OpisDescription |
|---|---|
NEW_USER | Użytkownik < 7 dniUser < 7 days |
RETURNING_USER | Użytkownik 7-30 dniUser 7-30 days |
LOYAL_USER | Użytkownik > 30 dniUser > 30 days |
VETERAN_USER | Użytkownik > 90 dniUser > 90 days |
PłatnościPayments
PAYING_USER | Dokonał jakiegokolwiek zakupuMade any purchase |
WHALE | Wydał > 10$Wydał > 10$Spent > $10 |
SUBSCRIBER | Ma aktywną subskrypcjęHas active subscription |
ZaangażowanieEngagement
HIGH_ENGAGEMENT | > 5 sesji w ostatnim tygodniu |
MEDIUM_ENGAGEMENT | 2-5 sesji w ostatnim tygodniu |
LOW_ENGAGEMENT | < 2 sesje w ostatnim tygodniu |
AT_RISK | Nie był > 7 dniNot seen > 7 days |
DORMANT | Nie był > 30 dniNot seen > 30 days |
Inne
NOTIFICATIONS_ENABLED | Włączył powiadomieniaEnabled notifications |
ONBOARDED | Ukończył onboardingCompleted onboarding |
📝 Śledzenie📝 Tracking
trackSession()
Śledź sesję (automatycznie przy init).Track session (automatic at init).
trackPurchase(amount: Double)
Śledź zakup.Track purchase.
setSubscriptionStatus(active: Boolean)
Ustaw status subskrypcji.
setNotificationsEnabled(enabled: Boolean)
Ustaw status powiadomień.Set notification status.
setOnboardingCompleted(completed: Boolean)
Oznacz onboarding jako ukończony.Mark onboarding as completed.
// Po zakupie
fun onPurchaseCompleted(amount: Double) {
ADict.Segments.trackPurchase(amount)
}
// Po subskrypcji
fun onSubscriptionStarted() {
ADict.Segments.setSubscriptionStatus(true)
}
// Po onboardingu
fun onOnboardingFinished() {
ADict.Segments.setOnboardingCompleted(true)
}
// Po włączeniu powiadomień
fun onNotificationsGranted() {
ADict.Segments.setNotificationsEnabled(true)
}
🔍 Pobieranie segmentów
isIn(segment: String): Boolean
Sprawdź czy użytkownik jest w segmencie.Check if user is in segment.
isInAny(vararg segments: String): Boolean
Czy jest w którymkolwiek z segmentów.
isInAll(vararg segments: String): Boolean
Czy jest we wszystkich segmentach.
getActive(): Set<String>
Pobierz wszystkie aktywne segmenty.
getUserData(): UserData
Pobierz surowe dane użytkownika.Get raw user data.
🔧 Własne segmenty🔧 Custom Segments
defineCustom(name: String, condition: (UserData) -> Boolean)
Zdefiniuj własny segment.Define a custom segment.
// Super aktywni (> 10 sesji/tydzień, > 50 zł wydane)
ADict.Segments.defineCustom("super_active") { userData ->
userData.sessionsLastWeek > 10 && userData.totalSpent > 50.0
}
// Potencjalny churn (dawno nie było, ale kiedyś płacił)
ADict.Segments.defineCustom("potential_churn") { userData ->
val daysSinceLastSession = TimeUnit.MILLISECONDS.toDays(
System.currentTimeMillis() - userData.lastSessionTimestamp
)
daysSinceLastSession > 14 && userData.hasPurchased
}
// Użycie
if (ADict.Segments.isIn("potential_churn")) {
sendWinBackNotification()
}
📡 Obserwacja (Flow)
lifecycleScope.launch {
ADict.Segments.segments.collect { activeSegments ->
updateUserBadge(activeSegments)
// Dostosuj UI do segmentu
when {
Segment.WHALE in activeSegments -> showVIPBanner()
Segment.AT_RISK in activeSegments -> showRetentionOffer()
Segment.NEW_USER in activeSegments -> showOnboardingTip()
}
}
}
💡 PrzykładyExamples użycia
// Mniej reklam dla płacących
fun getAdFrequency(): Int {
return when {
ADict.Segments.isIn(Segment.WHALE) -> 0 // Brak reklam
ADict.Segments.isIn(Segment.PAYING_USER) -> 5 // Co 5 akcji
ADict.Segments.isIn(Segment.HIGH_ENGAGEMENT) -> 3 // Co 3 akcje
else -> 2 // Co 2 akcje
}
}
// Specjalne oferty dla segmentów
fun getSpecialOffer(): Offer? {
return when {
ADict.Segments.isIn(Segment.AT_RISK) -> Offer.COMEBACK_DISCOUNT
ADict.Segments.isIn(Segment.NEW_USER) -> Offer.FIRST_PURCHASE_BONUS
ADict.Segments.isInAll(Segment.LOYAL_USER, Segment.HIGH_ENGAGEMENT)
-> Offer.LOYALTY_REWARD
else -> null
}
}
// Adaptacyjne powiadomienia
fun shouldSendNotification(type: NotificationType): Boolean {
return when (type) {
NotificationType.PROMO ->
ADict.Segments.isIn(Segment.HIGH_ENGAGEMENT)
NotificationType.COMEBACK ->
ADict.Segments.isIn(Segment.AT_RISK)
NotificationType.VIP_ONLY ->
ADict.Segments.isIn(Segment.WHALE)
else -> true
}
}
📦 data class UserData
- installTimestampLong
- lastSessionTimestampLong
- totalSessionsInt
- sessionsLastWeekInt
- totalSpentDouble
- hasPurchasedBoolean
- hasSubscriptionBoolean
- notificationsEnabledBoolean
- onboardingCompletedBoolean