Initialize Customer (Register/Identify)
Register or update a customer whenever they log in or register in your app. This allows Gameball to attach events and rewards to the customer profile.
import 'package:gameball_flutter/gameball_flutter.dart' ;
final attributes = CustomerAttributesBuilder ()
. displayName ( "John Doe" )
. firstName ( "John" )
. lastName ( "Doe" )
. email ( "john@example.com" )
. mobile ( "+1234567890" )
. preferredLanguage ( "en" )
. addCustomAttribute ( "loyaltyTier" , "gold" )
. addCustomAttribute ( "country" , "USA" )
. build ();
final request = InitializeCustomerRequestBuilder ()
. customerId ( "customer-123" )
. customerAttributes (attributes)
. build ();
final gameballApp = GameballApp . getInstance ();
gameballApp. initializeCustomer (request, (response, error) {
if (error == null ) {
print ( "Customer initialized successfully" );
} else {
print ( "Error: $ error " );
}
});
// With session token override
gameballApp. initializeCustomer (request, (response, error) {
// Handle response
}, sessionToken : "custom-token" );
Request Parameters
Unique identifier for the customer. This should never change for a given customer.
Customer attributes built using CustomerAttributesBuilder.
Device token for push notifications (FCM or HMS).
Push notification provider: PushProvider.Firebase or PushProvider.Huawei.
Optional session token to override the global token for this specific request.
In Flutter SDK, passing a sessionToken parameter updates the global token. Pass null to clear, or omit to use the current global token.
Validation Rules
InitializeCustomerRequest requires:
customerId cannot be null or empty
If deviceToken is provided, pushProvider must also be specified
If pushProvider is specified, deviceToken must also be provided
CustomerAttributesBuilder Methods
Build customer attributes using the builder pattern:
Show CustomerAttributes Builder Methods
Sets the display name of the customer.
Sets the first name of the customer.
Sets the last name of the customer.
Sets customer’s email address.
Sets customer’s mobile number.
Sets gender: “M” for male, “F” for female.
Sets date of birth in format YYYY-MM-DD.
Sets join date in format YYYY-MM-DD.
preferredLanguage(String)
Sets the preferred language for notifications.
addCustomAttribute(String, String)
Adds a custom attribute key-value pair.
Sets all custom attributes at once.
addAdditionalAttribute(String, String)
Adds an additional attribute key-value pair.
additionalAttributes(Map)
Sets all additional attributes at once.
Choose an Unchangeable Customer ID The customer ID should be a permanent identifier that will NEVER change. Avoid using email or phone number as the customer ID since these can be updated by users.
Display the Gameball customer profile widget to show rewards, campaigns, and leaderboards:
import 'package:gameball_flutter/gameball_flutter.dart' ;
final profileRequest = ShowProfileRequestBuilder ()
. customerId ( "customer-123" )
. openDetail ( "rewards" ) // optional
. hideNavigation ( false ) // optional
. showCloseButton ( true ) // optional
. closeButtonColor ( "#FF6B6B" ) // optional
. widgetUrlPrefix ( "custom-prefix" ) // optional
. build ();
final gameballApp = GameballApp . getInstance ();
gameballApp. showProfile (context, profileRequest);
The Flutter BuildContext from your widget.
The customer’s unique identifier.
Specific detail to open in the profile.
Hide navigation elements.
Show close button (defaults to true).
Close button color in hex format (e.g., “#FF0000”).
Custom widget URL prefix.
Validation Rules
ShowProfileRequest requires:
customerId cannot be null or empty
closeButtonColor must be in hex format (#RRGGBB) if provided
Full Example
class ProfileScreen extends StatelessWidget {
@override
Widget build ( BuildContext context) {
return Scaffold (
appBar : AppBar (title : Text ( 'My Profile' )),
body : Center (
child : ElevatedButton (
onPressed : () {
final profileRequest = ShowProfileRequestBuilder ()
. customerId ( "customer-123" )
. showCloseButton ( true )
. build ();
GameballApp . getInstance (). showProfile (context, profileRequest);
},
child : Text ( 'Open Gameball Profile' ),
),
),
);
}
}
Call registerPlayer when the user logs in or registers to ensure their profile is up-to-date before showing the widget.
Next Steps