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