Skip to content

Service · inherits Instance

AdService

Official docs ↗

The service responsible for in-experience advertising.

About AdService

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

Methods 7

  • CreateAdRewardFromDevProductId(devProductId: int64) → AdRewardCreates an AdReward to give users who watch a video ad.

    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.

  • GetAdAvailabilityNowAsync(adFormat: AdFormat) → GetAdAvailabilityNowResultYieldsChecks if an ad with the specified format is available to be shown to the LocalPlayer.

    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.

  • GetCampaignEligibilityAsync(campaignId: string, player: Player? = nil) → GetCampaignEligibilityResultYieldsChecks a Player's eligibility to be shown an ad integration campaign.

    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.

  • RegisterAdOpportunityAsync(instance: Instance, placementId: int64?) → ()YieldsTracks how many times a user had the chance to watch a video ad and the rate at which they actually watched the ad.

    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.

  • RegisterDisclosureButton(disclosureButton: GuiButton, adIntegrationPlacementId: string) → ()Registers an ad disclosure button for an ad integration.

    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.

  • ShowRewardedVideoAdAsync(player: Player, reward: AdReward, placementId: int64?) → ShowAdResultYieldsPlays the video ad to the current user inside the experience.

    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.

  • UnregisterAdOpportunity(instance: Instance) → ()Stops tracking an instance that was previously registered with RegisterAdOpportunityAsync.

    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.

AdService also has every member of Instance. Deprecated and Roblox-only members are hidden.

Reference text from the Roblox Creator Documentation, licensed CC BY 4.0, reorganized by rbxtoolshub.com · Studio 0.743.0.7431133.