Analytics
The SDK provides APIs for tracking application-level analytics events.
Track app launch
Use trackAppLaunch() to record application launch events.
import UIKit
import Magify
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else {
return
}
appDelegate.magify.trackAppLaunch()
}
}
Call this method when your application launch event should be tracked.
Track custom events
Use trackCustomEvent(_:parameters:) to send arbitrary named events with optional parameters.
// Simple event
magify.trackCustomEvent("level_complete")
// Event with parameters
magify.trackCustomEvent("item_purchased", parameters: [
"item_id": "sword_001",
"price": 100
])
The parameters argument accepts [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(for: campaignType)
// Record that the user tapped a campaign
magify.trackClick(for: campaignType)
// Record that the user tapped a specific product inside a campaign
magify.trackPurchaseClick(for: campaignType, productId: "product_001")
// Record a failed impression with a reason string
magify.trackImpressionFail(for: campaignType, reason: "no_fill")
Pass optional display metadata to trackImpression(for:info:) via the info parameter:
magify.trackImpression(for: campaignType, info: ["placement": "main_menu"])
Virtual-economy transactions
Use transactions to record changes to the user's in-game virtual currency or resources.
Income transaction
Call trackTransaction(_:) with a Transaction built from Transaction.IncomeType.receive(source:productInfo:) when the user gains resources:
let bonus = Transaction.Bonus(
name: "coins",
quantity: 500,
finalBalance: 1500,
group: "currency" // optional grouping label
)
let productInfo = Transaction.ProductInfo(
productId: "offer_pack_001",
price: "4.99", // optional
currency: "USD" // optional
)
let transaction = Transaction(
type: .receive(source: "iap_purchase", productInfo: productInfo),
bonuses: [bonus]
)
magify.trackTransaction(transaction)
Expense transaction
Use Transaction.IncomeType.spend() when the user spends resources:
let bonus = Transaction.Bonus(
name: "coins",
quantity: 100,
finalBalance: 1400
)
let transaction = Transaction(
type: .spend(),
bonuses: [bonus]
)
magify.trackTransaction(transaction)
Correction transaction
Use Transaction.IncomeType.correct(source:) to record balance corrections:
let bonus = Transaction.Bonus(
name: "coins",
quantity: 50,
finalBalance: 1450
)
let transaction = Transaction(
type: .correct(source: "admin_adjustment"),
bonuses: [bonus]
)
magify.trackTransaction(transaction)
Transaction.Bonus fields
Transaction.ProductInfo fields
Product usage events
Track how rewarded and free-bonus products are consumed after the user receives them.
// User received a rewarded-video reward
magify.trackRewardGranted(productId: "video_reward_001")
// User consumed a regular (non-reward, non-bonus) product
magify.trackOrdinaryProduct(withProductId: "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 nil to any setter to clear the value:
magify.setGameMode(nil)
User email
Associate a user email address with analytics events for mailing-status mapping:
magify.setUserEmail("user@example.com")
Next step
You have now completed the Magify Swift SDK analytics integration, covering app-launch tracking, custom events, campaign impression and click tracking, virtual-economy transactions, product usage, and game-state context.