Analytics

The SDK provides APIs for tracking application-level analytics events.

Track custom events

Use trackCustomEvent(event, params) to send arbitrary named events with optional parameters.

// Simple event
magify.trackCustomEvent("level_complete")

// Event with parameters
magify.trackCustomEvent(
    event = "item_purchased",
    params = mapOf(
        "item_id" to "sword_001",
        "price" to 100
    )
)

The params argument is Map<String, Any>? and is optional.

Campaign impression and click tracking

Track when a campaign is shown or tapped by the user.

// Record that a campaign was displayed
magify.trackImpression(CampaignType.SUBSCRIPTION)

// Record that the user tapped a campaign
magify.trackClick(CampaignType.SUBSCRIPTION)

// Record that the user tapped a specific product inside a campaign
magify.trackProductClick(CampaignType.SUBSCRIPTION, productId = "product_001")

// Record a failed impression with a reason string
magify.trackImpressionFail(CampaignType.SUBSCRIPTION, reason = "no_fill")

Virtual-economy transactions

Use transactions to record changes to the user's in-game virtual currency or resources.

BonusInfo

Every transaction requires at least one BonusInfo entry describing the resource affected.

import com.magify.sdk.analytics.model.BonusInfo

val bonus = BonusInfo(
    name = "coins",          // resource name
    quantity = 500,          // amount added or removed
    finalBalance = 1500,     // balance after the transaction
    group = "currency"       // optional grouping label
)

ProductInfo

Optionally attach product metadata to an income transaction.

import com.magify.sdk.analytics.model.ProductInfo

val product = ProductInfo(
    productId = "offer_pack_001",
    price = "4.99",   // optional
    currency = "USD"  // optional
)

Income transaction

Call trackIncomeTransaction(source, bonuses, product?) when the user gains resources:

magify.trackIncomeTransaction(
    source = "iap_purchase",
    bonuses = listOf(
        BonusInfo(name = "coins", quantity = 500, finalBalance = 1500, group = "currency")
    ),
    product = ProductInfo(productId = "offer_pack_001", price = "4.99", currency = "USD")
)

Expense transaction

Call trackExpenseTransaction(bonuses) when the user spends resources:

magify.trackExpenseTransaction(
    bonuses = listOf(
        BonusInfo(name = "coins", quantity = 100, finalBalance = 1400)
    )
)

Correction transaction

Call trackCorrectionTransaction(bonuses) to record a balance correction:

magify.trackCorrectionTransaction(
    bonuses = listOf(
        BonusInfo(name = "coins", quantity = 50, finalBalance = 1450)
    )
)

Product usage events

Track how rewarded, free-bonus, and ordinary products are consumed after the user receives them.

// User received a rewarded-video reward
magify.trackRewardGranted(productId = "video_reward_001")

// User received a free bonus product
magify.trackFreeBonusGranted(productId = "daily_bonus_001")

// User consumed a regular (non-reward, non-bonus) product
magify.trackOrdinaryProductUsed(productId = "consumable_pack_001")

Game state context

Attach game-state metadata to all subsequent analytics events. Call these methods whenever the values change.

// Current game mode (e.g. "pvp", "story")
magify.setGameMode("story")

// Current level the user is on
magify.setGameLevel(12)

// Highest level the user has reached
magify.setGameMaxLevel(15)

Pass null to any setter to clear the value:

magify.setGameMode(null)

User email

Associate a user email address with analytics events for mailing-status mapping:

magify.setUserEmail("user@example.com")

Observing state changes

The SDK exposes RxJava2 (io.reactivex.Observable) streams for reacting to state changes in your UI layer.

// Emits whenever the subscription status changes
magify.observeSubscriptionStatusChanged()
    .subscribe { /* update UI */ }

// Emits the new session number (Int) whenever the session counter increments
magify.observeSessionNumberChanged()
    .subscribe { sessionNumber -> /* log or display */ }

All observe* methods return io.reactivex.Observable.

Batching configuration

By default, the SDK uses built-in thresholds for how many events to accumulate before flushing (groupSize) and how often to flush on a timer (syncIntervalInSeconds). You can override these with tweakAnalyticsConfig and restore the defaults with resetAnalyticsConfig.

import com.magify.sdk.model.AnalyticsConfiguration

// Flush after every 5 events, or every 30 s — whichever comes first
magify.tweakAnalyticsConfig(
    AnalyticsConfiguration(
        groupSize = 5,            // events per flush batch
        syncIntervalInSeconds = 30  // flush timer interval, in seconds
    )
)

// Restore SDK defaults
magify.resetAnalyticsConfig()

Next step

You have now completed the Magify Android SDK analytics integration, covering custom events, campaign impression and click tracking, virtual-economy transactions, product usage, and game-state context.

Related articles

MagifyPresenter

NetworkStatus

InfoProduct

LimitedTimeOfferProvider

ProductIdType

Analytics Service