Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Web-Based Ad Requests

Discussion in 'BlackBerry' started by WaterlooErik, Apr 1, 2014.

  1. WaterlooErik

    WaterlooErik

    Joined:
    Jul 22, 2013
    Posts:
    89
    Hello all,

    I wanted to share something I've been exploring (still not there yet) but am hoping that with the community's help we might be able to get something going. The idea is to leverage the WWW API to make a GET call to an Advertising Service that allows for it, parse the image URL, and then make another GET call to retrieve the image and render it to a texture.

    The initial code that I've attached to a Quad looks like so:

    Code (csharp):
    1.  
    2.     // Use this for initialization
    3.     IEnumerator Start () {
    4.         string zone = "15562";
    5.         string ip = Network.player.ipAddress;
    6.         string ua = WWW.EscapeURL("Mozilla/5.0 (BB10; <Device Model>) AppleWebKit/<WebKit Version> (KHTML, like Gecko) Version/<BB Version #> Mobile Safari/<WebKit Version>");
    7.  
    8.         string url = "http://ads.moceanads.com/ad";
    9.         url += "?zone=" + zone;
    10.         url += "&ip=" + ip;
    11.         url += "&ua=" + ua;
    12.         url += "&key=5";
    13.         url += "&type=2";
    14.  
    15.         WWW www = new WWW(url);
    16.         yield return www;
    17.  
    18.         Debug.Log(www.url);
    19.         Debug.Log(www.bytes);
    20.         Debug.Log(www.bytesDownloaded);
    21.         Debug.Log(www.error);
    22.         Debug.Log(www.text);
    23.         Debug.Log(www.texture);
    24.  
    25.         /* Temporary static URL. */
    26.         url = "http://upload.wikimedia.org/wikipedia/commons/0/05/Public_Image_Ltd._live_27_10_2013_photo_1.JPG";
    27.         www = new WWW(url);
    28.         yield return www;
    29.  
    30.         renderer.material.mainTexture = www.texture;
    31.     }
    32.  
    The Ad Provider I'm testing with (Mocean) has their API here:
    http://developer.moceanmobile.com/Mocean_Ad_Request_API

    * This is the same Ad Provider behind the native BlackBerry implementation, so the fill-rate may not be that good. However, the goal is to get a proof of concept working in this manner.

    Running the above gives the following for www.text:
    ({"error" : "No ads available"})

    So, in theory, I believe this should work. But we need an Ad Service provider with RESTful API that works. Right now that's the missing piece, but am checking other providers to see what can be done.

    If anyone has any thoughts on this approach, I'm happy to hear them.
     
  2. MentalFish

    MentalFish

    Joined:
    Nov 2, 2005
    Posts:
    282
    That's cool Erik

    If/when it works with any web-api provider, it is in essence a platform agnostic solution, and should/could work on any Unity target platform right? Personally I would like to add "self promotion" into the setup so that I can promote my own game in previously published games I have made, especially in the case of "No ads available".
    Code (csharp):
    1. if(noAdsAvail)
    2. {
    3.     DisplayLatestSelfPromo("http://mentalfish.com/....");
    4. }
     
  3. MentalFish

    MentalFish

    Joined:
    Nov 2, 2005
    Posts:
    282
  4. WaterlooErik

    WaterlooErik

    Joined:
    Jul 22, 2013
    Posts:
    89
    That's a good find! Let me take a look into those.

    And indeed, the idea is to create a platform-agnostic approach to these ads. In addition, when no ad is found (i.e. no image URL in the initial web request, we could always default to an image (or series of images) that are packaged with the app, or hosted at a known URL. Basically, have a default fallback.

    Will let you know
     
  5. zezba9000

    zezba9000

    Joined:
    Sep 28, 2010
    Posts:
    985
    NOTE: Your ZoneID is Wrong! It must be the 6 digit number.
    WOW this totally works with my ZoneID... Now how do we tell the service we want a Test Ad vs a Live Ad?! I will post again with how to parse the return TEXT.
     
    Last edited: Apr 9, 2014
  6. zezba9000

    zezba9000

    Joined:
    Sep 28, 2010
    Posts:
    985
    This works! But it gives the same Ad image that I get in my Native BB10 plugin already. But this is cool cuz now I can add in Ad-Scaling.
    Now that we have something to test with, how do we get it to pull "REAL" Ads?

    Code (csharp):
    1.  
    2. public GameObject TestObj;
    3.     IEnumerator Start ()
    4.     {
    5.         // request Ad
    6.         string zone = "xxxxxx";
    7.         string ip = Network.player.ipAddress;
    8.         string ua = WWW.EscapeURL("Mozilla/5.0 (BB10; <Device Model>) AppleWebKit/<WebKit Version> (KHTML, like Gecko) Version/<BB Version #> Mobile Safari/<WebKit Version>");
    9.  
    10.         string url = "http://ads.moceanads.com/ad";
    11.         url += "?zone=" + zone;
    12.         url += "&ip=" + ip;
    13.         url += "&ua=" + ua;
    14.         url += "&key=5";
    15.         url += "&type=2";
    16.  
    17.         WWW www = new WWW(url);
    18.         yield return www;
    19.  
    20.         if (!string.IsNullOrEmpty([url]www.error[/url]))
    21.         {
    22.             Debug.LogError([url]www.error);[/url]
    23.             yield break;
    24.         }
    25.  
    26.         Debug.Log("Request Text: " + [url]www.text);[/url]
    27.  
    28.         // load banner image Ad.
    29.         var match = System.Text.RegularExpressions.Regex.Match
    30.         (
    31.             [url]www.text[/url],
    32.             @"""img"" \: \[ ""(.*\.jpg)"" \]"
    33.         );
    34.  
    35.         string imageURL = match.Groups[1].Value;
    36.         Debug.Log("Ad ImageURL: " + imageURL);
    37.         www = new WWW(imageURL);
    38.         yield return www;
    39.  
    40.         TestObj.renderer.material.mainTexture = [url]www.texture;[/url]
    41.     }
    42.  
    NOTE: remove the stupid tags the text editor ads in.[/B]
     
    Last edited: Apr 9, 2014
  7. WaterlooErik

    WaterlooErik

    Joined:
    Jul 22, 2013
    Posts:
    89
    That's great! I really appreciate your efforts and contributing that code snippet back.

    For test ads, my understanding was that the ZoneID I was using (15562) was the designated test ZoneID (it's what's referenced in Mocean's API documentation.

    The ideal part of this is that it's (A) platform agnostic; and (B) a RESTful ad service that returns JSON/XML should be relatively easily plugged in. We still have the issue of fill-rate with Mocean (they are the ad provider for the native APIs) but it's definitely a step forward.

    I have a feeling the returned ads are simply a symptom of the provider not giving a wide variety of meaningful ads. I think the next steps are to adapt the above to show a default ad if none is returned, and find a more reliable ad provider for the initial request. I'm going through the list provided by Petter to see if there is a better fit.
     
  8. zezba9000

    zezba9000

    Joined:
    Sep 28, 2010
    Posts:
    985
    Actually the test Ad ZoneID for Core Native Ads is: "117145"
    EDIT or i'm confused about what your saying.

    After using my ZoneID and only getting back the same image from the native plugin, I think you might be right. Or it also might be that the BB10 Advertising Dashboard is not documented and thus iv'e had to play the guessing game at to what properties to set... so the issue may be this too.
     
    Last edited: Apr 9, 2014
  9. WaterlooErik

    WaterlooErik

    Joined:
    Jul 22, 2013
    Posts:
    89
    Oh, have you tried this?
    http://developer.moceanmobile.com/Mocean_Ad_Request_API#Test_Ads

    I thought Zone ID 15562 was the "send me test ads" flag, but it seems that there is *actually* a flag for this.The Zone ID in the Mocean documentation doesn't actually seem to do anything, which would explain my requests not working.

    In order to get ads, you'll need to specify test ads, or get a Zone ID, which only activates after ~2-3 days after registering.
    https://adservices.blackberry.com/

    (I realize you already have a Zone ID, just sharing the link for anyone that drops by this thread.)

    Mocean is the ad provider for the BlackBerry Ad Services, so signing up at the above URL and leveraging that Zone ID should work with this approach; using the Mocean service in your requests.

    Seems we have one valid service thus far; though fill-rate is still an issue.
     
  10. zezba9000

    zezba9000

    Joined:
    Sep 28, 2010
    Posts:
    985
    Ya so for getting BB10 tests Ads just use "117145" ZoneID.
    But yes the fill-rate is the same as my native plugin.... In that I mean the only fill is a BB10 Ad that isn't worth anything. In fact this "real" BB10 Ad that shows is the same Ad image used in testing Ads but counts as a live Ad.

    Is there any other Ad services that uses Images (jpg/png) files and not HTML that you know of?
    Sadly this at the end of the day doesn't solve the root issue which is getting valid good Ads which make games money.

    Thanks for the link though, I may see if there is anything else useful in there.
     
    Last edited: Apr 10, 2014
  11. Jonny-Roy

    Jonny-Roy

    Joined:
    May 29, 2013
    Posts:
    666
    There are actually quite a few that do, I was looking into Mmedia as a provider, which looked quite promising, but I've had to postpone looking into it for a moment as we have another project that needed my attention, but Mmedia does provide a facility to do it.
     
  12. HenMx

    HenMx

    Joined:
    Feb 22, 2013
    Posts:
    1
  13. zezba9000

    zezba9000

    Joined:
    Sep 28, 2010
    Posts:
    985
  14. zezba9000

    zezba9000

    Joined:
    Sep 28, 2010
    Posts:
    985
    I got millennialmedia.com Web Ads working in Unity3D for BB10. But my site got rejected because it not a web-stie and rather a BB10/Unity app. Iv'e contacted MM Ads about this to see if I can work with them to get something working for BB10. I just hope I tried to contact them through the best channels.
     
  15. zezba9000

    zezba9000

    Joined:
    Sep 28, 2010
    Posts:
    985
    I released experimental MM Web Ads for BB10 (Also works in Unity editor) in my Reign plugin.
    It loads an animated GIF image that is requested from there server and renders it with Unitys GUI system. It also handles click Ad request.

    Everything seems to be working so far.
     
  16. WaterlooErik

    WaterlooErik

    Joined:
    Jul 22, 2013
    Posts:
    89
    That's great!

    I had a quick chat with the folks from Adiquity as well. They advised that using their web service for this purpose should work and that approvals for mobile apps should't be an issue. This documentation was provided:
    http://adiquity.com/app/data/download/api/Adiquity_Ad_Server_API_v2.1.pdf

    This approach was advised as a cross-platform approach and a "website" per-se isn't required as some other services seem to require.

    It's great to see MM integration, and I'm not pushing Adiquity, just wanted to give the additional information that came my way.

    Great work zezba9000.
     
  17. zezba9000

    zezba9000

    Joined:
    Sep 28, 2010
    Posts:
    985
    Cool thanks, I may take a look at that later.