Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EUID Support #19

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@
/// Text that indicates current coin count.
@IBOutlet weak var coinCountLabel: UILabel!

private let manager: UID2Manager = {
let isEUID = Bundle.main.object(forInfoDictionaryKey: "UID2EnvironmentEUID") as? Bool ?? false
if isEUID {
return EUIDManager.shared
} else {
return UID2Manager.shared
}
}()

override func viewDidLoad() {
super.viewDidLoad()

Expand Down Expand Up @@ -110,7 +119,7 @@
refreshExpires: refreshExpires,
refreshResponseKey: uid2IdentityFromFile.refreshResponseKey)

await UID2Manager.shared.setIdentity(uid2Identity)
await manager.setIdentity(uid2Identity)
} catch {
print("Error loading UID2Identity")
}
Expand Down Expand Up @@ -139,7 +148,7 @@
let request = GAMRequest()
GADRewardedInterstitialAd.load(
withAdUnitID: "/21775744923/example/rewarded_interstitial", request: request
) { (ad, error) in

Check warning on line 151 in Development/UID2GoogleGMADevelopmentApp/UID2GoogleGMADevelopmentApp/GameViewController.swift

View workflow job for this annotation

GitHub Actions / Code Tests

Variable name 'ad' should be between 3 and 40 characters long (identifier_name)
if let error = error {
print("Failed to load rewarded interstitial ad with error: \(error.localizedDescription)")
self.playAgainButton.isHidden = false
Expand Down Expand Up @@ -210,7 +219,7 @@
let alertAction = UIAlertAction(
title: "No, thanks",
style: .cancel
) { action in

Check warning on line 222 in Development/UID2GoogleGMADevelopmentApp/UID2GoogleGMADevelopmentApp/GameViewController.swift

View workflow job for this annotation

GitHub Actions / Code Tests

Unused parameter in a closure should be replaced with _ (unused_closure_parameter)
adCanceled = true
self.playAgainButton.isHidden = false
}
Expand All @@ -227,7 +236,7 @@
}

private func showRewardedInterstitialAd() {
guard let ad = self.rewardedInterstitialAd else {

Check warning on line 239 in Development/UID2GoogleGMADevelopmentApp/UID2GoogleGMADevelopmentApp/GameViewController.swift

View workflow job for this annotation

GitHub Actions / Code Tests

Variable name 'ad' should be between 3 and 40 characters long (identifier_name)
print("Ad wasn't ready")
return
}
Expand All @@ -248,18 +257,18 @@

// MARK: - GADFullScreenContentDelegate

func adWillPresentFullScreenContent(_ ad: GADFullScreenPresentingAd) {

Check warning on line 260 in Development/UID2GoogleGMADevelopmentApp/UID2GoogleGMADevelopmentApp/GameViewController.swift

View workflow job for this annotation

GitHub Actions / Code Tests

Variable name 'ad' should be between 3 and 40 characters long (identifier_name)
print("Ad did present full screen content.")
}

func ad(_ ad: GADFullScreenPresentingAd, didFailToPresentFullScreenContentWithError error: Error)

Check warning on line 264 in Development/UID2GoogleGMADevelopmentApp/UID2GoogleGMADevelopmentApp/GameViewController.swift

View workflow job for this annotation

GitHub Actions / Code Tests

Variable name 'ad' should be between 3 and 40 characters long (identifier_name)
{

Check warning on line 265 in Development/UID2GoogleGMADevelopmentApp/UID2GoogleGMADevelopmentApp/GameViewController.swift

View workflow job for this annotation

GitHub Actions / Code Tests

Opening braces should be preceded by a single space and on the same line as the declaration (opening_brace)
print("Ad failed to present full screen content with error \(error.localizedDescription).")
self.rewardedInterstitialAd = nil
self.playAgainButton.isHidden = false
}

func adDidDismissFullScreenContent(_ ad: GADFullScreenPresentingAd) {

Check warning on line 271 in Development/UID2GoogleGMADevelopmentApp/UID2GoogleGMADevelopmentApp/GameViewController.swift

View workflow job for this annotation

GitHub Actions / Code Tests

Variable name 'ad' should be between 3 and 40 characters long (identifier_name)
print("Ad did dismiss full screen content.")
self.rewardedInterstitialAd = nil
self.playAgainButton.isHidden = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>UID2EnvironmentEUID</key>
<false/>
<key>GADApplicationIdentifier</key>
<string>ca-app-pub-3940256099942544~1458002511</string>
<key>SKAdNetworkItems</key>
Expand Down
6 changes: 2 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ let package = Package(
]),
.testTarget(
name: "UID2GMAPluginTests",
dependencies: ["UID2GMAPlugin"],
resources: [
.copy("TestData")
])
dependencies: ["UID2GMAPlugin"]
)
]
)
2 changes: 2 additions & 0 deletions RELEASE_PROCESS.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Version Numbering follows [Semantic Versioning](https://semver.org) standards.
* https://github.com/IABTechLab/uid2-ios-plugin-google-gma/blob/cfc508a79af81d5b8d0aefdb60881567ea08fd24/Package.swift#L18
* Update / Confirm `adapterVersion()` in `UID2GMAMediationAdapter.swift` is set to expected version
* https://github.com/IABTechLab/uid2-ios-plugin-google-gma/blob/cfc508a79af81d5b8d0aefdb60881567ea08fd24/Sources/UID2GMAPlugin/UID2GMAMediationAdapter.swift#L40-L46
* Update / Confirm `adapterVersion()` in `EUIDGMAMediationAdapter.swift` is set to expected version
* https://github.com/IABTechLab/uid2-ios-plugin-google-gma/blob/ed1ffe2c710c58da2867d9ea0b888ecfa1aedefc/Sources/UID2GMAPlugin/EUIDGMAMediationAdapter.swift#L38-L44
* Update / Confirm `version` and `source.tag` in `UID2GMAPlugin.podspec.json` are set to expected version
* https://github.com/IABTechLab/uid2-ios-plugin-google-gma/blob/main/UID2GMAPlugin.podspec.jsonL6-L12
* Add and / or Edit any ADRs that support this release
Expand Down
61 changes: 61 additions & 0 deletions Sources/UID2GMAPlugin/EUIDGMAMediationAdapter.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//
// EUIDGMAMediationAdapter.swift
//

import Foundation
import GoogleMobileAds
import UID2

/// Adapter to connect EUID to Google Mobile Ads
/// https://developers.google.com/admob/ios/open-bidding-adapter
@available(iOS 13, *)
@objc(EUIDGMAMediationAdapter)
class EUIDGMAMediationAdapter: NSObject {

required override init() { }

}

@available(iOS 13, *)
extension EUIDGMAMediationAdapter: GADRTBAdapter {

static func setUpWith(_ configuration: GADMediationServerConfiguration, completionHandler: @escaping GADMediationAdapterSetUpCompletionBlock) {

// Ensure UID2Manager has started
_ = EUIDManager.shared

completionHandler(nil)
}

func collectSignals(for params: GADRTBRequestParameters, completionHandler: @escaping GADRTBSignalCompletionHandler) {
Task {
guard let advertisingToken = await EUIDManager.shared.getAdvertisingToken() else {
completionHandler(nil, AdvertisingTokenNotFoundError())
return
}
completionHandler(advertisingToken, nil)
}
}

static func adapterVersion() -> GADVersionNumber {
var version = GADVersionNumber()
version.majorVersion = 1
version.minorVersion = 0
version.patchVersion = 0
return version
}

static func adSDKVersion() -> GADVersionNumber {
let uid2Version = UID2SDKProperties.getUID2SDKVersion()
var version = GADVersionNumber()
version.majorVersion = uid2Version.major
version.minorVersion = uid2Version.minor
version.patchVersion = uid2Version.patch
return version
}

static func networkExtrasClass() -> GADAdNetworkExtras.Type? {
return nil
}

}
11 changes: 6 additions & 5 deletions Sources/UID2GMAPlugin/UID2GMAMediationAdapter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,18 @@ extension UID2GMAMediationAdapter: GADRTBAdapter {

static func adapterVersion() -> GADVersionNumber {
var version = GADVersionNumber()
version.majorVersion = 0
version.minorVersion = 4
version.majorVersion = 1
version.minorVersion = 0
version.patchVersion = 0
return version
}

static func adSDKVersion() -> GADVersionNumber {
let uid2Version = UID2SDKProperties.getUID2SDKVersion()
var version = GADVersionNumber()
version.majorVersion = UID2SDKProperties.getUID2SDKVersion().major
version.minorVersion = UID2SDKProperties.getUID2SDKVersion().minor
version.patchVersion = UID2SDKProperties.getUID2SDKVersion().patch
version.majorVersion = uid2Version.major
version.minorVersion = uid2Version.minor
version.patchVersion = uid2Version.patch
return version
}

Expand Down
81 changes: 81 additions & 0 deletions Tests/UID2GMAPluginTests/EUIDGMAMediationAdapterTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
//
// EUIDGMAMediationAdapterTests.swift
//

import XCTest
import GoogleMobileAds
import UID2
@testable import UID2GMAPlugin

final class EUIDGMAMediationAdapterTests: XCTestCase {

/// 🟩 - GMA Adapter Request Signal Success
func testRequestSignalsSuccess() async throws {
// Seed the sample UID2Identity data in the UID2Manager
await EUIDManager.shared.setAutomaticRefreshEnabled(false)
await EUIDManager.shared.setIdentity(
UID2Identity(
advertisingToken: "euid-test-token",
refreshToken: "refresh-token",
identityExpires: Date(timeIntervalSinceNow: 60 * 60).millisecondsSince1970,
refreshFrom: Date(timeIntervalSinceNow: 60 * 40).millisecondsSince1970,
refreshExpires: Date(timeIntervalSinceNow: 60 * 50).millisecondsSince1970,
refreshResponseKey: ""
)
)

let signal = try await EUIDGMAMediationAdapter().collectSignals(for: GADRTBRequestParameters())

// Confirm that Adapter returns expected data
XCTAssertEqual("euid-test-token", signal)
}

/// 🟥 - GMA Adapter Request Signal Error No Identity
func testRequestSignalsNoIdentity() async throws {
// Ensure no identity is set
await EUIDManager.shared.resetIdentity()

let result = await Task<String?, Error> {
try await EUIDGMAMediationAdapter().collectSignals(for: GADRTBRequestParameters())
}.result
XCTAssertThrowsError(try result.get()) { error in
let adapterError = error as? AdvertisingTokenNotFoundError
XCTAssertEqual(AdvertisingTokenNotFoundError(), adapterError)
}
}

/// 🟥 - GMA Adapter Request Signal No Advertising Token Erro
func testRequestSignalsNoAdvertisingToken() async throws {
// Set an identity with an invalid advertisingToken
await EUIDManager.shared.setAutomaticRefreshEnabled(false)
await EUIDManager.shared.setIdentity(
UID2Identity(
advertisingToken: "",
refreshToken: "refresh-token",
identityExpires: Date(timeIntervalSinceNow: 60 * 60).millisecondsSince1970,
refreshFrom: Date(timeIntervalSinceNow: 60 * 40).millisecondsSince1970,
refreshExpires: Date(timeIntervalSinceNow: 60 * 50).millisecondsSince1970,
refreshResponseKey: ""
)
)

let result = await Task<String?, Error> {
try await EUIDGMAMediationAdapter().collectSignals(for: GADRTBRequestParameters())
}.result
XCTAssertThrowsError(try result.get()) { error in
let adapterError = error as? AdvertisingTokenNotFoundError
XCTAssertEqual(AdvertisingTokenNotFoundError(), adapterError)
}
}

/// 🟩 - GMA Adapter Ad SDK Version Check Success
func testAdSDKVersion() async throws {

let adSDKVersion = EUIDGMAMediationAdapter.adSDKVersion()
let sdkVersion = await EUIDManager.shared.sdkVersion

XCTAssertEqual(sdkVersion.major, adSDKVersion.majorVersion)
XCTAssertEqual(sdkVersion.minor, adSDKVersion.minorVersion)
XCTAssertEqual(sdkVersion.patch, adSDKVersion.patchVersion)
}
}
9 changes: 0 additions & 9 deletions Tests/UID2GMAPluginTests/TestData/uid2identity.json

This file was deleted.

21 changes: 0 additions & 21 deletions Tests/UID2GMAPluginTests/TestExtensions/DataLoader.swift

This file was deleted.

4 changes: 2 additions & 2 deletions UID2GMAPlugin.podspec.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
"summary": "A plugin for integrating UID2 and Google GMA into iOS applications.",
"homepage": "https://unifiedid.com/",
"license": "Apache License, Version 2.0",
"version": "0.4.0",
"version": "1.0.0",
"authors": {
"David Snabel-Caunt": "[email protected]"
},
"source": {
"git": "https://github.com/IABTechLab/uid2-ios-plugin-google-gma.git",
"tag": "v0.4.0"
"tag": "v1.0.0"
},
"platforms": {
"ios": "12.0"
Expand Down