Skip to main content

AppEvents.shared

All event logging goes through the AppEvents.shared singleton. You access it directly without any setup beyond the standard SDK initialisation in your AppDelegate.
import FacebookCore

// Simple event with no parameters
AppEvents.shared.logEvent(.viewedContent)

Logging a simple event

Use logEvent(_:) when you only need to record that something happened:
AppEvents.shared.logEvent(.searched)

Logging an event with a value

Use logEvent(_:valueToSum:parameters:) to attach a numeric value and a parameters dictionary:
AppEvents.shared.logEvent(
    .viewedContent,
    valueToSum: 9.99,
    parameters: [
        .contentType: "product",
        .contentID: "SKU-12345"
    ]
)

Standard event names

The SDK defines constants for the most common event names. Use these where possible so Facebook can map them to standard event types. General events
Swift constantRaw valueDescription
AppEvents.Name.viewedContentfb_mobile_content_viewUser viewed content
AppEvents.Name.searchedfb_mobile_searchUser performed a search
AppEvents.Name.completedRegistrationfb_mobile_complete_registrationUser completed registration
AppEvents.Name.completedTutorialfb_mobile_tutorial_completionUser completed a tutorial
AppEvents.Name.ratedfb_mobile_rateUser rated an item
AppEvents.Name.contactContactUser initiated contact
AppEvents.Name.customizeProductCustomizeProductUser customized a product
AppEvents.Name.donateDonateUser made a donation
AppEvents.Name.findLocationFindLocationUser found a location
AppEvents.Name.scheduleScheduleUser booked an appointment
AppEvents.Name.submitApplicationSubmitApplicationUser submitted an application
AppEvents.Name.subscribeSubscribeUser started a paid subscription
AppEvents.Name.startTrialStartTrialUser started a free trial
AppEvents.Name.adClickAdClickUser clicked an ad
AppEvents.Name.adImpressionAdImpressionUser viewed an ad
E-commerce events
Swift constantRaw valueDescription
AppEvents.Name.addedToCartfb_mobile_add_to_cartUser added item to cart
AppEvents.Name.addedToWishlistfb_mobile_add_to_wishlistUser added item to wishlist
AppEvents.Name.initiatedCheckoutfb_mobile_initiated_checkoutUser entered checkout
AppEvents.Name.addedPaymentInfofb_mobile_add_payment_infoUser entered payment info
AppEvents.Name.purchasedfb_mobile_purchaseUser completed a purchase
Gaming events
Swift constantRaw valueDescription
AppEvents.Name.achievedLevelfb_mobile_level_achievedUser achieved a level
AppEvents.Name.unlockedAchievementfb_mobile_achievement_unlockedUser unlocked an achievement
AppEvents.Name.spentCreditsfb_mobile_spent_creditsUser spent in-app credits

Standard parameter names

Swift constantRaw valueDescription
AppEvents.ParameterName.contentTypefb_content_typeType of content viewed
AppEvents.ParameterName.contentIDfb_content_idIdentifier for the content
AppEvents.ParameterName.contentfb_contentJSON-encoded content descriptor
AppEvents.ParameterName.numItemsfb_num_itemsNumber of items
AppEvents.ParameterName.paymentInfoAvailablefb_payment_info_availableWhether payment info is on file
AppEvents.ParameterName.currencyfb_currencyISO 4217 currency code
AppEvents.ParameterName.searchStringfb_search_stringSearch query
AppEvents.ParameterName.successfb_successWhether the action succeeded
AppEvents.ParameterName.registrationMethodfb_registration_methodHow the user registered
AppEvents.ParameterName.orderIDfb_order_idOrder identifier

Logging a purchase

Use the dedicated logPurchase(purchaseAmount:currency:) helper for e-commerce transactions:
// Simple purchase
AppEvents.shared.logPurchase(purchaseAmount: 9.99, currency: "USD")

// Purchase with extra parameters
AppEvents.shared.logPurchase(
    purchaseAmount: 29.99,
    currency: "USD",
    parameters: [
        .contentID: "SKU-99",
        .numItems: 2,
        .contentType: "product"
    ]
)
This is equivalent to logging a FBSDKAppEventNamePurchased event with the currency injected as a parameter.

User properties

You can associate user data with events to improve matching and measurement. The SDK hashes all values before transmitting them.
AppEvents.shared.setUser(
    email: "[email protected]",
    firstName: "Jane",
    lastName: "Smith",
    phone: nil,
    dateOfBirth: nil,
    gender: nil,
    city: nil,
    state: nil,
    zip: nil,
    country: nil
)
Set a persistent user ID to link events across sessions:
AppEvents.shared.userID = "your_internal_user_id"
Clear user data when the user logs out:
AppEvents.shared.clearUserData()
AppEvents.shared.userID = nil

Flush behaviour

By default, the SDK uses FBSDKAppEventsFlushBehaviorAuto, which batches events and flushes them when 100 events have accumulated or after 15 seconds, whichever comes first. To flush immediately — for example, just before your app terminates — call:
AppEvents.shared.flush()
To require manual flushing only:
AppEvents.shared.flushBehavior = .explicitOnly
AppEvents.shared.flush() // must call this yourself
Use FBSDKAppEventsFlushBehaviorExplicitOnly during testing so you can control exactly when events are sent and verify them in Events Manager.

Build docs developers (and LLMs) love