Skip to main content

GraphQL API

You can integrate banners into your frontend applications using our BannerGraphQl API. This API allows developers to retrieve banner placeholders with context-awareness (based on page, product, category, cart, etc.) and to track user impressions and clicks for analytics.

tip

Before start work with API use this commands to receive the extension via composer and install them:

composer require mirasvit/module-banner-graph-ql
php -f bin/magento module:enable Mirasvit_BannerGraphQl
php -f bin/magento setup:upgrade

Don't forget to clear the cache and deploy static view files.

Use this API to dynamically insert promotional banners in any storefront area and monitor their performance.

For general GraphQL usage, refer to the Magento GraphQL Developer Guide.

The BannerGraphQl API provides the following object types:

  • mstBannerPlaceholder: defines banner placeholder blocks
  • mstBannerBanner: defines individual banners
  • mstBannerContextInput: input type for contextual filtering
  • Two mutations: for tracking banner impressions and clicks

The Query object can contain the following attributes:

AttributeDescriptionData Type
mstBannerPlaceholdersList of banner placeholders filtered by position and contextmstBannerPlaceholder

mstBannerPlaceholder object

Represents a placeholder where banners are rendered on the storefront.

AttributeDescriptionData Type
identifierUnique placeholder IDString!
rendererRendering mode (e.g. popup, slider, block)String!
cssCustom CSS stylingString
delayDelay before display (Popup, Lightbox)Int
cookieLifetimeCookie lifetime in secondsInt
timeoutAutoplay timeout (Slider)Int
prevPrevious button selector (Slider)String
nextNext button selector (Slider)String
closeClose button selector (Lightbox)String
autoplayAutoplay enabled (Slider)Boolean
loopLoop banners (Slider)Boolean
navigationShow navigation arrows (Slider)Boolean
paginationShow pagination dots (Slider)Boolean
popupPositionPosition on screen (Popup)String
maskColorOverlay mask color (Lightbox)String
bannersList of banners inside the placeholdermstBannerBanner!

mstBannerBanner object

Represents the actual banner rendered inside a placeholder.

AttributeDescriptionData Type
banner_idUnique ID of the bannerInt!
contentHTML content of the bannerString!

mstBannerContextInput object

Input object used to define the current page context (optional). Helps filter and personalize which banners should be displayed.

AttributeDescriptionData Type
actionNameMagento full action nameString
uriPage URI (e.g., /product/sneakers.html)String
categoryIdCurrent category IDInt
productIdCurrent product IDInt
cartIdCart identifier (quote ID)String

Mutation object

The Mutation object can contain the following attributes:

AttributeDescriptionData Type
mstBannerTrackImpressionTracks banner impression (viewed)Boolean!
mstBannerTrackClickTracks banner clickBoolean!

mstBannerTrackImpression Mutation

Tracks when a banner is displayed on the frontend.

AttributeDescriptionData Type
bannerIdID of the viewed bannerInt!
referrerPage where the banner was shownString!

Example for impression tracking:

mutation {
mstBannerTrackImpression(bannerId: 101, referrer: "/product/sneakers.html")
}

mstBannerTrackClick Mutation

Tracks when a customer clicks on a banner.

AttributeDescriptionData Type
bannerIdID of the clicked bannerInt!
referrerPage where the banner was clickedString!

Example for click tracking:

mutation {
mstBannerTrackClick(bannerId: 101, referrer: "/product/sneakers.html")
}

GraphQL example

An example query that uses mstBannerPlaceholders to retrieve banners assigned to the popup position,
based on the context of a product page.

query GetPopupBanners {
mstBannerPlaceholders(
position: "popup",
context: {
uri: "/product/sneakers.html",
productId: 123,
categoryId: 7,
cartId: "abcde12345"
}
) {
identifier
renderer
css
delay
autoplay
popupPosition
banners {
banner_id
content
}
}
}