{"_id":"59a812affee6e30037057c07","project":"574ff4bd3fa1870e00889ba6","version":{"_id":"574ff4bd3fa1870e00889ba9","project":"574ff4bd3fa1870e00889ba6","__v":20,"createdAt":"2016-06-02T08:56:29.492Z","releaseDate":"2016-06-02T08:56:29.492Z","categories":["574ff4bd3fa1870e00889baa","577278ecdceb570e003a9001","577279865617b117009e643f","577279985617b117009e6440","577279bc8c48e00e00503504","5774fe18605b770e0037be8a","577ce3ad87acf617003c4187","577f8476a77c700e006a6c52","57b486ae0d2b640e00e9d3f5","57b722133d3e620e004ec74b","57bd95f00fe3a00e003e2cc5","57c8349359cd4b0e00b888ef","57c8349b5754fa1700b12242","57cedb0bad483e0e00890239","57cedbe807d7ea0e00e438cc","57d82967156ef72b007ffcd8","58ee353ad1ee2f0f0034a13d","596623221738df00298622a5","59a51730192dba000fc9ca38","59a8129f1e7b26000fa0fb1a"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"3.0.0","version":"3.0"},"category":{"_id":"59a8129f1e7b26000fa0fb1a","project":"574ff4bd3fa1870e00889ba6","version":"574ff4bd3fa1870e00889ba9","__v":0,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2017-08-31T13:43:59.109Z","from_sync":false,"order":11,"slug":"unity-sdk","title":"Unity SDK"},"user":"5770fa1ce5a0000e0023c680","__v":0,"parentDoc":null,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2017-08-31T13:44:15.677Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":0,"body":"PubNative Android Plugin for Unity supports 2 ad formats:\n\n  * **[Banners](http://developers.pubnative.net/docs/android-plugin-1#banner-integration-instructions)**\n  * **[Interstitials](http://developers.pubnative.net/docs/android-plugin-1#interstitial-integration-instructions)**\n\nPlease follow this integration guide to configure PubNative ads.\n[block:api-header]\n{\n  \"title\": \"Installation instructions\"\n}\n[/block]\n# Requirements\n\n  * Unity Project (Minimum Unity 5)\n  * An **App token** provided by the PubNative dashboard\n  * A **placement name** created in the PubNative dashboard\n  * PubNative Unity plugin. It can be found here: https://drive.google.com/file/d/0B-5uf-3n9OfFMzFLcUFDamxlY1U/view?usp=sharing\n  \n# Plugin integration\n\n  * Open the project in the Unity Editor\n  * With the project open, double click on the downloaded **PubNativeUnityPlugin** file, all the required files will be imported into the project.\n  * Make sure that the **Assets/Plugins** folder is created in it contains the **Android** folder inside.\n  * Now the plugin is integrated and ready to begin the specific integration per ad format.\n\n# Caution\n\nIf you already have the project set up to be deployed in Android, importing the plugin might try to override your Manifest of gradle file. If that’s the case just keep your original file and add the dependencies from the plugin gradle file and the permissions from the Manifest.\n\n\n[block:api-header]\n{\n  \"title\": \"Banner integration instructions\"\n}\n[/block]\n# Creating the banner\n\nThe **PNBanner** should be created inside a script which is linked to a **GameObject**. It must be created using the PNBannerFactory **create** method which created a banner based on the platform that the application is being built for.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"public static PNBanner createBanner(MonoBehaviour parent) \",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\nA sample of this this instantiation is the following:\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"PNBanner banner = PNBannerFactory.createBanner (this); \",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\nIn the previous sample **“this”** is an object which inherits from MonoBehaviour so it’s linked to a **GameObject**.\n\nAfter creating the banner you must set the appToken and placement properties:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"banner.appToken = “app token obtain from PubNative dashboard”;\\nbanner.placement = “placement name configured in dashboard”; \",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\nSetting the listeners is also recommended to check the correct behaviour of the ads. There are two listeners for PNBanner: ILoadListener and ITrackListener.\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"\",\n      \"language\": \"text\"\n    }\n  ]\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"\",\n      \"language\": \"text\"\n    }\n  ]\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"public interface ILoadListener\\n{\\n    void OnLoadFinished ();\\n\\n    void OnLoadFailed (Exception error);\\n} \\n\\npublic interface ITrackListener\\n{\\n    void OnImpressionTracked ();\\n\\n    void OnClickTracked ();\\n} \",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\nAdding a LoadListener to the PNBanner is mandatory since it will send callbacks when the ad was loaded or failed. After the ad is loaded then it can be displayed.\n\nTrackListener is optional in case you want to receive callbacks when the ad has been impressed on screen or when the ad has been clicked. \n\nHere’s an implementation sample:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"banner.LoadListener = LOAD_LISTENER_INSTANCE;\\nbanner.TrackListener = TRACK_LISTENER_INSTANCE; \",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n\n# Loading the banner\nTo load the banner you should use the method: **Load ()** must be invoked in the following way:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"banner.Load (); \",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n\nThe result of this method will be received in the LoadListener callbacks.\n\n# Showing the banner\nThe banner can be displayed in two positions of the screen: TOP, BOTTOM. After the ad is loaded successfully, the method **Show (Position position)** must be used to display the ad.\n\nHere’s are samples of how to show the banner on top or bottom of the screen.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"banner.Show (PNBanner.Position.TOP); \\nbanner.Show (PNBanner.Position.BOTTOM); \",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\nKeep in mind this method should be called always after receiving confirmation that the ad was loaded successfully. Otherwise it’ll result in an error and nothing will be displayed.\n\n\n# Code Sample\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"using System;\\nusing System.Collections;\\nusing System.Collections.Generic;\\nusing UnityEngine;\\nusing UnityEngine.UI;\\n\\npublic class BannerNative : MonoBehaviour, ILoadListener, ITrackListener\\n{\\n    private PNBanner banner;\\n\\n    public string appToken;\\n    public string placement;\\n\\n    [SerializeField]\\n    private Button _buttonLoadBanner;\\n\\n    [SerializeField]\\n    private Button _buttonHideBanner;\\n\\n    // Use this for initialization\\n    void Start ()\\n    {\\n        banner = PNBannerFactory.createBanner (this);\\n\\n        banner.appToken = appToken;\\n        banner.placement = placement;\\n        banner.LoadListener = this;\\n        banner.TrackListener = this;\\n        _buttonLoadBanner.onClick.AddListener (RequestBanner);\\n        _buttonHideBanner.onClick.AddListener (HideBanner);\\n    }\\n\\n    private void RequestBanner ()\\n    {\\n        if (banner != null) {\\n            banner.Load ();\\n        }\\n    }\\n\\n    private void HideBanner ()\\n    {\\n        banner.Hide ();\\n    }\\n\\n    public void OnLoadFinished ()\\n    {\\n        banner.Show (PNBanner.Position.TOP);\\n    }\\n\\n    public void OnLoadFailed (Exception error)\\n    {\\n        // Handle error\\n    }\\n\\n    public void OnImpressionTracked()\\n    {\\n        // Handle Impression\\n    }\\n\\n    public void OnClickTracked ()\\n    {\\n        // Handle Click\\n    }\\n} \",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"title\": \"Interstitial integration instructions\"\n}\n[/block]\n# Creating the interstitial\n\nThe **PNInterstitial** should be created inside a script which is linked to a **GameObject**. It must be created using the PNInterstitialFactory **create** method which created a banner based on the platform that the application is being built for.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"public static PNInterstitial createInterstitial(MonoBehaviour parent) \",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\nA sample of this this instantiation is the following:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"PNInterstitial interstitial = PNInterstitialFactory.createInterstitial (this); \",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n \n\nIn the previous sample **“this”** is an object which inherits from MonoBehaviour so it’s linked to a **GameObject**.\n\nAfter creating the interstitial you must set the appToken and placement properties:\n\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"interstitial.appToken = “app token obtain from PubNative dashboard”;\\ninterstitial.placement = “placement name configured in dashboard”; \",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\nSetting the listeners is also recommended to check the correct behaviour of the ads. There are three listeners for PNInterstitial: ILoadListener, ITrackListener and IViewListener.\n\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"public interface ILoadListener\\n{\\n    void OnLoadFinished ();\\n\\n    void OnLoadFailed (Exception error);\\n} \\n\\npublic interface ITrackListener\\n{\\n    void OnImpressionTracked ();\\n\\n    void OnClickTracked ();\\n} \\n\\npublic interface IViewListener\\n{\\n    void OnShown ();\\n\\n    void OnHidden ();\\n} \",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\nAdding a LoadListener to the PNInterstitial is mandatory since it will send callbacks when the ad was loaded or failed. After the ad is loaded then it can be displayed.\n\nTrackListener is optional in case you want to receive callbacks when the ad has been impressed on screen or when the ad has been clicked.\n\nViewListener is optional in case you want to receive callbacks when the interstitial has been shown and hidden.\n\nHere’s an implementation sample:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"interstitial.LoadListener = LOAD_LISTENER_INSTANCE;\\ninterstitial.TrackListener = TRACK_LISTENER_INSTANCE; \\ninterstitial.ViewListener = VIEW_LISTENER_INSTANCE; \",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n# Loading the interstitial\n\nTo load the interstitial you should use the method: **Load ()** must be invoked in the following way:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"interstitial.Load (); \",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n\nThe result of this method will be received in the LoadListener callbacks.\n\n# Showing the interstitial\n\nAfter the ad is loaded successfully, the method **Show ()** must be used to display the ad.\n\nHere’s are samples of how to show interstitial on screen.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"interstitial.Show (); \",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\nKeep in mind this method should be called always after receiving confirmation that the ad was loaded successfully. Otherwise it’ll result in an error and nothing will be displayed.\n\n# Code sample\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"using System;\\nusing System.Collections;\\nusing System.Collections.Generic;\\nusing UnityEngine;\\nusing UnityEngine.UI;\\n\\npublic class InterstitialNative : MonoBehaviour, ILoadListener, ITrackListener, IViewListener\\n{\\n    private PNInterstitial interstitial;\\n\\n    public string appToken;\\n    public string placement;\\n\\n    [SerializeField]\\n    private Button _buttonLoadInterstitial;\\n\\n    // Use this for initialization\\n    void Start ()\\n    {\\n        interstitial = PNInterstitialFactory.createInterstitial (this);\\n\\n        interstitial.appToken = appToken;\\n        interstitial.placement = placement;\\n        interstitial.LoadListener = this;\\n        interstitial.TrackListener = this;\\n        interstitial.ViewListener = this;\\n        _buttonLoadInterstitial.onClick.AddListener (RequestInterstitial);\\n    }\\n\\n    private void RequestInterstitial ()\\n    {\\n        if (interstitial != null) {\\n            interstitial.Load();\\n        }\\n    }\\n\\n    public void OnLoadFinished ()\\n    {\\n        interstitial.Show ();\\n    }\\n\\n    public void OnLoadFailed (Exception error)\\n    {\\n        // Handle error\\n    }\\n\\n    public void OnImpressionTracked()\\n    {\\n        // Handle Impression\\n    }\\n\\n    public void OnClickTracked ()\\n    {\\n        // Handle Click\\n    }\\n\\n    public void OnShown ()\\n    {\\n        // Handle interstitial show\\n    }\\n\\n    public void OnHidden ()\\n    {\\n        // Handle interstitial hide\\n    }\\n}\\n\",\n      \"language\": \"java\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"title\": \"Demo app on github\"\n}\n[/block]\nOn the github repo you can find the demo project for unity and the generated Android project.\n\nhttps://drive.google.com/file/d/0B-5uf-3n9OfFNG5zRlVjUVQ1YjA/view?usp=sharing","excerpt":"","slug":"android-plugin-1","type":"basic","title":"Android Plugin"}
PubNative Android Plugin for Unity supports 2 ad formats: * **[Banners](http://developers.pubnative.net/docs/android-plugin-1#banner-integration-instructions)** * **[Interstitials](http://developers.pubnative.net/docs/android-plugin-1#interstitial-integration-instructions)** Please follow this integration guide to configure PubNative ads. [block:api-header] { "title": "Installation instructions" } [/block] # Requirements * Unity Project (Minimum Unity 5) * An **App token** provided by the PubNative dashboard * A **placement name** created in the PubNative dashboard * PubNative Unity plugin. It can be found here: https://drive.google.com/file/d/0B-5uf-3n9OfFMzFLcUFDamxlY1U/view?usp=sharing # Plugin integration * Open the project in the Unity Editor * With the project open, double click on the downloaded **PubNativeUnityPlugin** file, all the required files will be imported into the project. * Make sure that the **Assets/Plugins** folder is created in it contains the **Android** folder inside. * Now the plugin is integrated and ready to begin the specific integration per ad format. # Caution If you already have the project set up to be deployed in Android, importing the plugin might try to override your Manifest of gradle file. If that’s the case just keep your original file and add the dependencies from the plugin gradle file and the permissions from the Manifest. [block:api-header] { "title": "Banner integration instructions" } [/block] # Creating the banner The **PNBanner** should be created inside a script which is linked to a **GameObject**. It must be created using the PNBannerFactory **create** method which created a banner based on the platform that the application is being built for. [block:code] { "codes": [ { "code": "public static PNBanner createBanner(MonoBehaviour parent) ", "language": "java" } ] } [/block] A sample of this this instantiation is the following: [block:code] { "codes": [ { "code": "PNBanner banner = PNBannerFactory.createBanner (this); ", "language": "java" } ] } [/block] In the previous sample **“this”** is an object which inherits from MonoBehaviour so it’s linked to a **GameObject**. After creating the banner you must set the appToken and placement properties: [block:code] { "codes": [ { "code": "banner.appToken = “app token obtain from PubNative dashboard”;\nbanner.placement = “placement name configured in dashboard”; ", "language": "java" } ] } [/block] Setting the listeners is also recommended to check the correct behaviour of the ads. There are two listeners for PNBanner: ILoadListener and ITrackListener. [block:code] { "codes": [ { "code": "", "language": "text" } ] } [/block] [block:code] { "codes": [ { "code": "", "language": "text" } ] } [/block] [block:code] { "codes": [ { "code": "public interface ILoadListener\n{\n void OnLoadFinished ();\n\n void OnLoadFailed (Exception error);\n} \n\npublic interface ITrackListener\n{\n void OnImpressionTracked ();\n\n void OnClickTracked ();\n} ", "language": "java" } ] } [/block] Adding a LoadListener to the PNBanner is mandatory since it will send callbacks when the ad was loaded or failed. After the ad is loaded then it can be displayed. TrackListener is optional in case you want to receive callbacks when the ad has been impressed on screen or when the ad has been clicked. Here’s an implementation sample: [block:code] { "codes": [ { "code": "banner.LoadListener = LOAD_LISTENER_INSTANCE;\nbanner.TrackListener = TRACK_LISTENER_INSTANCE; ", "language": "java" } ] } [/block] # Loading the banner To load the banner you should use the method: **Load ()** must be invoked in the following way: [block:code] { "codes": [ { "code": "banner.Load (); ", "language": "java" } ] } [/block] The result of this method will be received in the LoadListener callbacks. # Showing the banner The banner can be displayed in two positions of the screen: TOP, BOTTOM. After the ad is loaded successfully, the method **Show (Position position)** must be used to display the ad. Here’s are samples of how to show the banner on top or bottom of the screen. [block:code] { "codes": [ { "code": "banner.Show (PNBanner.Position.TOP); \nbanner.Show (PNBanner.Position.BOTTOM); ", "language": "java" } ] } [/block] Keep in mind this method should be called always after receiving confirmation that the ad was loaded successfully. Otherwise it’ll result in an error and nothing will be displayed. # Code Sample [block:code] { "codes": [ { "code": "using System;\nusing System.Collections;\nusing System.Collections.Generic;\nusing UnityEngine;\nusing UnityEngine.UI;\n\npublic class BannerNative : MonoBehaviour, ILoadListener, ITrackListener\n{\n private PNBanner banner;\n\n public string appToken;\n public string placement;\n\n [SerializeField]\n private Button _buttonLoadBanner;\n\n [SerializeField]\n private Button _buttonHideBanner;\n\n // Use this for initialization\n void Start ()\n {\n banner = PNBannerFactory.createBanner (this);\n\n banner.appToken = appToken;\n banner.placement = placement;\n banner.LoadListener = this;\n banner.TrackListener = this;\n _buttonLoadBanner.onClick.AddListener (RequestBanner);\n _buttonHideBanner.onClick.AddListener (HideBanner);\n }\n\n private void RequestBanner ()\n {\n if (banner != null) {\n banner.Load ();\n }\n }\n\n private void HideBanner ()\n {\n banner.Hide ();\n }\n\n public void OnLoadFinished ()\n {\n banner.Show (PNBanner.Position.TOP);\n }\n\n public void OnLoadFailed (Exception error)\n {\n // Handle error\n }\n\n public void OnImpressionTracked()\n {\n // Handle Impression\n }\n\n public void OnClickTracked ()\n {\n // Handle Click\n }\n} ", "language": "java" } ] } [/block] [block:api-header] { "title": "Interstitial integration instructions" } [/block] # Creating the interstitial The **PNInterstitial** should be created inside a script which is linked to a **GameObject**. It must be created using the PNInterstitialFactory **create** method which created a banner based on the platform that the application is being built for. [block:code] { "codes": [ { "code": "public static PNInterstitial createInterstitial(MonoBehaviour parent) ", "language": "java" } ] } [/block] A sample of this this instantiation is the following: [block:code] { "codes": [ { "code": "PNInterstitial interstitial = PNInterstitialFactory.createInterstitial (this); ", "language": "java" } ] } [/block] In the previous sample **“this”** is an object which inherits from MonoBehaviour so it’s linked to a **GameObject**. After creating the interstitial you must set the appToken and placement properties: [block:code] { "codes": [ { "code": "interstitial.appToken = “app token obtain from PubNative dashboard”;\ninterstitial.placement = “placement name configured in dashboard”; ", "language": "java" } ] } [/block] Setting the listeners is also recommended to check the correct behaviour of the ads. There are three listeners for PNInterstitial: ILoadListener, ITrackListener and IViewListener. [block:code] { "codes": [ { "code": "public interface ILoadListener\n{\n void OnLoadFinished ();\n\n void OnLoadFailed (Exception error);\n} \n\npublic interface ITrackListener\n{\n void OnImpressionTracked ();\n\n void OnClickTracked ();\n} \n\npublic interface IViewListener\n{\n void OnShown ();\n\n void OnHidden ();\n} ", "language": "java" } ] } [/block] Adding a LoadListener to the PNInterstitial is mandatory since it will send callbacks when the ad was loaded or failed. After the ad is loaded then it can be displayed. TrackListener is optional in case you want to receive callbacks when the ad has been impressed on screen or when the ad has been clicked. ViewListener is optional in case you want to receive callbacks when the interstitial has been shown and hidden. Here’s an implementation sample: [block:code] { "codes": [ { "code": "interstitial.LoadListener = LOAD_LISTENER_INSTANCE;\ninterstitial.TrackListener = TRACK_LISTENER_INSTANCE; \ninterstitial.ViewListener = VIEW_LISTENER_INSTANCE; ", "language": "java" } ] } [/block] # Loading the interstitial To load the interstitial you should use the method: **Load ()** must be invoked in the following way: [block:code] { "codes": [ { "code": "interstitial.Load (); ", "language": "java" } ] } [/block] The result of this method will be received in the LoadListener callbacks. # Showing the interstitial After the ad is loaded successfully, the method **Show ()** must be used to display the ad. Here’s are samples of how to show interstitial on screen. [block:code] { "codes": [ { "code": "interstitial.Show (); ", "language": "java" } ] } [/block] Keep in mind this method should be called always after receiving confirmation that the ad was loaded successfully. Otherwise it’ll result in an error and nothing will be displayed. # Code sample [block:code] { "codes": [ { "code": "using System;\nusing System.Collections;\nusing System.Collections.Generic;\nusing UnityEngine;\nusing UnityEngine.UI;\n\npublic class InterstitialNative : MonoBehaviour, ILoadListener, ITrackListener, IViewListener\n{\n private PNInterstitial interstitial;\n\n public string appToken;\n public string placement;\n\n [SerializeField]\n private Button _buttonLoadInterstitial;\n\n // Use this for initialization\n void Start ()\n {\n interstitial = PNInterstitialFactory.createInterstitial (this);\n\n interstitial.appToken = appToken;\n interstitial.placement = placement;\n interstitial.LoadListener = this;\n interstitial.TrackListener = this;\n interstitial.ViewListener = this;\n _buttonLoadInterstitial.onClick.AddListener (RequestInterstitial);\n }\n\n private void RequestInterstitial ()\n {\n if (interstitial != null) {\n interstitial.Load();\n }\n }\n\n public void OnLoadFinished ()\n {\n interstitial.Show ();\n }\n\n public void OnLoadFailed (Exception error)\n {\n // Handle error\n }\n\n public void OnImpressionTracked()\n {\n // Handle Impression\n }\n\n public void OnClickTracked ()\n {\n // Handle Click\n }\n\n public void OnShown ()\n {\n // Handle interstitial show\n }\n\n public void OnHidden ()\n {\n // Handle interstitial hide\n }\n}\n", "language": "java" } ] } [/block] [block:api-header] { "title": "Demo app on github" } [/block] On the github repo you can find the demo project for unity and the generated Android project. https://drive.google.com/file/d/0B-5uf-3n9OfFNG5zRlVjUVQ1YjA/view?usp=sharing