Class TAds

Unit

Declaration

type TAds = class(TComponent)

Description

Advertisements in game. Right now only on Android (does nothing on other platforms, as CastleMessaging does nothing on non-Android platforms).

Usage:

  1. Create an instance of this class (only a single instance allowed).

  2. Initialize at least one ad network using one of the InitializeXxx methods. Usually you want to call the initialization from TCastleApplication.OnInitialize.

  3. Use remaining methods of this class to show / hide ads, like ShowFullScreenAd, ShowBanner, HideBanner.

  4. To include the necessary integration code in your Android project, add the appropriate services (admob, chartboost, startapp...) inside CastleEngineManifest.xml . See https://castle-engine.io/android_services .

Source: services/castleads.pas (line 99).

Hierarchy

  • TObject
  • TPersistent
  • TComponent
  • TAds
Show Additional Members:

Overview

Methods

Protected procedure FullScreenAdClosed(const WatchedStatus: TAdWatchStatus); virtual;
Protected procedure ConsentGathered(const ACanRequestAds, APrivacyOptionsRequired: Boolean; const ErrorCode: Integer); virtual;
Public constructor Create(AOwner: TComponent); override;
Public destructor Destroy; override;
Public procedure InitializeAdMob(const BannerUnitId, InterstitialUnitId, RewardedUnitId: string; const TestDeviceIds: array of string); overload;
Public procedure InitializeAdMob(const BannerUnitId, InterstitialUnitId: string; const TestDeviceIds: array of string); overload;
Public procedure InitializeAdMobWithConsent( const BannerUnitId, InterstitialUnitId, RewardedUnitId: string; const TestDeviceIds: array of string; const DebugForceEea: Boolean; const DebugDeviceHashes: array of string); overload;
Public procedure InitializeAdMobWithConsent( const BannerUnitId, InterstitialUnitId, RewardedUnitId: string; const TestDeviceIds: array of string); overload;
Public procedure ShowConsentPrivacyOptions;
Public procedure ResetConsent;
Public procedure InitializeStartapp(const AppId: string);
Public procedure InitializeChartboost(const AppId, AppSignature: string);
Public procedure ShowFullScreenAd(const AdNetwork: TAdNetwork; const AdType: TFullScreenAdType; const WaitUntilLoaded: boolean);
Public procedure ShowBanner(const AdNetwork: TAdNetwork; const HorizontalGravity: THorizontalPosition; const VerticalGravity: TVerticalPosition);
Public procedure HideBanner(const AdNetwork: TAdNetwork);

Properties

Public property OnFullScreenAdClosed: TAdClosedEvent read FOnFullScreenAdClosed write FOnFullScreenAdClosed;
Public property OnConsentGathered: TConsentGatheredEvent read FOnConsentGathered write FOnConsentGathered;
Public property CanRequestAds: Boolean read FCanRequestAds;
Public property PrivacyOptionsRequired: Boolean read FPrivacyOptionsRequired;
Public property BannerSize: TRectangle read FBannerSize;

Description

Methods

Protected procedure FullScreenAdClosed(const WatchedStatus: TAdWatchStatus); virtual;

This item has no description.

Source: services/castleads.pas (line 182).

Protected procedure ConsentGathered(const ACanRequestAds, APrivacyOptionsRequired: Boolean; const ErrorCode: Integer); virtual;

Called when the user consent was gathered, see TConsentGatheredEvent.

Source: services/castleads.pas (line 184).

Public constructor Create(AOwner: TComponent); override;

This item has no description.

Source: services/castleads.pas (line 187).

Public destructor Destroy; override;

This item has no description.

Source: services/castleads.pas (line 188).

Public procedure InitializeAdMob(const BannerUnitId, InterstitialUnitId, RewardedUnitId: string; const TestDeviceIds: array of string); overload;

Initialize AdMob ads. You need to create the unit ids on AdMob website (or use TestAdMobBannerUnitId, TestAdMobInterstitialUnitId for testing).

This is usually called from TCastleApplication.OnInitialize.

Parameters
TestDeviceIds
List of devices where you always want to see "test ads" — even if you use real (non-test) ad units.

This is useful when you test ads in your application (with real ad units, on a real phone). Paste here the list of your devices (see https://developers.google.com/mobile-ads-sdk/docs/admob/android/quick-start , you can see your device ids in "adb logcat" output) in order to avoid getting banned for clicking on your own ads.

Source: services/castleads.pas (line 205).

Public procedure InitializeAdMob(const BannerUnitId, InterstitialUnitId: string; const TestDeviceIds: array of string); overload;

This item has no description.

Source: services/castleads.pas (line 208).

Public procedure InitializeAdMobWithConsent( const BannerUnitId, InterstitialUnitId, RewardedUnitId: string; const TestDeviceIds: array of string; const DebugForceEea: Boolean; const DebugDeviceHashes: array of string); overload;

Initialize AdMob ads, gathering the user consent first, using the Google User Messaging Platform (UMP).

Google requires a consent management platform for the users in the European Economic Area and the UK, and requires that no ad is requested before such user has answered the consent form. This method does exactly that: the consent form is shown when it is required, and the ads SDK is initialized only once the answer allows requesting ads. Where no consent is required, e.g. outside of Europe, nothing is shown to the user and the ads are initialized right away.

The consent messages have to be configured in your AdMob account first, see https://support.google.com/admob/answer/10113005 .

When the consent has been gathered, OnConsentGathered is called and CanRequestAds, PrivacyOptionsRequired are updated.

Note that this does not make your application compliant by itself. In particular, when PrivacyOptionsRequired is True, you have to show your own entry point (e.g. a button in the settings) that calls ShowConsentPrivacyOptions.

Usually called from TCastleApplication.OnInitialize, instead of InitializeAdMob.

Parameters
DebugForceEea
Pretend that the device is in the European Economic Area, to see the consent form outside of it. Testing only, and it works only on the devices listed in DebugDeviceHashes.
DebugDeviceHashes
Devices where DebugForceEea works. The hash of a device is printed by the UMP SDK to the log, visible in "adb logcat", when the consent is gathered on it for the first time.

Source: services/castleads.pas (line 243).

Public procedure InitializeAdMobWithConsent( const BannerUnitId, InterstitialUnitId, RewardedUnitId: string; const TestDeviceIds: array of string); overload;

Initialize AdMob ads, gathering the user consent first, without the testing parameters.

Source: services/castleads.pas (line 251).

Public procedure ShowConsentPrivacyOptions;

Show the form that lets the user change or withdraw the consent given earlier. Show it from your own entry point (e.g. a button in the settings) whenever PrivacyOptionsRequired is True. Does nothing when the consent was not gathered.

Source: services/castleads.pas (line 259).

Public procedure ResetConsent;

Forget the gathered consent, so that the next application run asks again. Testing only.

Source: services/castleads.pas (line 263).

Public procedure InitializeStartapp(const AppId: string);

Initialize StartApp ads. You need to register your game on http://startapp.com/ to get app id.

Usually called from TCastleApplication.OnInitialize.

Source: services/castleads.pas (line 269).

Public procedure InitializeChartboost(const AppId, AppSignature: string);

Initialize Chartboost ads. You need to register your game on http://chartboost.com/ to get app id and signature.

Usually called from TCastleApplication.OnInitialize.

Source: services/castleads.pas (line 275).

Public procedure ShowFullScreenAd(const AdNetwork: TAdNetwork; const AdType: TFullScreenAdType; const WaitUntilLoaded: boolean);

Show full-screen ad, interstitial (in-between) or reward ad.

Not all ad networks support (or differentiate between) all full-screen ad types possible in TFullScreenAdType enumeration. So we eventually show other sensible ad type instead.

If WaitUntilLoaded, then we wait until the ad contents are fetched (be sure to show some "loading" state to user, as it may take a while in case of a slow network). If not WaitUntilLoaded, then we immediately resign if ad is not loaded yet. Not all ad implementations support this setting reliably, so this is only a suggestion.

In any case, after this method is called, we make sure to call callback OnFullScreenAdClosed sometime.

Source: services/castleads.pas (line 291).

Public procedure ShowBanner(const AdNetwork: TAdNetwork; const HorizontalGravity: THorizontalPosition; const VerticalGravity: TVerticalPosition);

Show banner ad. Banners are not supported by all ad networks (only AdMob now), in case they are unsupported this call is silently ignored.

Source: services/castleads.pas (line 298).

Public procedure HideBanner(const AdNetwork: TAdNetwork);

Hide banner ad. Banners are not supported by all ad networks (only AdMob now), in case they are unsupported this call is silently ignored.

Source: services/castleads.pas (line 305).

Properties

Public property OnFullScreenAdClosed: TAdClosedEvent read FOnFullScreenAdClosed write FOnFullScreenAdClosed;

This item has no description.

Source: services/castleads.pas (line 307).

Public property OnConsentGathered: TConsentGatheredEvent read FOnConsentGathered write FOnConsentGathered;

Called when the user consent was gathered, see InitializeAdMobWithConsent.

Source: services/castleads.pas (line 312).

Public property CanRequestAds: Boolean read FCanRequestAds;

Whether we may request ads. It is True unless the consent was gathered (see InitializeAdMobWithConsent) and the answer does not allow requesting ads.

Source: services/castleads.pas (line 318).

Public property PrivacyOptionsRequired: Boolean read FPrivacyOptionsRequired;

Whether your application has to show an entry point calling ShowConsentPrivacyOptions. Meaningful only after the consent was gathered, see InitializeAdMobWithConsent.

Source: services/castleads.pas (line 323).

Public property BannerSize: TRectangle read FBannerSize;

This item has no description.

Source: services/castleads.pas (line 325).


Generated by PasDoc 1.0.4.