SwAdIcon

Ad Placement Four Essentials

  • Use case: app recommendation grid / horizontal row (page top / middle / bottom, inside list feeds; slotKey e.g. home_icon)
  • Industry form: Icon ads (a common format in the domestic market; AdSDK format icon)
  • Visual form: icon + name in a grid (grid) or horizontal row (image) layout
  • Tracking events: same as banner — adImpression (once on entering the viewport via IntersectionObserver) / adClick; built-in zero-config, silent no-op when the tracker gate is off

Picking the wrong scenario = wrong ad_type / timing in tracking. See Ad Component Selection.

SwAdIcon is the icon ad slot component — an "image-type" self-rendering component of the ad foundation. It supports two layouts: grid (multi-icon grid, e.g. a homepage shortcut row) and image (single icon, e.g. a floating entry). Impression / click tracking is built in.

Icon grid (grid, 5 columns)

加载中...

Props

NameTypeRequiredDefaultDescription
itemsSwAdItem[]✓—Ad creative array
slotKeystring✓—Ad slot key → ad_slot_key
slotNamestringundefinedAd slot name → ad_slot_name
pageKeystringundefinedPage key → page_key
pageNamestringundefinedPage name → page_name
ratiostring'1/1'Icon aspect ratio, default square
radiusnumber | string8Corner radius (number = px, string passed to SwImage as-is, e.g. '1.125rem')
showAdLabelbooleanundefined"Ad" compliance badge; when not set it follows the global swiftConfig.ad.showLabel (default true), an explicit value always wins
layout'grid' | 'image''grid'Layout: grid / single icon
gridColumnsnumber | { mobile?, tablet?, desktop? }5grid columns. Object form sets per-breakpoint tiers (<768 / 768-1023 / ≥1024), missing tiers fall back to the nearest one (same pattern as SwGallery columns)
minItemWidthnumber | stringundefinedMinimum card width. A number is treated as px; a string is passed through as-is (same as radius / gridGap). When set and gridColumns is not, the grid switches to auto-fill flow mode (column count adapts to container width); gridColumns takes precedence
gridGapnumber | string8Gap (number = px, string used as-is — can reference a token)

Events

NamePayloadDescription
load—Rendered
empty—items empty
impressionitems: SwAdItem[]Impression (auto tracking)
clickitem: SwAdItemClick (auto tracking)
error—Render / load error

Single-icon mode

layout="image" renders a single icon, suited to a floating campaign entry:

Single icon (image)

加载中...

layout='image' horizontal scroll

加载中...

gridColumns / gridGap tuning

加载中...

Events

加载中...
<!-- Grid shortcut row -->
<SwAdIcon :items="icons" slot-key="home_kingkong" :grid-columns="5" :radius="12" />

<!-- Responsive columns: 4 on mobile / 6 on tablet / 8 on desktop -->
<SwAdIcon :items="icons" slot-key="home_kingkong" :grid-columns="{ mobile: 4, tablet: 6, desktop: 8 }" />

<!-- Flow mode: no locked column count, each card at least 72px wide, columns adapt to container width -->
<SwAdIcon :items="icons" slot-key="home_kingkong" :min-item-width="72" />

<!-- gridGap / radius accept strings: tokens / rem -->
<SwAdIcon :items="icons" slot-key="home_kingkong" grid-gap="0.75rem" radius="1.125rem" />

<!-- Floating single-icon entry -->
<SwAdIcon :items="[entry]" slot-key="float_entry" layout="image" :radius="12" />

CSS variables

Layout is no longer inline style — everything lands as CSS variables, so business CSS can override the layout with plain rules, no !important needed:

VariableDefaultDescription
--sw-ad-icon-gap8pxGrid / row gap (maps to gridGap)
--sw-ad-icon-cols-mobile / --sw-ad-icon-cols-tablet / --sw-ad-icon-cols-desktop5Grid column count per breakpoint (maps to gridColumns)
--sw-ad-icon-min—Minimum card width in flow mode (maps to minItemWidth, flow mode only)
--sw-ad-icon-item-width4.5remCard width of the layout="image" horizontal row

Caveats

  • grid columns are set by gridColumns (number or breakpoint object); setting minItemWidth without gridColumns switches to auto-fill flow mode.
  • image mode ignores gridColumns / minItemWidth; gridGap still applies. With multiple icons the items don't shrink (flex: 0 0 auto) so overflow scrolls horizontally; tune card width via --sw-ad-icon-item-width.
  • Tracking is built in and gated.