Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help rendering an ad slot based on the state of another ad #27

Open
jdwinall-tm opened this issue Apr 25, 2017 · 3 comments
Open

Help rendering an ad slot based on the state of another ad #27

jdwinall-tm opened this issue Apr 25, 2017 · 3 comments

Comments

@jdwinall-tm
Copy link

jdwinall-tm commented Apr 25, 2017

I have three ads on a page with ids half-page, top-medium-rectangle & bottom-medium-rectangle.

How would I implement the following?

I want to render half-page on desktop with two conditions:

  • If half-page renders and the contents are empty, I want to render two different ad slots: top-medium-rectangle & bottom-medium-rectangle.
  • If half-page renders and displays an ad, I do not want to show top-medium-rectangle & bottom-medium-rectangle.

This is my custom ad component that uses react-gpt with a TODO console log.

import React, { Component, PropTypes } from 'react'
import { Bling as Gpt, Events } from 'react-gpt' // eslint-disable-line import/no-unresolved

Gpt.configure({renderWhenViewable: true})
Gpt.enableSingleRequest()

Gpt.on(Events.SLOT_RENDER_ENDED, event => {
  const slot = event.slot
  const divId = slot.getSlotElementId()
  const targetingKeys = slot.getTargetingKeys()
  const targeting = targetingKeys.reduce((t, key) => {
    const val = slot.getTargeting(key)
    t[key] = val.length === 1 ? val[0] : val
    return t
  }, {})
  if (debug) {
    if (!event.isEmpty && event.size) {
      console.log(`${targeting.adType} ad creative '${event.creativeId}' is rendered to slot '${divId}' of size '${event.size[0]}x${event.size[1]}'`, event, targeting)
    } else {
      console.log(`${targeting.adType} ad rendered but empty, div id is ${divId}`, event, targeting)
      if (targeting.adType === 'Half Page') {
        console.log('@TODO: Attempt to render Top Medium Rectangle and Bottom Medium Rectangle')
      }
    }
  }
})

class AdGpt extends Component {
  render () {
    const adState = {
      'halfPage': {
        adUnitPath: '/4595/nfl.test.open'
        collapseEmptyDiv: [true, true],
        id: 'half-page',
        sizeMapping: [
          {viewport: [800,0], slot: [300, 600]}
        ],
        targeting: {
          adType: 'Half Page'
        }
      },
      'topMediumRectangle': {
        adUnitPath: '/4595/nfl.test.open'
        collapseEmptyDiv: [true, true],
        id: 'top-medium-rectangle',
        sizeMapping: [
          {viewport: [800,0], slot: [300, 250]}
        ],
        targeting: {
          adType: 'Top Medium Rectangle'
        }
      },
      'bottomMediumRectangle': {
        adUnitPath: '/4595/nfl.test.open'
        collapseEmptyDiv: [true, true],
        id: 'bottom-medium-rectangle',
        sizeMapping: [
          {viewport: [800,0], slot: [300, 250]}
        ],
        targeting: {
          adType: 'Bottom Medium Rectangle'
        }
      },
    }

    return (
      <div>
        <Gpt {...adState[this.props.name]} />
      </div>
    )
  }
}

export default AdGpt

And this is how I am using it:

import React from 'react'
import AdGpt from 'components/AdGpt'

const Test = props => {
  return (
    <div>
      <AdGpt
        name={['halfPage']} />

      <AdGpt
        name={['topMediumRectangle']} />

      <AdGpt
        name={['bottomMediumRectangle']} />
    </div>
  )
}

export default
@apotek
Copy link

apotek commented Apr 28, 2017

Very interested in these kinds of conditional solutions based on viewport and previous ad delivery events within the same page. There must be a pattern for this to follow. Curious to see what comes of this thread.

@jdwinall-tm
Copy link
Author

Is this functionality possible? @blakemcintyre @potench @hewholived @potenchious @taak77

@dbredvick
Copy link

I know this issue is almost four years old, but does anyone have a solution for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants