Integration of Google Publisher Tag - iOS
Integrating Google Publisher Tags (GPT) from Google Ad Manager (GAM) into an iOS application involves several steps, including setting up GAM, integrating the GPT library, defining ad units, and testing ad delivery. Here's a step-by-step guide to help you integrate GPT and test ad delivery in your iOS application:
Step 1: Set Up Google Ad Manager (GAM)
- Create a Google Ad Manager account if you don't have one: https://admanager.google.com.
- Set up an application in GAM and create ad units as described in previous sections.
Step 2: Integrate Google Publisher Tags (GPT) Library
Download and integrate the GPT library into your iOS project:
- Visit the Google Publisher Tag GitHub repository to download the GPT library.
- Add the library to your Xcode project. You can do this by dragging the .framework files into your project and ensuring they are added to your target.
Step 3: Configure GPT in Your iOS App
- Import the GPT library in your view controller where you want to display ads:
import GoogleMobileAds
- Initialize GPT with your Ad Manager ad unit ID and target ad size:
let adUnitID = "/YOUR/AD_UNIT_ID" let adSize = GADAdSizeFromCGSize(CGSize(width: 320, height: 50)) // Example size let adView = DFPBannerView(adSize: adSize) adView.adUnitID = adUnitID adView.rootViewController = self
- Load and display the ad:
let request = DFPRequest() adView.load(request)
Step 4: Test Ad Delivery
- Use Google's test ad unit IDs for testing. Replace "YOUR/AD_UNIT_ID" with the appropriate test ad unit ID:
- Test banner ad: /6499/example/banner
- Test interstitial ad: /6499/example/interstitial
- Make sure you are not using real ad unit IDs during testing to prevent serving live ads.
- Run your iOS app in the simulator or on a real device to test the ad delivery. Ensure you have an active internet connection.
Additional Steps
- Implement GPT ad event listeners to handle ad lifecycle events, such as ad loaded, ad clicked, etc.
- Test different ad formats, sizes, and targeting options using the GPT library.
Please refer to the Google Publisher Tags (GPT) documentation and the Google Mobile Ads iOS SDK documentation for more detailed information, guides, and code examples.
© 2024 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.