Skip to content

@get-advantage/advantage / advantage/messaging/creative-side / AdvantageCreativeMessenger

Class: AdvantageCreativeMessenger ​

advantage/messaging/creative-side.AdvantageCreativeMessenger

AdvantageCreativeMessenger is the class that should be used in creative ads to communicate with Advantage on the publisher side. This class is used to request formats and other information from the parent website.

Example

Here's an example on how to request a format from the parent website and then start the ad when the format is confirmed:

typescript
const advantageMessenger = new AdvantageCreativeMessenger();
const session = await advantageMessenger.startSession();

if (session) {
 // Request the midscroll format
 const response = await advantageMessenger.sendMessage({
     action: AdvantageMessageAction.REQUEST_FORMAT,
     format: AdvantageFormatName.Midscroll
 });
 // The format is confirmed, start the ad
 if (response?.action === AdvantageMessageAction.FORMAT_CONFIRMED) {
     document.body.classList.add("midscroll");
 }
} else {
     console.log("Session failed to start");
}
javascript
const advantageMessenger = new AdvantageCreativeMessenger();
advantageMessenger.startSession().then((confirmed) => {
 if (confirmed) {
     advantageMessenger.sendMessage({
         action: "REQUEST_FORMAT",
         format: "MIDSCROLL"
     }).then((response) => {
         if (response.action === "FORMAT_CONFIRMED") {
             // The format is confirmed, start the ad
             document.body.classList.add("midscroll");
         }
     });
 } else {
    console.log("Session failed to start");
 }
});

Constructors ​

constructor ​

• new AdvantageCreativeMessenger(): AdvantageCreativeMessenger

Returns ​

AdvantageCreativeMessenger

Defined in ​

src/advantage/messaging/creative-side.ts:64

Properties ​

#broadcastChannel ​

• Private #broadcastChannel: null | BroadcastChannel = null

Defined in ​

src/advantage/messaging/creative-side.ts:62


#messageChannel ​

• Private #messageChannel: null | MessageChannel = null

Defined in ​

src/advantage/messaging/creative-side.ts:59


#sessionID ​

• Private #sessionID: string

Defined in ​

src/advantage/messaging/creative-side.ts:60


#validSession ​

• Private #validSession: boolean = false

Defined in ​

src/advantage/messaging/creative-side.ts:61

Methods ​

listenToWaypoints ​

▸ listenToWaypoints(onWaypointTrigger): Object

Parameters ​

NameType
onWaypointTrigger(waypointId: string, isIntersecting: boolean) => void

Returns ​

Object

NameType
disconnect() => void

Defined in ​

src/advantage/messaging/creative-side.ts:161


onMessage ​

▸ onMessage(callback): void

Parameters ​

NameType
callback(message: AdvantageMessage) => void

Returns ​

void

Defined in ​

src/advantage/messaging/creative-side.ts:116


sendMessage ​

▸ sendMessage(message): Promise<undefined | AdvantageMessage>

Parameters ​

NameType
messagePartial<AdvantageMessage>

Returns ​

Promise<undefined | AdvantageMessage>

Defined in ​

src/advantage/messaging/creative-side.ts:95


setupWaypoints ​

▸ setupWaypoints(waypoints): Object

Parameters ​

NameType
waypointsHTMLElement[]

Returns ​

Object

NameType
disconnect() => void

Defined in ​

src/advantage/messaging/creative-side.ts:128


startSession ​

▸ startSession(): Promise<boolean>

Returns ​

Promise<boolean>

Defined in ​

src/advantage/messaging/creative-side.ts:78