Module: dfp-script

A directive for supplying additional JavaScript to configure an ad slot.

Since our library does not cover all parts of the GPT library, it may be necessary to add your own, additional JavaScript to further configure an ad slot. For this, the dfp-script directive allows writing inline or external JS and manipulate the ad slot. More precisely, the library will inject the slot object (which can be renamed) into the scope of the JavaScript. Moreover, you may inject your own scope object that will be available inside the script.

The dfp-script tag must be nested directly under the main dfp-ad tag.

License:
  • Apache Copyright 2016 Google Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Example

Example usage of the `dfp-script` directive.

<dfp-ad ad-unit="path/to/my/ad-unit">
  <dfp-script slot-as="mySlot" scope="{ path: 'spaghetti' }">
    if (mySlot.getAdUnitPath() === scope.path) {
      mySlot.clearTargeting();
    }
  </dfp-script>
</dfp-ad>

Classes

DFPScriptError