Skip to content

Commit

Permalink
EUID Support
Browse files Browse the repository at this point in the history
  • Loading branch information
dcaunt committed Aug 12, 2024
1 parent 2b1fc35 commit d5278ce
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/IABTechLab/uid2-ios-sdk.git",
"state" : {
"revision" : "91c290d29a7093cfc209eca493d1fee80c17e16a",
"version" : "1.2.4"
"branch" : "dave/euid",
"revision" : "699fc4ca78aeb808417ff783a2986975eb964ac0"
}
}
],
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ let package = Package(
targets: ["UID2IMAPlugin"])
],
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", .branchItem("dave/euid")),
.package(url: "https://github.com/googleads/swift-package-manager-google-interactive-media-ads-ios.git", from: "3.18.5")
],
targets: [
Expand Down
48 changes: 48 additions & 0 deletions Sources/UID2IMAPlugin/EUIDIMASecureSignalsAdapter.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//
// EUIDIMASecureSignalsAdapter.swift
//

import Foundation
import GoogleInteractiveMediaAds
import UID2

@available(iOS 13.0, *)
@objc(EUIDIMASecureSignalsAdapter)
public class EUIDIMASecureSignalsAdapter: NSObject {

required public override init() {
// Ensure UID2Manager has started
_ = EUIDManager.shared
}

}

extension EUIDIMASecureSignalsAdapter: IMASecureSignalsAdapter {

public static func adapterVersion() -> IMAVersion {
let version = IMAVersion()
version.majorVersion = 0
version.minorVersion = 3
version.patchVersion = 3
return version
}

public static func adSDKVersion() -> IMAVersion {
let sdkVersion = UID2SDKProperties.getUID2SDKVersion()
let version = IMAVersion()
version.majorVersion = sdkVersion.major
version.minorVersion = sdkVersion.minor
version.patchVersion = sdkVersion.patch
return version
}

public func collectSignals(completion: @escaping IMASignalCompletionHandler) {
Task {
guard let advertisingToken = await EUIDManager.shared.getAdvertisingToken() else {
completion(nil, AdvertisingTokenNotFoundError())
return
}
completion(advertisingToken, nil)
}
}
}
78 changes: 78 additions & 0 deletions Tests/UID2IMAPluginTests/EUIDIMASecureSignalsAdapterTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
//
// EUIDIMASecureSignalsAdapterTests.swift
//

import XCTest
import GoogleInteractiveMediaAds
import UID2
import UID2IMAPlugin

final class EUIDIMASecureSignalsAdapterTests: XCTestCase {
/// 🟩 - IMA 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 EUIDIMASecureSignalsAdapter().collectSignals()

// 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 EUIDIMASecureSignalsAdapter().collectSignals()
}.result
XCTAssertThrowsError(try result.get()) { error in
let adapterError = error as? AdvertisingTokenNotFoundError
XCTAssertEqual(AdvertisingTokenNotFoundError(), adapterError)
}
}

/// 🟥 - IMA Adapter Request Signal No Advertising Token Error
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 EUIDIMASecureSignalsAdapter().collectSignals()
}.result
XCTAssertThrowsError(try result.get()) { error in
let adapterError = error as? AdvertisingTokenNotFoundError
XCTAssertEqual(AdvertisingTokenNotFoundError(), adapterError)
}
}

func testAdSDKVersion() async throws {
let adSDKVersion = EUIDIMASecureSignalsAdapter.adSDKVersion()
let sdkVersion = await EUIDManager.shared.sdkVersion

XCTAssertEqual(sdkVersion.major, adSDKVersion.majorVersion)
XCTAssertEqual(sdkVersion.minor, adSDKVersion.minorVersion)
XCTAssertEqual(sdkVersion.patch, adSDKVersion.patchVersion)
}
}

0 comments on commit d5278ce

Please sign in to comment.