Skip to content

Commit 0a1e93f

Browse files
authored
EUID support (#19)
1 parent 1743532 commit 0a1e93f

File tree

10 files changed

+166
-42
lines changed

10 files changed

+166
-42
lines changed

Development/UID2GoogleGMADevelopmentApp/UID2GoogleGMADevelopmentApp/GameViewController.swift

+10-1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,15 @@ class GameViewController: UIViewController, GADFullScreenContentDelegate {
6363
/// Text that indicates current coin count.
6464
@IBOutlet weak var coinCountLabel: UILabel!
6565

66+
private let manager: UID2Manager = {
67+
let isEUID = Bundle.main.object(forInfoDictionaryKey: "UID2EnvironmentEUID") as? Bool ?? false
68+
if isEUID {
69+
return EUIDManager.shared
70+
} else {
71+
return UID2Manager.shared
72+
}
73+
}()
74+
6675
override func viewDidLoad() {
6776
super.viewDidLoad()
6877

@@ -110,7 +119,7 @@ class GameViewController: UIViewController, GADFullScreenContentDelegate {
110119
refreshExpires: refreshExpires,
111120
refreshResponseKey: uid2IdentityFromFile.refreshResponseKey)
112121

113-
await UID2Manager.shared.setIdentity(uid2Identity)
122+
await manager.setIdentity(uid2Identity)
114123
} catch {
115124
print("Error loading UID2Identity")
116125
}

Development/UID2GoogleGMADevelopmentApp/UID2GoogleGMADevelopmentApp/Info.plist

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
33
<plist version="1.0">
44
<dict>
5+
<key>UID2EnvironmentEUID</key>
6+
<false/>
57
<key>GADApplicationIdentifier</key>
68
<string>ca-app-pub-3940256099942544~1458002511</string>
79
<key>SKAdNetworkItems</key>

Package.swift

+2-4
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ let package = Package(
3030
]),
3131
.testTarget(
3232
name: "UID2GMAPluginTests",
33-
dependencies: ["UID2GMAPlugin"],
34-
resources: [
35-
.copy("TestData")
36-
])
33+
dependencies: ["UID2GMAPlugin"]
34+
)
3735
]
3836
)

RELEASE_PROCESS.md

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Version Numbering follows [Semantic Versioning](https://semver.org) standards.
1515
* https://github.com/IABTechLab/uid2-ios-plugin-google-gma/blob/cfc508a79af81d5b8d0aefdb60881567ea08fd24/Package.swift#L18
1616
* Update / Confirm `adapterVersion()` in `UID2GMAMediationAdapter.swift` is set to expected version
1717
* https://github.com/IABTechLab/uid2-ios-plugin-google-gma/blob/cfc508a79af81d5b8d0aefdb60881567ea08fd24/Sources/UID2GMAPlugin/UID2GMAMediationAdapter.swift#L40-L46
18+
* Update / Confirm `adapterVersion()` in `EUIDGMAMediationAdapter.swift` is set to expected version
19+
* https://github.com/IABTechLab/uid2-ios-plugin-google-gma/blob/ed1ffe2c710c58da2867d9ea0b888ecfa1aedefc/Sources/UID2GMAPlugin/EUIDGMAMediationAdapter.swift#L38-L44
1820
* Update / Confirm `version` and `source.tag` in `UID2GMAPlugin.podspec.json` are set to expected version
1921
* https://github.com/IABTechLab/uid2-ios-plugin-google-gma/blob/main/UID2GMAPlugin.podspec.jsonL6-L12
2022
* Add and / or Edit any ADRs that support this release
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//
2+
// EUIDGMAMediationAdapter.swift
3+
//
4+
5+
import Foundation
6+
import GoogleMobileAds
7+
import UID2
8+
9+
/// Adapter to connect EUID to Google Mobile Ads
10+
/// https://developers.google.com/admob/ios/open-bidding-adapter
11+
@available(iOS 13, *)
12+
@objc(EUIDGMAMediationAdapter)
13+
class EUIDGMAMediationAdapter: NSObject {
14+
15+
required override init() { }
16+
17+
}
18+
19+
@available(iOS 13, *)
20+
extension EUIDGMAMediationAdapter: GADRTBAdapter {
21+
22+
static func setUpWith(_ configuration: GADMediationServerConfiguration, completionHandler: @escaping GADMediationAdapterSetUpCompletionBlock) {
23+
24+
// Ensure UID2Manager has started
25+
_ = EUIDManager.shared
26+
27+
completionHandler(nil)
28+
}
29+
30+
func collectSignals(for params: GADRTBRequestParameters, completionHandler: @escaping GADRTBSignalCompletionHandler) {
31+
Task {
32+
guard let advertisingToken = await EUIDManager.shared.getAdvertisingToken() else {
33+
completionHandler(nil, AdvertisingTokenNotFoundError())
34+
return
35+
}
36+
completionHandler(advertisingToken, nil)
37+
}
38+
}
39+
40+
static func adapterVersion() -> GADVersionNumber {
41+
var version = GADVersionNumber()
42+
version.majorVersion = 1
43+
version.minorVersion = 0
44+
version.patchVersion = 0
45+
return version
46+
}
47+
48+
static func adSDKVersion() -> GADVersionNumber {
49+
let uid2Version = UID2SDKProperties.getUID2SDKVersion()
50+
var version = GADVersionNumber()
51+
version.majorVersion = uid2Version.major
52+
version.minorVersion = uid2Version.minor
53+
version.patchVersion = uid2Version.patch
54+
return version
55+
}
56+
57+
static func networkExtrasClass() -> GADAdNetworkExtras.Type? {
58+
return nil
59+
}
60+
61+
}

Sources/UID2GMAPlugin/UID2GMAMediationAdapter.swift

+6-5
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,18 @@ extension UID2GMAMediationAdapter: GADRTBAdapter {
4242

4343
static func adapterVersion() -> GADVersionNumber {
4444
var version = GADVersionNumber()
45-
version.majorVersion = 0
46-
version.minorVersion = 4
45+
version.majorVersion = 1
46+
version.minorVersion = 0
4747
version.patchVersion = 0
4848
return version
4949
}
5050

5151
static func adSDKVersion() -> GADVersionNumber {
52+
let uid2Version = UID2SDKProperties.getUID2SDKVersion()
5253
var version = GADVersionNumber()
53-
version.majorVersion = UID2SDKProperties.getUID2SDKVersion().major
54-
version.minorVersion = UID2SDKProperties.getUID2SDKVersion().minor
55-
version.patchVersion = UID2SDKProperties.getUID2SDKVersion().patch
54+
version.majorVersion = uid2Version.major
55+
version.minorVersion = uid2Version.minor
56+
version.patchVersion = uid2Version.patch
5657
return version
5758
}
5859

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
//
2+
// EUIDGMAMediationAdapterTests.swift
3+
//
4+
5+
import XCTest
6+
import GoogleMobileAds
7+
import UID2
8+
@testable import UID2GMAPlugin
9+
10+
final class EUIDGMAMediationAdapterTests: XCTestCase {
11+
12+
/// 🟩 - GMA Adapter Request Signal Success
13+
func testRequestSignalsSuccess() async throws {
14+
// Seed the sample UID2Identity data in the UID2Manager
15+
await EUIDManager.shared.setAutomaticRefreshEnabled(false)
16+
await EUIDManager.shared.setIdentity(
17+
UID2Identity(
18+
advertisingToken: "euid-test-token",
19+
refreshToken: "refresh-token",
20+
identityExpires: Date(timeIntervalSinceNow: 60 * 60).millisecondsSince1970,
21+
refreshFrom: Date(timeIntervalSinceNow: 60 * 40).millisecondsSince1970,
22+
refreshExpires: Date(timeIntervalSinceNow: 60 * 50).millisecondsSince1970,
23+
refreshResponseKey: ""
24+
)
25+
)
26+
27+
let signal = try await EUIDGMAMediationAdapter().collectSignals(for: GADRTBRequestParameters())
28+
29+
// Confirm that Adapter returns expected data
30+
XCTAssertEqual("euid-test-token", signal)
31+
}
32+
33+
/// 🟥 - GMA Adapter Request Signal Error No Identity
34+
func testRequestSignalsNoIdentity() async throws {
35+
// Ensure no identity is set
36+
await EUIDManager.shared.resetIdentity()
37+
38+
let result = await Task<String?, Error> {
39+
try await EUIDGMAMediationAdapter().collectSignals(for: GADRTBRequestParameters())
40+
}.result
41+
XCTAssertThrowsError(try result.get()) { error in
42+
let adapterError = error as? AdvertisingTokenNotFoundError
43+
XCTAssertEqual(AdvertisingTokenNotFoundError(), adapterError)
44+
}
45+
}
46+
47+
/// 🟥 - GMA Adapter Request Signal No Advertising Token Erro
48+
func testRequestSignalsNoAdvertisingToken() async throws {
49+
// Set an identity with an invalid advertisingToken
50+
await EUIDManager.shared.setAutomaticRefreshEnabled(false)
51+
await EUIDManager.shared.setIdentity(
52+
UID2Identity(
53+
advertisingToken: "",
54+
refreshToken: "refresh-token",
55+
identityExpires: Date(timeIntervalSinceNow: 60 * 60).millisecondsSince1970,
56+
refreshFrom: Date(timeIntervalSinceNow: 60 * 40).millisecondsSince1970,
57+
refreshExpires: Date(timeIntervalSinceNow: 60 * 50).millisecondsSince1970,
58+
refreshResponseKey: ""
59+
)
60+
)
61+
62+
let result = await Task<String?, Error> {
63+
try await EUIDGMAMediationAdapter().collectSignals(for: GADRTBRequestParameters())
64+
}.result
65+
XCTAssertThrowsError(try result.get()) { error in
66+
let adapterError = error as? AdvertisingTokenNotFoundError
67+
XCTAssertEqual(AdvertisingTokenNotFoundError(), adapterError)
68+
}
69+
}
70+
71+
/// 🟩 - GMA Adapter Ad SDK Version Check Success
72+
func testAdSDKVersion() async throws {
73+
74+
let adSDKVersion = EUIDGMAMediationAdapter.adSDKVersion()
75+
let sdkVersion = await EUIDManager.shared.sdkVersion
76+
77+
XCTAssertEqual(sdkVersion.major, adSDKVersion.majorVersion)
78+
XCTAssertEqual(sdkVersion.minor, adSDKVersion.minorVersion)
79+
XCTAssertEqual(sdkVersion.patch, adSDKVersion.patchVersion)
80+
}
81+
}

Tests/UID2GMAPluginTests/TestData/uid2identity.json

-9
This file was deleted.

Tests/UID2GMAPluginTests/TestExtensions/DataLoader.swift

-21
This file was deleted.

UID2GMAPlugin.podspec.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
"summary": "A plugin for integrating UID2 and Google GMA into iOS applications.",
44
"homepage": "https://unifiedid.com/",
55
"license": "Apache License, Version 2.0",
6-
"version": "0.4.0",
6+
"version": "1.0.0",
77
"authors": {
88
"David Snabel-Caunt": "dave.snabel-caunt@thetradedesk.com"
99
},
1010
"source": {
1111
"git": "https://github.com/IABTechLab/uid2-ios-plugin-google-gma.git",
12-
"tag": "v0.4.0"
12+
"tag": "v1.0.0"
1313
},
1414
"platforms": {
1515
"ios": "12.0"

0 commit comments

Comments
 (0)