Skip to main content

Troubleshooting

1. gladsdk.cmd not used

All APIs in NAM SDK must be used within functions added to the gladsdk command queue (gladsdk.cmd).

Initialize window.gladsdk command queue

window.gladsdk = window.gladsdk || { cmd: [] };

Call from a callback function added to the window.gladsdk.cmd array when using the NAM SDK API

  • Incorrect code

    // gladsdk.cmd not used
    window.gladsdk.defineAdSlot(adSlotInfo);
  • Recommended code

    window.gladsdk.cmd.push(function () {
    window.gladsdk.defineAdSlot(adSlotInfo);
    });

2. Issues caused by gladsdk scope chaining

If window.gladsdk is allocated to a local variable (or member variable) and is not redeclared in the gladsdk.cmd.push callback function, the default object will appear to be gladsdk that is not initialized within the callback function.
In the case of the non-initialized object appearing, the gladsdk API is unavailable.

  • Incorrect code

    window.gladsdk = window.gladsdk || { cmd: [] };

    var gladsdk = window.gladsdk;

    gladsdk.cmd.push(function() {
    // `gladsdk` object does not have the `defineAdSlot` method in this funcion scope
    var targetAdSlot = gladsdk.defineAdSlot({
    ...
    });
    });
  • [Solution 1] Redeclare gladsdk within the callback function.

    window.gladsdk = window.gladsdk || { cmd: [] };

    var gladsdk = window.gladsdk;

    gladsdk.cmd.push(function() {
    var gladsdk = window.gladsdk;
    var targetAdSlot = gladsdk.defineAdSlot({
    ...
    });
    });
  • [Solution 2] Use window.gladsdk at all times.

    window.gladsdk = window.gladsdk || { cmd: [] };

    window.gladsdk.cmd.push(function() {
    var targetAdSlot = window.gladsdk.defineAdSlot({
    ...
    });
    });