1# @ohos.advertising.AutoAdComponent (Carousel Ad Component) 2 3The AutoAdComponent module provides the capability of displaying carousel ads. 4 5> **NOTE** 6> 7> The initial APIs of this module are supported since API version 11. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8 9## Modules to Import 10 11```ts 12import { AutoAdComponent } from '@kit.AdsKit'; 13``` 14 15## AutoAdComponent 16 17AutoAdComponent(adParam: advertising.AdRequestParams, adOptions: advertising.AdOptions, displayOptions: advertising.AdDisplayOptions, interactionListener: advertising.AdInteractionListener): void 18 19Component used to automatically play ads. 20 21**Atomic service API**: This API can be used in atomic services since API version 12. 22 23**System capability**: SystemCapability.Advertising.Ads 24 25**Parameters** 26 27| Name | Type | Mandatory| Description | 28|---------------------|-----------------------------------------------------------------------------------|----|-----------| 29| adParam | advertising.[AdRequestParams](js-apis-advertising.md#adrequestparams) | Yes | Ad request parameters. | 30| adOptions | advertising.[AdOptions](js-apis-advertising.md#adoptions) | Yes | Ad configuration. | 31| displayOptions | advertising.[AdDisplayOptions](js-apis-advertising.md#addisplayoptions) | Yes | Ad display parameters. | 32| interactionListener | advertising.[AdInteractionListener](js-apis-advertising.md#adinteractionlistener) | Yes | Ad status change callback.| 33 34**Example** 35 36```ts 37import { advertising, AutoAdComponent } from '@kit.AdsKit'; 38import { hilog } from '@kit.PerformanceAnalysisKit'; 39 40@Entry 41@Component 42struct Index { 43 private adRequestParams: advertising.AdRequestParams = { 44 // Ad type. 45 adType: 8, 46 // Ad ID. 47 adId: 'testw6vs28auh3' 48 }; 49 private adOptions: advertising.AdOptions = { 50 // Set the maximum ad content rating. 51 adContentClassification: 'A' 52 }; 53 // Ad display parameters. 54 private adDisplayOptions: advertising.AdDisplayOptions = { 55 // Whether to mute the ad. By default, the ad is not muted. 56 mute: false, 57 // Interval at which the carousel items rotate, in ms. The value range is [30000, 120000]. 58 refreshTime: 30000 59 }; 60 61 build() { 62 Column() { 63 // The AutoAdComponent is used to show the carousel ad in non-full-screen mode. 64 AutoAdComponent({ 65 adParam: this.adRequestParams, 66 adOptions: this.adOptions, 67 displayOptions: this.adDisplayOptions, 68 interactionListener: { 69 // Ad status change callback. 70 onStatusChanged: (status: string, ad: advertising.Advertisement, data: string) => { 71 switch (status) { 72 case 'onAdOpen': 73 hilog.info(0x0000, 'testTag', 'onAdOpen'); 74 break; 75 case 'onAdClick': 76 hilog.info(0x0000, 'testTag', 'onAdClick'); 77 break; 78 case 'onAdClose': 79 hilog.info(0x0000, 'testTag', 'onAdClose'); 80 break; 81 } 82 } 83 } 84 }) 85 .width('100%') 86 .height('100%') 87 } 88 .width('100%') 89 .height('100%') 90 } 91} 92``` 93