Class
AdService
NotCreatableService
The service responsible for in-experience advertising.
AdService is responsible for in-experience advertising. This includes
rewarded video and
ad integrations.
Methods 8#
| CreateAdRewardFromDevProductId | Creates an AdReward to give users who watch a video ad. |
| GetAdAvailabilityNowAsync | Checks if an ad with the specified format is available to be shown to the
LocalPlayer.Yields |
| GetCampaignEligibilityAsync | Checks a Player's eligibility to be shown an
ad integration
campaign.Yields |
| RegisterAdOpportunityAsync | Tracks how many times a user had the chance to watch a video ad and the rate at which they actually watched the ad.Yields |
| RegisterDisclosureButton | Registers an ad disclosure button for an ad integration. |
| ShowRewardedVideoAdAsync | Plays the video ad to the current user inside the experience.Yields |
| ShowVideoAd | Show mobile video advertisements.Deprecated |
| UnregisterAdOpportunity | Stops 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.
| Name | Type | Default | Description |
|---|---|---|---|
devProductId | int64 | The ID of the developer product you want to grant as a reward. |
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.
| Name | Type | Default | Description |
|---|---|---|---|
adFormat | AdFormat | The 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.
| Name | Type | Default | Description |
|---|---|---|---|
campaignId | string | The ID of the campaign that you want to check a Player's
eligibility for. | |
player | Player? | nil | The 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.
| Name | Type | Default | Description |
|---|---|---|---|
instance | Instance | The GuiButton to track as a rewarded video ad opportunity.
Must be a descendant of a ScreenGui. | |
placementId | int64? | 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.
| Name | Type | Default | Description |
|---|---|---|---|
disclosureButton | GuiButton | The GuiButton you want to mark as an ad integration
disclosure. The GuiButton must follow labeling guidelines
outlined
here. | |
adIntegrationPlacementId | string | The 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.
| Name | Type | Default | Description |
|---|---|---|---|
player | Player | The Player to trigger a rewarded video ad play for. | |
reward | AdReward | The AdReward to grant the user after they view the ad. | |
placementId | int64? | The ID of the placement of the rewarded video ad inside the experience. Allows for reporting on the performance of individual ad placements. |
Returns
ShowAdResult— TheShowAdResultof the client's ad presentation. You should not use this result to grant the reward. Instead, you should grant the reward from yourProcessReceiptimplementation. For developer products earned through rewarded video ads, thereceipt.ProductPurchaseChannelwill beProductPurchaseChannel.AdReward.
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.
| Name | Type | Default | Description |
|---|---|---|---|
instance | Instance | The instance to stop tracking. This should be an instance that you
previously passed to
RegisterAdOpportunityAsync(). |
Returns
()
Events 1#
| VideoAdClosed | Fires 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.
| Name | Type | Default | Description |
|---|---|---|---|
adShown | boolean |
Inherited members#
Inherited from Instance 58
Properties (10)
Archivable, archivable, Capabilities, IsInSandbox, Name, Parent, PredictionMode, RobloxLocked, Sandboxed, UniqueId
Methods (39)
AddTag, children, ClearAllChildren, Clone, clone, Destroy, destroy, FindFirstAncestor, FindFirstAncestorOfClass, FindFirstAncestorWhichIsA, FindFirstChild, findFirstChild, FindFirstChildOfClass, FindFirstChildWhichIsA, FindFirstDescendant, GetActor, GetAttribute, GetAttributeChangedSignal, GetAttributes, GetChildren, getChildren, GetDebugId, GetDescendants, GetFullName, GetStyled, GetStyledPropertyChangedSignal, GetTags, HasTag, IsAncestorOf, IsDescendantOf, isDescendantOf, IsPropertyModified, QueryDescendants, Remove, remove, RemoveTag, ResetPropertyToDefault, SetAttribute, WaitForChild