# App Events Best Practices for Casino Gaming App



This guide is intended to be used as a starting point for your app and should be customized. The example app provides a screen by screen breakdown of the different events and parameters that can be collected. At the end of it, there is a table that lists the recommended events and parameters for your app.

## Casino Gaming App Product and Marketing Objectives
+ Understand the most popular items being purchased in-app as well as hardest levels to complete
+ Retarget users that never completed the tutorial and have not played a game
+ Find new users using lookalikes of high value or frequent purchasers

## Example Casino Game App
### ActivatedApp Event

**ActivatedApp Event Code Example:**

### Objective-C
```
/**
 * For more details, please take a look at:
 * developers.facebook.com/docs/reference/ios/current/class/FBSDKAppEvents
 */
- (void)applicationDidBecomeActive:(UIApplication *)application {
    [FBSDKAppEvents activateApp];
}
```

### Android SDK
```
/**
 * This function assumes logger is an instance of AppEventsLogger and has been
 * created using AppEventsLogger.newLogger() call.
 */
@Override
public void onCreate() {
    super.onCreate();
    FacebookSdk.sdkInitialize(getApplicationContext());
    AppEventsLogger.activateApp(this);
}
```

### Unity SDK
```
/**
 * Include the Facebook namespace via the following code:
 * using Facebook.Unity;
 *
 * For more details, please take a look at:
 * developers.facebook.com/documentation/unity/reference/current/FB.LogAppEvent
 */
void Awake ()
{
    if (FB.IsInitialized) {
        FB.ActivateApp();
    } else {
        //Handle FB.Init
        FB.Init( () => {
            FB.ActivateApp();
        });
    }
}
```

### CompletedRegistration Event

**CompletedRegistration Event Code Example:**

### Objective-C
```
/**
 * For more details, please take a look at:
 * developers.facebook.com/docs/reference/ios/current/class/FBSDKAppEvents
 */
 - (void)logCompletedRegistrationEvent :(NSString*)registrationMethod {

NSDictionary *params =
    [[NSDictionary alloc] initWithObjectsAndKeys:
        registrationMethod, FBSDKAppEventParameterNameRegistrationMethod,
        nil];

    [FBSDKAppEvents logEvent: FBSDKAppEventNameCompletedRegistration
        parameters: params];
}
```

### Android SDK
```
/**
 * This function assumes logger is an instance of AppEventsLogger and has been
 * created using AppEventsLogger.newLogger() call.
 */
public void logCompletedRegistrationEvent (String registrationMethod) {
    Bundle params = new Bundle();
    params.putString(AppEventsConstants.EVENT_PARAM_REGISTRATION_METHOD, registrationMethod);
    logger.logEvent(AppEventsConstants.EVENT_NAME_COMPLETED_REGISTRATION, params);
}
```

### Unity SDK
```
/**
 * Include the Facebook namespace via the following code:
 * using Facebook.Unity;
 *
 * For more details, please take a look at:
 * developers.facebook.com/documentation/unity/reference/current/FB.LogAppEvent
 */
public void LogCompletedRegistrationEvent (string registrationMethod) {
    var parameters = new Dictionary<string, object>();
    parameters[AppEventParameterName.RegistrationMethod] = registrationMethod;
    FB.LogAppEvent(
        AppEventName.CompletedRegistration,
        parameters
    );
}
```

### AchievedLevel Event  

**AchievedLevel Event Code Example:**

### Objective-C
```
/**
 * For more details, please take a look at:
 * developers.facebook.com/docs/reference/ios/current/class/FBSDKAppEvents
 */
 - (void)logAchievedLevelEvent :(NSString*)level {

NSDictionary *params =
    [[NSDictionary alloc] initWithObjectsAndKeys:
        level, FBSDKAppEventParameterNameLevel,
        nil];

    [FBSDKAppEvents logEvent: FBSDKAppEventNameAchievedLevel
        parameters: params];
}
```

### Android SDK
```
/**
 * This function assumes logger is an instance of AppEventsLogger and has been
 * created using AppEventsLogger.newLogger() call.
 */
public void logAchievedLevelEvent (String level) {
    Bundle params = new Bundle();
    params.putString(AppEventsConstants.EVENT_PARAM_LEVEL, level);
    logger.logEvent(AppEventsConstants.EVENT_NAME_ACHIEVED_LEVEL, params);
}
```

### Unity SDK
```
/**
 * Include the Facebook namespace via the following code:
 * using Facebook.Unity;
 *
 * For more details, please take a look at:
 * developers.facebook.com/documentation/unity/reference/current/FB.LogAppEvent
 */
public void LogAchievedLevelEvent (string level) {
    var parameters = new Dictionary<string, object>();
    parameters[AppEventParameterName.Level] = level;
    FB.LogAppEvent(
        AppEventName.AchievedLevel,
        parameters
    );
}
```

### UnlockedAchievement Event

**UnlockedAchievement Event Code Example:**

### Objective-C
```
/**
 * For more details, please take a look at:
 * developers.facebook.com/docs/reference/ios/current/class/FBSDKAppEvents
 */
 - (void)logUnlockedAchievementEvent :(NSString*)description {

NSDictionary *params =
    [[NSDictionary alloc] initWithObjectsAndKeys:
        description, FBSDKAppEventParameterNameDescription,
        nil];

    [FBSDKAppEvents logEvent: FBSDKAppEventNameUnlockedAchievement
        parameters: params];
}
```

### Android SDK
```
/**
 * This function assumes logger is an instance of AppEventsLogger and has been
 * created using AppEventsLogger.newLogger() call.
 */
public void logUnlockedAchievementEvent (String description) {
    Bundle params = new Bundle();
    params.putString(AppEventsConstants.EVENT_PARAM_DESCRIPTION, description);
    logger.logEvent(AppEventsConstants.EVENT_UNLOCKED_ACHIEVEMENTS, params);
}
```

### Unity SDK
```
/**
 * Include the Facebook namespace via the following code:
 * using Facebook.Unity;
 *
 * For more details, please take a look at:
 * developers.facebook.com/documentation/unity/reference/current/FB.LogAppEvent
 */
public void LogUnlockedAchievementEvent (string description) {
    var parameters = new Dictionary<string, object>();
    parameters[AppEventParameterName.Description] = description;
    FB.LogAppEvent(
        AppEventName.UnlockedAchievement,
        parameters
    );
}
```

### InitiatedCheckout Event  

**InitiatedCheckout Event Code Example:**

### Objective-C
```
/**
 * For more details, please take a look at:
 * developers.facebook.com/docs/reference/ios/current/class/FBSDKAppEvents
 */
 - (void)logInitiatedCheckoutEvent :(NSString*)contentId
    contentType :(NSString*)contentType
    numItems :(int)numItems
    paymentInfoAvailable :(BOOL)paymentInfoAvailable
    currency :(NSString*)currency
    valToSum :(double)totalPrice {

NSDictionary *params =
    [[NSDictionary alloc] initWithObjectsAndKeys:
        contentId, FBSDKAppEventParameterNameContentID,
        contentType, FBSDKAppEventParameterNameContentType,
        [NSNumber numberWithInt:numItems], FBSDKAppEventParameterNameNumItems,
        [NSNumber numberWithInt:paymentInfoAvailable ? 1 : 0], FBSDKAppEventParameterNamePaymentInfoAvailable,
        currency, FBSDKAppEventParameterNameCurrency,
        nil];

    [FBSDKAppEvents logEvent: FBSDKAppEventNameInitiatedCheckout
        valueToSum: totalPrice
        parameters: params];
}
```

### Android SDK
```
/**
 * This function assumes logger is an instance of AppEventsLogger and has been
 * created using AppEventsLogger.newLogger() call.
 */
public void logInitiatedCheckoutEvent (String contentId, String contentType, int numItems, boolean paymentInfoAvailable, String currency, double totalPrice) {
    Bundle params = new Bundle();
    params.putString(AppEventsConstants.EVENT_PARAM_CONTENT_ID, contentId);
    params.putString(AppEventsConstants.EVENT_PARAM_CONTENT_TYPE, contentType);
    params.putInt(AppEventsConstants.EVENT_PARAM_NUM_ITEMS, numItems);
    params.putInt(AppEventsConstants.EVENT_PARAM_PAYMENT_INFO_AVAILABLE, paymentInfoAvailable ? 1 : 0);
    params.putString(AppEventsConstants.EVENT_PARAM_CURRENCY, currency);
    logger.logEvent(AppEventsConstants.EVENT_NAME_INITIATED_CHECKOUT, totalPrice, params);
}
```

### Unity SDK
```
/**
 * Include the Facebook namespace via the following code:
 * using Facebook.Unity;
 *
 * For more details, please take a look at:
 * developers.facebook.com/documentation/unity/reference/current/FB.LogAppEvent
 */
public void LogInitiatedCheckoutEvent (string contentId, string contentType, int numItems, bool paymentInfoAvailable, string currency, double totalPrice) {
    var parameters = new Dictionary<string, object>();
    parameters[AppEventParameterName.ContentID] = contentId;
    parameters[AppEventParameterName.ContentType] = contentType;
    parameters[AppEventParameterName.NumItems] = numItems;
    parameters[AppEventParameterName.PaymentInfoAvailable] = paymentInfoAvailable ? 1 : 0;
    parameters[AppEventParameterName.Currency] = currency;
    FB.LogAppEvent(
        AppEventName.InitiatedCheckout,
        (float)totalPrice,
        parameters
    );
}
```

### Purchased Event

**Purchased Event Code Example:**

### Objective-C
```
/**
 * For more details, please take a look at:
 * developers.facebook.com/docs/reference/ios/current/class/FBSDKAppEvents
 */
 - (void)logPurchasedEvent :(int)numItems
    contentType :(NSString*)contentType
    contentId :(NSString*)contentId
    currency :(NSString*)currency
    valToSum :(double)price {

NSDictionary *params =
    [[NSDictionary alloc] initWithObjectsAndKeys:
        [NSNumber numberWithInt:numItems], FBSDKAppEventParameterNameNumItems,
        contentType, FBSDKAppEventParameterNameContentType,
        contentId, FBSDKAppEventParameterNameContentID,
        currency, FBSDKAppEventParameterNameCurrency,
        nil];

    [FBSDKAppEvents logPurchase:price
          currency: currency
        parameters: params];
}
```

### Android SDK
```
/**
 * This function assumes logger is an instance of AppEventsLogger and has been
 * created using AppEventsLogger.newLogger() call.
 */
public void logPurchasedEvent (int numItems, String contentType, String contentId, String currency, double price) {
    Bundle params = new Bundle();
    params.putInt(AppEventsConstants.EVENT_PARAM_NUM_ITEMS, numItems);
    params.putString(AppEventsConstants.EVENT_PARAM_CONTENT_TYPE, contentType);
    params.putString(AppEventsConstants.EVENT_PARAM_CONTENT_ID, contentId);
    params.putString(AppEventsConstants.EVENT_PARAM_CURRENCY, currency);
    logger.logPurchase(price, Currency.getInstance(currency),params);
}
```

### Unity SDK
```
/**
 * Include the Facebook namespace via the following code:
 * using Facebook.Unity;
 *
 * For more details, please take a look at:
 * developers.facebook.com/documentation/unity/reference/current/FB.LogAppEvent
 */
public void LogPurchasedEvent (int numItems, string contentType, string contentId, string currency, double price) {
    var parameters = new Dictionary<string, object>();
    parameters[AppEventParameterName.NumItems] = numItems;
    parameters[AppEventParameterName.ContentType] = contentType;
    parameters[AppEventParameterName.ContentID] = contentId;
    parameters[AppEventParameterName.Currency] = currency;
    FB.LogPurchase(
        (float)price,
        currency,
        parameters
    );
}
```

### PurchaseCancelled Event  

### Invite Event

### Request Event

## Strategy Gaming App Recommended Events and Parameters
| Event Name | Predefined | Suggested Parameters |
| --- | --- | --- |
| App Install | Yes |  |
| Launched App | Yes |  |
| Completed Registration | Yes | `Registration Method` |
| Achieved Level | Yes | `Content Type`, `Level Number` |
| Unlocked Achievement | Yes | `Achievement Type`, `Achievement ID`, `Description` |
| Initiated Checkout | Yes | `Content Type`, `Content ID`, `Currency`,  `valueToSum` |
| Purchased | Yes | `Content Type`, `Content ID`, `Currency`,  `valueToSum` |
| Purchase Cancelled | No | `Content Type`, `Content ID`, `Currency`,  `valueToSum` |
| Invite | No | `Number Invited` |
| Request | No |  |