val permutive = (application as MyApplication).permutiveval currentCohorts: List<String> = permutive.currentCohortscurrentCohorts.forEach { cohortId -> Log.d("Permutive", "User is in cohort: $cohortId")}
Get cohorts activated for specific platforms:
val currentActivations: Map<String, List<String>> = permutive.currentActivations// Get Google Ad Manager activationsval gamActivations = currentActivations["dfp"].orEmpty()// Get AppNexus activationsval appNexusActivations = currentActivations["appnexus_adserver"].orEmpty()// Get contextual activationsval gamContextual = currentActivations["dfp_contextual"].orEmpty()
For real-time cohort changes, use TriggersProvider:
val triggersProvider = permutive.triggersProvider()// Get notified when user enters/exits a cohortval trigger = triggersProvider.triggerAction("premium_subscriber") { isInCohort -> if (isInCohort) { showPremiumFeatures() } else { hidePremiumFeatures() }}// Don't forget to close when doneoverride fun onDestroy() { super.onDestroy() trigger.close()}
TriggersProvider Guide
Complete documentation for reactive updates
currentCohorts and currentActivations return snapshot values at the time they’re called. For real-time updates, use TriggersProvider.
class PersonalizedHomeActivity : AppCompatActivity() { private val permutive by lazy { (application as MyApplication).permutive } private fun personalizeContent() { val cohorts = permutive.currentCohorts when { "premium_subscriber" in cohorts -> showPremiumContent() "sports_enthusiast" in cohorts -> showSportsRecommendations() "tech_reader" in cohorts -> showTechRecommendations() else -> showGeneralContent() } }}
Feature Flags / A/B Testing
class ExperimentalFeatureActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) val cohorts = permutive.currentCohorts // Use cohort membership as feature flag val enableNewCheckout = "checkout_experiment_v2" in cohorts if (enableNewCheckout) { setContentView(R.layout.activity_checkout_v2) } else { setContentView(R.layout.activity_checkout_v1) } }}
Dynamic Ad Targeting
Activations are automatically used by our add-on libraries:
// Google Ad Manager (automatic with add-on)val adRequest = AdManagerAdRequest.Builder() .addPermutiveTargeting(permutive) // Adds activations automatically .build()// AppNexus (automatic with add-on)adView.addPermutiveTargeting(permutive) // Adds activations automatically
Analytics and Logging
class AnalyticsHelper(private val permutive: Permutive) { fun logUserSegments() { val cohorts = permutive.currentCohorts // Log to your analytics platform Analytics.setUserProperty("permutive_cohorts", cohorts.joinToString(",")) Analytics.logEvent("cohort_count", mapOf("count" to cohorts.size)) } fun getActivationInfo(): Map<String, Any> { val activations = permutive.currentActivations return mapOf( "gam_cohort_count" to (activations["dfp"]?.size ?: 0), "appnexus_cohort_count" to (activations["appnexus_adserver"]?.size ?: 0), "has_contextual" to (activations["dfp_contextual"]?.isNotEmpty() ?: false) ) }}
Problem:currentCohorts returns an empty list.Solutions:
Wait a few seconds after initialization
Track some events and check again
Use TriggersProvider for reactive updates
Enable debug logging to see sync status
Activations different from cohorts
Problem: User is in a cohort but it doesn’t appear in activations.Cause: Not all cohorts are activated for all platforms. This is configured in your Permutive dashboard.Solution: Check your dashboard configuration or contact your Customer Success Manager.
Contextual cohorts not appearing
Problem:dfp_contextual activations are empty.Solutions: