Roblox UtilitiesDevlHub Roblox Documentation

Class

AdService

NotCreatableService
Inherits
Instance › Object
Memory category
Instances

The service responsible for in-experience advertising.

AdService is responsible for in-experience advertising. This includes rewarded video and ad integrations.

Methods 8#

CreateAdRewardFromDevProductIdCreates an AdReward to give users who watch a video ad.
GetAdAvailabilityNowAsyncChecks if an ad with the specified format is available to be shown to the LocalPlayer.Yields
GetCampaignEligibilityAsyncChecks a Player's eligibility to be shown an ad integration campaign.Yields
RegisterAdOpportunityAsyncTracks how many times a user had the chance to watch a video ad and the rate at which they actually watched the ad.Yields
RegisterDisclosureButtonRegisters an ad disclosure button for an ad integration.
ShowRewardedVideoAdAsyncPlays the video ad to the current user inside the experience.Yields
ShowVideoAdShow mobile video advertisements.Deprecated
UnregisterAdOpportunityStops tracking an instance that was previously registered with RegisterAdOpportunityAsync.

CreateAdRewardFromDevProductId(devProductId: int64): AdReward#

Constructs an AdReward that wraps the given developer product so it can be passed to ShowRewardedVideoAdAsync. When the user watches the entire rewarded video ad, the developer product identified by devProductId is granted through the ProcessReceipt callback with a ProductPurchaseChannel of ProductPurchaseChannel.AdReward.

NameTypeDefaultDescription
devProductIdint64The ID of the developer product you want to grant as a reward.
Returns
  • AdReward — An AdReward configured as a developer product reward for the specified product.

GetAdAvailabilityNowAsync(adFormat: AdFormat): GetAdAvailabilityNowResult#

Yields

This method may only be called from a Script with RunContext.Client.

Note that you should call this method as close as possible to the moment you plan to show the ad. For example, if you have a "Watch video ad to get a reward" button in a shop menu, only call this method when the user opens the shop menu. This approach improves performance by preventing ads from unnecessarily being held in memory, and it benefits CPM (cost-per-thousand impressions) and earnings by optimizing the ad fill rate.

NameTypeDefaultDescription
adFormatAdFormatThe format of the requested ad. For example, AdFormat.RewardedVideo.
Returns
  • GetAdAvailabilityNowResult — A dictionary that looks like { AdAvailabilityResult: Enum.AdAvailabilityResult }.

GetCampaignEligibilityAsync(campaignId: string, player: Player? = nil): GetCampaignEligibilityResult#

Yields

GetCampaignEligibilityAsync checks whether a Player is eligible to be shown a specific ad integration campaign, returning a dictionary that looks like { IsEligible: boolean }.

Call this method and confirm that result.IsEligible is true before you display any of the campaign's ad integration assets or register their disclosure buttons with RegisterDisclosureButton. All ad integration assets should remain hidden until the Player is confirmed eligible.

When called from the client, the player argument defaults to the LocalPlayer. When called from the server, player is required. The call raises an error if the supplied campaignId exceeds the maximum allowed length.

NameTypeDefaultDescription
campaignIdstringThe ID of the campaign that you want to check a Player's eligibility for.
playerPlayer?nilThe Player you want to check eligibility for. If omitted, it will default to the LocalPlayer. On the server, player argument is required.
Returns
  • GetCampaignEligibilityResult — A dictionary that looks like { IsEligible: boolean }.

RegisterAdOpportunityAsync(instance: Instance, placementId: int64?): ()#

Yields

This method may only be called from a Script with RunContext.Client.

Registers a GuiButton for ad opportunity tracking. Once registered, the system periodically checks whether the button is visible and unobstructed (the topmost input-sinking element at its center point). These visibility transitions are reported as ad opportunity impressions and used to measure the rate at which users are presented with, and choose to watch, rewarded video ads.

The instance must be a GuiButton that is a descendant of a ScreenGui under PlayerGui. If the instance is moved out of a valid hierarchy at runtime, tracking pauses automatically and resumes when it returns to a valid ancestor. Call UnregisterAdOpportunity to stop tracking the instance.

NameTypeDefaultDescription
instanceInstanceThe GuiButton to track as a rewarded video ad opportunity. Must be a descendant of a ScreenGui.
placementIdint64?The ID of the placement of the rewarded video ad inside the experience. Allows for reporting on the performance of individual ad placements.
Returns
  • ()

RegisterDisclosureButton(disclosureButton: GuiButton, adIntegrationPlacementId: string): ()#

This method may only be called from a Script with RunContext.Client.

RegisterDisclosureButton marks a button in your experience as an ad disclosure for an ad integration. When a user clicks it, they can see who is paying for the ad. See ad integrations for guidance on what the disclosures should look like and when they should be visible.

Note: you must verify that the LocalPlayer is eligible to see the associated ad integration campaign by calling GetCampaignEligibilityAsync and verifying that result.IsEligible is true before attempting to register a disclosure button for it. If you do not wait, or the LocalPlayer is not eligible to see the associated campaign, then RegisterDisclosureButton will raise an error.

NameTypeDefaultDescription
disclosureButtonGuiButtonThe GuiButton you want to mark as an ad integration disclosure. The GuiButton must follow labeling guidelines outlined here.
adIntegrationPlacementIdstringThe ID of the placement that this disclosure is attached to.
Returns
  • ()

ShowRewardedVideoAdAsync(player: Player, reward: AdReward, placementId: int64?): ShowAdResult#

Yields

Warning: Rewarded Video ads must be user opt-in and clearly disclosed. For details, review our eligibility requirements and advertising standards.

This method may only be called from a Script with RunContext.Server.

Note: before calling this method, you must first verify that the specified user has a rewarded video ad available to show by calling GetAdAvailabilityNowAsync. If the client does not have an available ad, then ShowRewardedVideoAdAsync will return ShowAdResult.AdNotReady.

NameTypeDefaultDescription
playerPlayerThe Player to trigger a rewarded video ad play for.
rewardAdRewardThe AdReward to grant the user after they view the ad.
placementIdint64?The ID of the placement of the rewarded video ad inside the experience. Allows for reporting on the performance of individual ad placements.
Returns

ShowVideoAd(): ()#

DeprecatedDeprecated

Deprecated. ShowVideoAd has been decommissioned and is no longer operational.

Show mobile video advertisements.

Returns
  • ()

UnregisterAdOpportunity(instance: Instance): ()#

Removes instance from the ad opportunity tracker so that it no longer counts toward the rewarded video ad opportunity reporting started by RegisterAdOpportunityAsync(). Call it once an instance should no longer be treated as an ad opportunity, such as when its associated UI is closed or removed.

If the supplied instance is not currently being tracked, this method has no effect.

NameTypeDefaultDescription
instanceInstanceThe instance to stop tracking. This should be an instance that you previously passed to RegisterAdOpportunityAsync().
Returns
  • ()

Events 1#

VideoAdClosedFires when an AdService video closes.Deprecated

VideoAdClosed(adShown: boolean)#

DeprecatedDeprecated

Deprecated. VideoAdClosed has been decommissioned and is no longer operational.

Fires when an AdService video closes.

NameTypeDefaultDescription
adShownboolean

Inherited members#

Inherited from Instance 58
Inherited from Object 6
Properties (2)

ClassName, className

Events (1)

Changed