Skip to content

Commit

Permalink
EUID support
Browse files Browse the repository at this point in the history
  • Loading branch information
dcaunt committed Aug 22, 2024
1 parent 04773b7 commit e33b289
Show file tree
Hide file tree
Showing 12 changed files with 166 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/IABTechLab/uid2-ios-sdk.git",
"state" : {
"revision" : "91c290d29a7093cfc209eca493d1fee80c17e16a",
"version" : "1.2.4"
"revision" : "1e07ae53fa8b3775011254147b146b5004c532e7",
"version" : "1.6.0"
}
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ class GameViewController: UIViewController, GADFullScreenContentDelegate {
/// 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 @@ class GameViewController: UIViewController, GADFullScreenContentDelegate {
refreshExpires: refreshExpires,
refreshResponseKey: uid2IdentityFromFile.refreshResponseKey)

await UID2Manager.shared.setIdentity(uid2Identity)
await manager.setIdentity(uid2Identity)
} catch {
print("Error loading UID2Identity")
}
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
4 changes: 2 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/IABTechLab/uid2-ios-sdk.git",
"state" : {
"revision" : "91c290d29a7093cfc209eca493d1fee80c17e16a",
"version" : "1.2.4"
"revision" : "1e07ae53fa8b3775011254147b146b5004c532e7",
"version" : "1.6.0"
}
}
],
Expand Down
8 changes: 3 additions & 5 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ let package = Package(
targets: ["UID2GMAPlugin"])
],
dependencies: [
.package(url: "https://github.com/IABTechLab/uid2-ios-sdk.git", "0.2.0" ..< "2.0.0"),
.package(url: "https://github.com/IABTechLab/uid2-ios-sdk.git", "1.6.0" ..< "2.0.0"),
.package(url: "https://github.com/googleads/swift-package-manager-google-mobile-ads.git", "10.7.0" ..< "12.0.0")
],
targets: [
Expand All @@ -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
59 changes: 59 additions & 0 deletions Sources/UID2GMAPlugin/EUIDGMAMediationAdapter.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//
// 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
@objc(EUIDGMAMediationAdapter)
class EUIDGMAMediationAdapter: NSObject {

required override init() { }

}

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 = 0
version.minorVersion = 4
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
}

}
4 changes: 2 additions & 2 deletions Sources/UID2GMAPlugin/UID2GMAMediationAdapter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ extension UID2GMAMediationAdapter: GADRTBAdapter {
static func adapterVersion() -> GADVersionNumber {
var version = GADVersionNumber()
version.majorVersion = 0
version.minorVersion = 3
version.patchVersion = 3
version.minorVersion = 4
version.patchVersion = 0
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.

6 changes: 3 additions & 3 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.3.3",
"version": "0.4.0",
"authors": {
"David Snabel-Caunt": "[email protected]"
},
"source": {
"git": "https://github.com/IABTechLab/uid2-ios-plugin-google-gma.git",
"tag": "v0.3.3"
"tag": "v0.4.0"
},
"platforms": {
"ios": "13.0"
Expand All @@ -31,7 +31,7 @@
"< 12.0"
],
"UID2": [
">= 0.2",
">= 1.6",
"< 2.0"
]
}
Expand Down

0 comments on commit e33b289

Please sign in to comment.