Giter VIP home page Giter VIP logo

phaser-ads's Introduction

IMPORTANT NOTE

This repository is to be considered DEPRECATED and all efforts are going towards developing the next version of the Ad Wrapper in azerion/h5-ad-wrapper.

npm version jsDelivr Hits

Phaser Ads

This Phaser plugin that allows you to leverage different ad providers whilst providing the same simple API. Also allows you to easily integrate mobile ads (via Cocoon).

Key features:

  • Ads for your mobile web experience
  • Pluggable ad providers
  • Gamedistribution.com
  • IMA3 SDK
  • Cocoon.io (support for AdMob/HeyZap/MoPub/Chartboost)
  • HeyZap for Cordova
  • Integrates nicely into Phaser
  • Fullscreen ad support

Getting Started

First you want to get a fresh copy of the plugin. You can get it from this repo or from npm.

npm install @azerion/phaser-ads

Next up you'd want to add it to your list of js sources you load into your game:

<script src="path/to/phaser-ads.min.js"></script>

You could also opt for using the (free) jsdelivr cdn:

<script src="https://cdn.jsdelivr.net/npm/@azerion/phaser-ads@latest/build/phaser-ads.min.js"></script>

After adding the script to the page you can activate it by enabling the plugin:

game.add.plugin(PhaserAds.AdManager);

Usage

First thing you need to do after loading the plugin is attaching a provider to the adManager. PhaserAds comes pre-compiled with 4 providers for you to choose from:

Gamedistribution.com

If you already have an account on Gamedistribution.com you can skip this introduction if not, head on over to gamedistribution.com and sign up for a free account. Once you're signed up you can check out this guide for settings up a game. This is important because this will supply you with a gameId, which you need to supply to the plugin.

So when you have your gameId you can start by registering the provider to the plugin:

// Let's create a new provider, first argument should be the game, second should be the ad tag URL
var provider = new PhaserAds.AdProvider.GameDistributionAds(
   game,                                        // Your Phaser game instance
   '2d77cfd4b1e5487d998465c29de195b3'           // Your gameId
);
game.ads.setAdProvider(provider);

After this it's as easy as calling:

game.ads.showAd();

IMA SDK

A provider can use any number of arguments configured in order to make it work, it all depends on the implementation that was made by the developer. For our IMA Provider you can create one like this:

// Let's create a new provider, first argument should be the game, second should be the ad tag URL
var provider = new PhaserAds.AdProvider.Ima3(
   game,
   'https://pubads.g.doubleclick.net/gampad/ads?sz=640x480&iu=/124319096/external/single_ad_samples&ciu_szs=300x250&impl=s&gdfp_req=1&env=vp&output=vast&unviewed_position_start=1&correlator'
);
game.ads.setAdProvider(provider);

Now all you need to do is request an ad, and add an event listener that is called when the ad is completed/skipped/finished/done playing.

game.ads.onContentResumed.addOnce(function() {
    // This gets called when the ad is complete
    game.state.start('NextState');
});

// Here we request the ad
game.ads.showAd();

You can also send custom parameters by adding them as an object to the showAd function.

F.A.Q.

I Don't see any ads!

This can happen, sometimes the provider does something wrong, but most of the time (and when you are testing locally) your ads get blocked from showing. That's right, ads don't show when testing locally. The easiest way to avoid this is by testing your game on a server (online).

Another work around would be to adjust your /etc/hosts.

Why don't you support this ad provider!

The setup allows for a multitude of ad providers to work, but sadly we don't have the time and resources to add all of them. That beeing said, this plugin is on GitHub, and you're welcome to shoot in a PR to add a new provider =)

Disclaimer

We at Azerion just love playing and creating awesome games. We aren't affiliated with Phaser.io. We just needed some awesome ads in our awesome HTML5 games. Feel free to use it for enhancing your own awesome games!

Phaser Ads is distributed under the MIT license. All 3rd party libraries and components are distributed under their respective license terms.

phaser-ads's People

Contributors

alebles avatar davidzwitser avatar dreadknight avatar florisdh avatar jamesskemp avatar lukasdrgon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

phaser-ads's Issues

Question about ES6 import

Hello,

Could this be possible to use one of your project in an ES6 project with just an import ? I don't work in typescript and don't really understand why there is no export feature in your projects, it looks like typescript doesn't need that.

You can close my issue right after your answer. I am just sad not being able to use any of your great projects :(

no way to get the example to work

Hello,
there's no way to get the example to work, once you link Phaser you get an error on this line:

game.ads.onAdError.add(function (error) {

the error is

(index):50 Uncaught TypeError: Cannot read property 'add' of undefined

also, no docs :(

Outdated example html

I am writing with regard to this html file:
https://github.com/orange-games/phaser-ads/blob/master/example/index.html

I am afraid that the example is outdated but still works with few modifications:

line 29
- game.plugins.add(Fabrique.Plugins.AdManager);
+ game.plugins.add(PhaserAds.AdManager);

line 49
- game.ads.setAdProvider(new Fabrique.AdProvider.Ima3(
+ game.ads.setAdProvider(new PhaserAds.AdProvider.Ima3(

Thank you for your attention to this matter in advance!

Error - blocking frame

Here is the error message I'm getting ..

ncaught TypeError: Cannot read property 'add' of undefinedcreate @ (index):49loadComplete @ phaser.js:30903preUpdate @ phaser.js:30670updateLogic @ phaser.js:39184update @ phaser.js:39071updateRAF @ phaser.js:62151_onLoop @ phaser.js:62135

VM333:1 Uncaught SecurityError: Blocked a frame with origin "http://imasdk.googleapis.com" from accessing a frame with origin "http://technotip.org". Protocols, domains, and ports must match.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.