Understanding MochiAds Publisher Bridge

Now that you have a WordPress theme and plugin in order to set uo your own MochiAds arcade site like triqui.com, let’s see how we can add some interesting features with the Publisher Bridge.

Every step explained in this tutorial will be included in the next upgrade of Triqui MochiAds Arcade theme, but it’s very interesting to see how does it work in order to custom it or install it in your own arcade site.

First, let me explain why you should use the Publisher Bridge… the reasons are listed in the official page:

  1. Leverage the hundreds of MochiAds leaderboard enabled games to attract new players.
  2. Receive new traffic – MochiAds’ Challenges feature will drive new players back to your site to compete in top scores.
  3. Build exciting site features – Save player scoring info for all MochiAds leaderboard-enabled games.
  4. Encourage competition – In-game scores are listed for your community only.
  5. Maintain consistency – Display your own community usernames when players post scores.
  6. Promote your brand – Put your site logo directly in the game.

but, as usual, it’s up to your creativity finding the best way to use them.

Cross-domain policy

From the Cross-domain policy file specification you cana cross-domain policy file is an XML document that grants a web client – such as Adobe Flash Player (though not necessarily limited to it) – permission to handle data across multiple domains. When a client hosts content from a particular source domain and that content makes requests directed towards a domain other than its own, the remote domain would need to host a cross-domain policy file that grants access to the source domain, allowing the client to continue with the transaction.

So the first thing you should do is to create a file called crossdomain.xml in your root, with this content:

1
2
3
4
5
6
7
8
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM
"http://www.adobe.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
     <site-control permitted-cross-domain-policies="master-only"/>
     <allow-access-from domain="x.mochiads.com"/>
     <allow-access-from domain="www.mochiads.com"/>
</cross-domain-policy>

This will allow Mochi client to communicate with your server.

Javascript call

Once your server is able to communicate, you need to insert the javascript provided by Mochi in the same page where you host (or leech) a game.

You don’t need to know if the game has a leaderboard, if the game does not support highscores, nothing will happen.

This is the one I used:

1
2
<script src="http://xs.mochiads.com/static/pub/swf/leaderboard.js" type="text/javascript"></script>
               <script type="text/javascript">var options = {partnerID: "3b7a2ab2368e1d2d", id: "leaderboard_bridge",globalScores:"true",gateway : "http://www.triqui.com/wp-content/themes/triqui/postscores.php",callback : function (params) {document.getElementById('latest').innerHTML="Your latest score: "+params.score;}}; Mochi.addLeaderboardIntegration(options);</script>

I used only a few options among the ones provided by Mochi, let me explain them:

partnerID: this is the ID MochiAds gave you when you signed up as a publisher. Remember: the Publisher ID, not the Publisher Secret Key!!!

id: The id of the HTML element you want to place the Bridge SWF into. Place such element wherever you want, it’s not important since it does not contain anything.

globalScores: Set to true if you wish to display global scores and not just those submitted from your site. I recommend to set it to true if your portal does not have that much visits per day (under 10,000).

gateway: the absolute path of a file that will receive posted data with POST method. I’ll explain how to use such data in next tutorial

callback: a JavaScript function which will be called when the player submits a score. In my case, I simply display in the page the latest score the player got, but obviously you can use Ajax to improve the interactivity.

Try to see it in action playing a leaderboard enabled game on Triqui.com, such as Mazeroll and see what happens when you submit a score.

But the most exciting feature lies in the gateway: having all score data in the POST array will allow you to create custom leaderboards and some other interesting things I’ll explain during next tutorial.

Meanwhile, look at the variables the bridge passes to postscores.php page when I submit a score, obtained with a simple var_dump:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
array(14) {
  ["signature"]=>
  string(32) "(had to omit it)"
  ["sessionID"]=>
  string(0) ""
  ["userID"]=>
  string(0) ""
  ["username"]=>
  string(0) ""
  ["scoreLabel"]=>
  string(6) "Points"
  ["sortOrder"]=>
  string(4) "desc"
  ["datatype"]=>
  string(6) "number"
  ["description"]=>
  string(0) ""
  ["title"]=>
  string(10) "Highscores"
  ["gameID"]=>
  string(16) "98c536dbf70a1cbc"
  ["boardID"]=>
  string(32) "4b2ac948de239f8853a3bc6a1b771d9d"
  ["name"]=>
  string(4) "ququ"
  ["score"]=>
  string(3) "520"
  ["lcId"]=>
  string(1) "1"
}

Next time I’ll show you how to use these values.

Rate this post: 1 Star2 Stars3 Stars4 Stars5 Stars (12 votes, average: 4.17 out of 5)
Loading ... Loading ...
If you found this post useful, please consider a small donation.
» WordPress themes are designs for WordPress - one of the most popular blogging software nowadays.
You will be pleasantly surprised by WordPress Themes provided by Template Monster. All of them are of professional design and high quality.

14 Responses to “Understanding MochiAds Publisher Bridge”

  1. Josh of Cubicle Ninjas on July 16th, 2009 8:01 pm

    Just as an FYI – I’m seeing a bunch or errors in my RSS feed where your ad is. Happy to send these along if they’d help debug.

    Btw, very excited about the Box2D powered platformer. You might enjoy this similar engine as an example:
    http://citrusengine.com/

  2. SJG on July 17th, 2009 4:23 pm

    Absolutely awesome beginning… looking forward to the next post very much as I am about to start to attempt to integrate.

    Not only are you teaching flash, but you are teaching PHP and Wordpress… What more can someone want :)

    Any idea’s when the next version will come out?
    And did my fix’s make any sense?

  3. Guest on July 18th, 2009 8:17 am

    mmm… can’t be this used to cheat?

  4. Games on August 2nd, 2009 8:42 am

    nice post …. Thanks

  5. öykü on August 2nd, 2009 6:06 pm

    Good solution, thanks

  6. SJG on August 6th, 2009 6:52 pm

    Eagerly awaiting part 2….

  7. Old Man on September 19th, 2009 9:38 pm

    OK managed to sort the previous issue. Got 20 games yet when I go to Add games to blog it says No new games to add.

    When I clich Manage game files I get:

    Warning: Invalid argument supplied for foreach() in /home/himitsu/public_html/wp-content/plugins/mochi/mochi.php on line 63

  8. Harack on November 7th, 2009 2:55 am

    i was unable to get it to print the scores when submitted. Can’t seem to find the problem i followed the tutorial from the start and added the code to the posts. Nothing was being written to my postscores.php.

    var options = {partnerID: “32c56bcde8981861″, id: “leaderboard_bridge”,globalScores:”true”,gateway : “http://www.harack.co.nz/wordpress/wp-content/themes/triqui/postscores.php”,callback : function (params) {document.getElementById(‘latest’).innerHTML=”Your latest score: “+params.score;}}; Mochi.addLeaderboardIntegration(options);

  9. skuvy on January 28th, 2010 9:28 pm

    hello i have installed this plugin but i am getting 2 errors:

    at ‘New Games’

    Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 47 bytes) in /home/awzombox/public_html/wp-content/plugins/mochi/mochi.php on line 148
    ———-
    tried raising memory_limit = 64M but no luck..
    also tried adding the following lines at wp-config.php without any luck either..
    define(‘WP_MEMORY_LIMIT’, ‘64M’);
    @ini_set(‘memory_limit’,'64M’);

    —————————————
    at ‘Manage Game Files’
    Warning: Invalid argument supplied for foreach() in /home/awzombox/public_html/wp-content/plugins/mochi/mochi.php on line 63

    —-

    I would really appreciate your help on this.

    Thanks in advanced.

  10. skuvy on January 29th, 2010 1:02 pm

    fixed the previous errors :)

    now i am having the following:

    I am having the Add Games to blog ‘No new games to add’ issue..
    i have tried changing json limit on line 291 but no luck..
    also checked and url_fopen is enable on my host.

    has someone find any solution to this?
    I would really appreciate a little help here :)

    sK.

  11. alifuatexe on February 7th, 2010 8:59 pm

    how did you fix can you explain pls

    at ‘Manage Game Files’
    Warning: Invalid argument supplied for foreach() in /home/awzombox/public_html/wp-content/plugins/mochi/mochi.php on line 63

  12. Ankit Saini on February 13th, 2010 3:06 am

    is there any way that my logged in user score automatically saved in leaderboard and also in my site..

    thanks

Leave a Reply




Trackbacks

  1. Understanding MochiAds Publisher Bridge – Part 2 : Emanuele Feronato on August 17th, 2009 11:06 pm

    [...] This is the second part of Understanding MochiAds Publisher Bridge. [...]

  2. Understanding MochiAds Publisher Bridge – Part 3 : Emanuele Feronato on August 24th, 2009 4:20 pm

    [...] part 1 we saw how to configure a cross-domain policy file, calling the javascript and send the results to [...]

flash games company