CPMStar html5

ceosol

  • *
  • Posts: 2263
This isn't really an extension right now, but I wanted to share some things that I found last night. CPMStar works in html5. You need to get your account approved, which might be troublesome if you do not have a sponsor code. They have a list of possible sponsors on their website. Once that is in, you also need to get your game approved. Once it is approved, you can view the code needed. This code has to make its way into the html5 files, mainly index.html.

That is found in Export/html5/bin

In the header, insert this code:

Code: [Select]
<script>
(function(zonefile) {
var rnd = Math.round(Math.random()*999999);
var s = document.createElement('script'); s.type = 'text/javascript'; s.async = true;
var proto = document.location.protocol;
var host = ( proto == "https:" || proto == "file:")?"https://server":"//cdn";
if(window.location.hash=="#cpmstarDev") host = "//dev.server";
if(window.location.hash=="#cpmstarStaging") host = "//staging.server";
s.src = host + ".cpmstar.com/cached/zonefiles/" + zonefile + ".js?rnd="+rnd;
var s2=document.getElementsByTagName('script')[0];
s2.parentNode.insertBefore(s, s2);
var y=window.location.href.split('#')[0].split('').reduce(function(a,b){return(a<<5)-a+b.charCodeAt(0)>>>1},0);y=(10+((y*7)%26)).toString(36)+y.toString(36);
var drutObj = window[y] = window[y] || {};
window.cpmstarAPI = function(o) { (drutObj.cmd = drutObj.cmd || []).push(o); }
}('ZONE_ID'));
</script>

The ZONE_ID, you get from cpmstar after having your game approved.

Then in the body, insert this code (and any other code you may want to include, such as framing and buttons outside of your game):

Code: [Select]
<script>
cpmstarAPI(function(api) {
//  api.game.setContentID("CONTENT_ID")
});
</script>

<script>
cpmstarAPI(function(api) {
  api.game.setTarget(document.getElementById("GAME_NAME")); //replace document.body with your game div
});
</script>

<script>
//init the interstitial
cpmstarAPI({
kind:"game.createInterstitial",
onAdOpened: function(){},
onAdClosed: function(){}
});
</script>

<script>
cpmstarAPI({kind: "go", module: "anchor", config: { target:{el:document.getElementById("mygame")}}});
</script>

The CONTENT_ID is also given to you when you submit a game. The GAME_NAME is whatever you supplied, they call it the document.body.

Not all of that is needed, but I tried a few ways and it didn't hurt having it in there. The next step is going into the .js file. The .js has all of your game coding, separated into similar structure as clicking the binoculars in the bottom right hand corner. Use those binoculars to see what area of the .js file you are looking for. For instance, scenes are called things like SceneEvents_12. Actor events are called something similar. The scene and actor behaviors are called names like Design_300_300. Whatever that particular set of event code is called also shows up in the .js file.

Once you find the correct location, go line by line and compare it to the binoculars code view in Stencyl. Whenever you want the CPMStar ad to be played, simply put:

Code: [Select]
cpmstarAPI("game.displayInterstitial");

There you have it. If I find any more information during the process, I will update this :)