# Unity Ads / Snapchat Playable Ad and MRAID usage

**URL:** <https://forum.playcanvas.com/t/unity-ads-snapchat-playable-ad-and-mraid-usage/27407>\
**Category:** Help & Support\
**Tags:** scripting\
**Created:** [September 7, 2022, 3:50pm UTC](https://forum.playcanvas.com/t/unity-ads-snapchat-playable-ad-and-mraid-usage/27407 "2022-09-07T15:50:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![MaxD](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/maxd/32/15943_2.png) [@MaxD](https://forum.playcanvas.com/u/MaxD)\
**Post date:** [September 7, 2022, 3:50pm UTC](https://forum.playcanvas.com/t/unity-ads-snapchat-playable-ad-and-mraid-usage/27407/1 "2022-09-07T15:50:48Z")

</div>

Looking at the sample project called Cube Jump ([PlayCanvas | HTML5 Game Engine](https://playcanvas.com/editor/scene/1155440)) while developing the Playable Ads for various platforms I came to the point where I need help / suggestions.

In the beginning I was making a playable for UnityAds which utilizes mraid.js various functions and made a script which loads before the engine:

```javascript
if (mraid && mraid.getState() === 'loading') {
    mraid.addEventListener('ready', onSdkReady);
} else {
    onSdkReady();
}

function onSdkReady() {
    mraid.addEventListener('viewableChange', viewableChangeHandler);
    // Wait for the ad to become viewable for the first time
    if (mraid.isViewable()) {
        if (pc.Application.getApplication()) {
            pc.app.fire('playable:viewable');
        } 
    }
}

function pcGameReady() {
    if (pc && pc.Application.getApplication() && mraid && mraid.isViewable()) {
        pc.app.fire('playable:viewable');
        pc.app.fire('music:play');
    }
}

```

In the start.js script we use:

```javascript
Start.prototype.postInitialize = function() {
    pcGameReady();
};

```

The challenge for the Snapchat Playable Ads is to utilize these mraid.getState() and mraid.isViewable().

BTW the Rest-Api-Tool fails on having before-engine scripts and “extern\_files.enabled”: true.

💻 The question is should we try to make playable utilize the features of the mraid or we should keep it simple without too much over-engineering ?

Thanks in advance 🚀

---

<div class="post-metadata">

**Author:** ![yaustar](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/yaustar/32/2268_2.png) [@yaustar](https://forum.playcanvas.com/u/yaustar)\
**Post date:** [September 8, 2022, 8:27am UTC](https://forum.playcanvas.com/t/unity-ads-snapchat-playable-ad-and-mraid-usage/27407/2 "2022-09-08T08:27:55Z")

</div>

Is this the same issue? [https://github.com/playcanvas/playcanvas-rest-api-tools/issues/41](https://github.com/playcanvas/playcanvas-rest-api-tools/issues/41)

---

<div class="post-metadata">

**Author:** ![MaxD](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/maxd/32/15943_2.png) [@MaxD](https://forum.playcanvas.com/u/MaxD)\
**Post date:** [September 9, 2022, 8:56am UTC](https://forum.playcanvas.com/t/unity-ads-snapchat-playable-ad-and-mraid-usage/27407/3 "2022-09-09T08:56:43Z")

</div>

> Is this the same issue? [https://github.com/playcanvas/playcanvas-rest-api-tools/issues/41](https://github.com/playcanvas/playcanvas-rest-api-tools/issues/41)

[yaustar](https://forum.playcanvas.com/u/yaustar) Yes, this is related.

Do you know about the support of mraid.getState() and mraid.isViewable() in Snap Playable Ads?

Since Snap do not have a Playable test tool it will be a challenge to live test it.

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![yaustar](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/yaustar/32/2268_2.png) [@yaustar](https://forum.playcanvas.com/u/yaustar)\
**Post date:** [September 9, 2022, 9:19am UTC](https://forum.playcanvas.com/t/unity-ads-snapchat-playable-ad-and-mraid-usage/27407/4 "2022-09-09T09:19:30Z")

</div>

> [@MaxD](#):
>
> Do you know about the support of mraid.getState() and mraid.isViewable() in Snap Playable Ads?

Unfortunately, I don’t ☹ You will have to ask through your Snap contact. AFAIK, if it’s part of MRAID, it _should_ be support but don’t quote me on that

---

<div class="post-metadata">

**Author:** ![yaustar](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/yaustar/32/2268_2.png) [@yaustar](https://forum.playcanvas.com/u/yaustar)\
**Post date:** [September 9, 2022, 9:20am UTC](https://forum.playcanvas.com/t/unity-ads-snapchat-playable-ad-and-mraid-usage/27407/5 "2022-09-09T09:20:36Z")

</div>

I also have a branch/PR waiting with the fix for the issue with the script being added before the engine: [https://github.com/playcanvas/playcanvas-rest-api-tools/pull/43](https://github.com/playcanvas/playcanvas-rest-api-tools/pull/43)

---

<div class="post-metadata">

**Author:** ![MaxD](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/maxd/32/15943_2.png) [@MaxD](https://forum.playcanvas.com/u/MaxD)\
**Post date:** [September 9, 2022, 10:03am UTC](https://forum.playcanvas.com/t/unity-ads-snapchat-playable-ad-and-mraid-usage/27407/6 "2022-09-09T10:03:21Z")

</div>

Thank you for your help, I’ll will post here an update regarding the MRAID thenever I will have some details on that. Thanks one’s again !
