Skip to content

Instantly share code, notes, and snippets.

@zv3
Created May 18, 2016 21:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zv3/ee8d0c1a6f52c3a87be1506b4b8c9ab3 to your computer and use it in GitHub Desktop.
Save zv3/ee8d0c1a6f52c3a87be1506b4b8c9ab3 to your computer and use it in GitHub Desktop.
Google Publisher Tag (DFP) Scala.js façade
package client.facades
import scala.scalajs.js
import scala.scalajs.js.annotation.{JSName, ScalaJSDefined}
import scala.scalajs.js.|
/*
Don't forget to include the GPT JS script fetching code (sync or async) at the head HTML tag!
*/
object GoogleTagTypes {
type GeneralSize = SingleSize | MultiSize
type MultiSize = js.Array[SingleSize]
type NamedSize = String
type SingleSize = SingleSizeArray | NamedSize
type SingleSizeArray = js.Tuple2[Int, Int]
type SizeMapping = js.Tuple2[SingleSizeArray, GeneralSize]
type SizeMappingArray = js.Array[SizeMapping]
val SingleSizeArray = js.Tuple2[Int, Int] _
}
@JSName("googletag")
@js.native
object GoogleTag extends js.Object {
def pubads(): PubAdsService = js.native
def defineSlot(adUnitPath: String, size: GoogleTagTypes.GeneralSize, div: js.UndefOr[String] = js.undefined): Slot = js.native
def destroySlots(slots: js.Array[Slot]): Boolean = js.native
def sizeMapping(): SizeMappingBuilder = js.native
def enableServices(): Unit = js.native
def display(div: String): Unit = js.native
def enableSingleRequest(): Unit = js.native
@js.native
object cmd extends js.Object {
def push(func: js.Function0[Any]): Unit = js.native
}
}
@js.native
trait Service extends js.Object {
def addEventListener(eventType: String, listener: js.Function1[SlotRenderedEvent, Any]): this.type = js.native
}
@js.native
trait Slot extends js.Object {
def addService(service: Service): this.type = js.native
def setTargeting(key: String, value: String | js.Array[String]): this.type = js.native
def defineSizeMapping(sizeMapping: GoogleTagTypes.SizeMappingArray): this.type = js.native
def getSlotElementId(): String = js.native
def setCollapseEmptyDiv(shouldCollapseAfter: Boolean, shouldCollapseBefore: js.UndefOr[Boolean] = js.undefined): this.type = js.native
}
@js.native
trait PubAdsService extends Service {
def setTargeting(key: String, value: String | js.Array[String]): this.type = js.native
def refresh(slots: js.UndefOr[js.Array[Slot]] = js.undefined, changeCorrelator: js.UndefOr[ChangeCorrelator] = js.undefined): Unit = js.native
def collapseEmptyDivs(boolean: js.UndefOr[Boolean] = js.undefined): Boolean = js.native
def display(adUnitPath: String, size: GoogleTagTypes.GeneralSize, div: js.UndefOr[String] = js.undefined, clickUrl: js.UndefOr[String] = js.undefined): Unit = js.native
def enableSingleRequest(): Boolean = js.native
}
@js.native
trait SizeMappingBuilder extends js.Object {
def addSize(viewportSize: GoogleTagTypes.SingleSizeArray, slotSize: GoogleTagTypes.GeneralSize): this.type = js.native
def build(): GoogleTagTypes.SizeMappingArray = js.native
}
@ScalaJSDefined
trait ChangeCorrelator extends js.Any {
val changeCorrelator: Boolean
}
@js.native
trait SlotRenderedEvent extends js.Object {
val creativeId : Null | Int
val isEmpty : Boolean
val lineItemId : Null | Int
val serviceName : String
val size : GoogleTagTypes.SingleSize
val slot : Slot
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment