Advertisements
Complete guide to requesting and displaying advertisements in your game
Advertisements
After establishing authorization and creating an active game session, you can request advertisements to display to your players. This section covers the process of fetching and implementing advertisements in your game.
Prerequisites
Before requesting advertisements, ensure you have:
- Completed the authorization flow
- Established an active game session
- Maintained regular heartbeat requests for your session
Requesting Advertisements
POST /api/advertisements
This endpoint returns advertisement content based on available campaigns for your game.
Request Parameters
Parameter | Type | Required | Description |
---|---|---|---|
game_uuid | string | Yes | Your game's unique identifier |
auth_token | string | Yes | The active authorization token from your session |
Example Request
{
"game_uuid": "32bde2de-d225-448f-8c6a-263275d93ef2",
"auth_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}
Response Structure
The response contains an ad
object with the following properties:
Field | Type | Description |
---|---|---|
id | number | Unique identifier for the advertisement |
title | string | Advertisement title to display |
description | string | Brief description of the advertisement content |
type | number | Different formats of advertisements. Different types can have different price |
campaign | number | Identifier for the associated advertising campaign |
url | string | Destination URL for user interaction with the advertisement |
media | string | URL to the advertisement's media asset (image, video) |
isActive | boolean | Indicates if the advertisement is currently active |
Example Response
{
"ad": {
"id": 123,
"title": "New Season Sale!",
"description": "Get up to 50% off on all items.",
"type": 1,
"campaign": 456,
"url": "https://example.com/ad/123",
"isActive": true,
"media": "https://example.com/ad/123.png"
}
}
Possible Errors
Status Code | Error Code | Description |
---|---|---|
400 | INVALID_IDENTIFIER | The provided game UUID is invalid |
400 | NO_ACTIVE_SESSION | No active session found for this user |
400 | INVALID_TOKEN | The provided authorization token is invalid |
401 | PREMIUM_USER | The current user has premium status and should not receive advertisements |
404 | NO_ACTIVE_CAMPAIGNS | No active advertising campaigns are available |
404 | NO_ACTIVE_ADS | No active advertisements are available in the current campaigns |
408 | ERR_TIMEOUT | Request timed out, try again later |
500 | INTERNAL_SERVER_ERROR | Internal server error |
Implementing Advertisements
Display Guidelines
-
User Experience: Ensure advertisements do not disrupt critical gameplay moments
-
Tracking: Implement proper click/view tracking by directing users to the provided
url
when they interact with the advertisement
Premium Users
The API will return a PREMIUM_USER
error code when attempting to request advertisements for users with premium status. Your implementation should:
- Handle this error gracefully
- Skip advertisement displays for premium users
- Continue normal game flow without waiting for advertisements
Best Practices
-
Error Handling: Implement robust error handling to ensure the game continues functioning even if advertisement requests fail
-
Timing: Request advertisements slightly before they are needed to account for potential network latency
-
Testing: Thoroughly test advertisement implementation using the development UUID before deploying to production
Next Steps
After implementing advertisements, ensure your application properly maintains sessions through heartbeats and terminates sessions when users exit the game.
For additional support or integration questions, please contact our developer support team.