Skip to content

Commit

Permalink
Add kochava integration (#4274)
Browse files Browse the repository at this point in the history
* Reapply "Add `$kochavaDeviceId` attribution convenience method (#4238)" (#4265)

This reverts commit f2ce441.

* Add userAgent tracking for attribution networks

* Fix tests

* Add X-Platform-Device header

* Rename user agent to device version

* Use correct attribution method

* [skip ci] Generating new test snapshots (#4278)

* [skip ci] Generating new test snapshots (#4279)

* [skip ci] Generating new test snapshots (#4280)

* [skip ci] Generating new test snapshots (#4281)

* [skip ci] Generating new test snapshots (#4282)

* [skip ci] Generating new test snapshots (#4283)

* Generating new test snapshots (#4284)

* Fix ttests

---------

Co-authored-by: RevenueCat Git Bot <72824662+RCGitBot@users.noreply.github.com>
  • Loading branch information
2 people authored and nyeu committed Oct 1, 2024
1 parent 22b617e commit f2d5e48
Show file tree
Hide file tree
Showing 765 changed files with 938 additions and 24 deletions.
13 changes: 13 additions & 0 deletions Sources/Misc/SystemInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,19 @@ class SystemInfo {
return Self.forceUniversalAppStore ? "iOS" : self.platformHeaderConstant
}

static var deviceVersion: String {
var systemInfo = utsname()
uname(&systemInfo)

let machineMirror = Mirror(reflecting: systemInfo.machine)
let identifier = machineMirror.children.reduce("") { identifier, element in
guard let value = element.value as? Int8, value != 0 else { return identifier }
return identifier + String(UnicodeScalar(UInt8(value)))
}

return identifier
}

var identifierForVendor: String? {
// Should match available platforms in
// https://developer.apple.com/documentation/uikit/uidevice?language=swift
Expand Down
1 change: 1 addition & 0 deletions Sources/Networking/HTTPClient/HTTPClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ class HTTPClient {
"X-Platform": SystemInfo.platformHeader,
"X-Platform-Version": SystemInfo.systemVersion,
"X-Platform-Flavor": self.systemInfo.platformFlavor,
"X-Platform-Device": SystemInfo.deviceVersion,
"X-Client-Version": SystemInfo.appVersion,
"X-Client-Build-Version": SystemInfo.buildVersion,
"X-Client-Bundle-ID": SystemInfo.bundleIdentifier,
Expand Down
13 changes: 13 additions & 0 deletions Sources/Purchasing/Purchases/Attribution.swift
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,19 @@ public extension Attribution {
self.subscriberAttributesManager.setCleverTapID(cleverTapID, appUserID: appUserID)
}

/**
* Subscriber attribute associated with the Kochava Device ID for the user.
* Recommended for the RevenueCat Kochava integration.
*
* #### Related Articles
* - [Kochava RevenueCat Integration](https://docs.revenuecat.com/docs/kochava)
*
* - Parameter kochavaDeviceID: Empty String or `nil` will delete the subscriber attribute.
*/
@objc func setKochavaDeviceID(_ kochavaDeviceID: String?) {
self.subscriberAttributesManager.setKochavaDeviceID(kochavaDeviceID, appUserID: appUserID)
}

/**
* Subscriber attribute associated with the Mixpanel Distinct ID for the user.
* Optional for the RevenueCat Mixpanel integration.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ enum ReservedSubscriberAttribute: String {
case consentStatus = "$attConsentStatus"

case ip = "$ip"
case deviceVersion = "$deviceVersion"

case adjustID = "$adjustId"
case appsFlyerID = "$appsflyerId"
Expand All @@ -39,6 +40,7 @@ enum ReservedSubscriberAttribute: String {
case oneSignalUserID = "$onesignalUserId"
case airshipChannelID = "$airshipChannelId"
case cleverTapID = "$clevertapId"
case kochavaDeviceID = "$kochavaDeviceId"
case mixpanelDistinctID = "$mixpanelDistinctId"
case firebaseAppInstanceID = "$firebaseAppInstanceId"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ class SubscriberAttributesManager {
setReservedAttribute(.cleverTapID, value: cleverTapID, appUserID: appUserID)
}

func setKochavaDeviceID(_ kochavaDeviceID: String?, appUserID: String) {
setAttributionID(kochavaDeviceID, forNetworkID: .kochavaDeviceID, appUserID: appUserID)
}

func setMixpanelDistinctID(_ mixpanelDistinctID: String?, appUserID: String) {
setReservedAttribute(.mixpanelDistinctID, value: mixpanelDistinctID, appUserID: appUserID)
}
Expand Down Expand Up @@ -136,6 +140,7 @@ class SubscriberAttributesManager {
setReservedAttribute(.idfa, value: identifierForAdvertisers, appUserID: appUserID)
setReservedAttribute(.idfv, value: identifierForVendor, appUserID: appUserID)
setReservedAttribute(.ip, value: "true", appUserID: appUserID)
setReservedAttribute(.deviceVersion, value: "true", appUserID: appUserID)
}

/// - Parameter syncedAttribute: will be called for every attribute that is updated
Expand Down
2 changes: 2 additions & 0 deletions Tests/APITesters/AllAPITests/ObjcAPITester/RCAttributionAPI.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ + (void)checkAPI {
[a setOnesignalUserID: @""];
[a setCleverTapID: nil];
[a setCleverTapID: @""];
[a setKochavaDeviceID:nil];
[a setKochavaDeviceID:@""];
[a setMixpanelDistinctID: nil];
[a setMixpanelDistinctID: @""];
[a setFirebaseAppInstanceID: nil];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ func checkAttributionAPI() {
attribution.setCleverTapID("")
attribution.setCleverTapID(nil)

attribution.setKochavaDeviceID("")
attribution.setKochavaDeviceID(nil)

attribution.setMixpanelDistinctID("")
attribution.setMixpanelDistinctID(nil)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ struct SubscriberAttributesView: View {
case setAppsflyerID
case setAirshipChannelID
case setCleverTapID
case setKochavaDeviceID
case setMparticleID
case setOnesignalID
case setFBAnonymousID
Expand Down Expand Up @@ -142,6 +143,8 @@ struct SubscriberAttributesView: View {
Purchases.shared.attribution.setAirshipChannelID(self.otherValue)
case .setCleverTapID:
Purchases.shared.attribution.setCleverTapID(self.otherValue)
case .setKochavaDeviceID:
Purchases.shared.attribution.setKochavaDeviceID(self.otherValue)
case .setMparticleID:
Purchases.shared.attribution.setMparticleID(self.otherValue)
case .setOnesignalID:
Expand Down
12 changes: 12 additions & 0 deletions Tests/UnitTests/Mocks/MockSubscriberAttributesManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,18 @@ class MockSubscriberAttributesManager: SubscriberAttributesManager {
invokedSetCleverTapIDParametersList.append((cleverTapID, appUserID))
}

var invokedSetKochavaDeviceID = false
var invokedSetKochavaDeviceIDCount = 0
var invokedSetKochavaDeviceIDParameters: (KochavaDeviceID: String?, appUserID: String?)?
var invokedSetKochavaDeviceIDParametersList = [(KochavaDeviceID: String?, appUserID: String?)]()

override func setKochavaDeviceID(_ kochavaDeviceID: String?, appUserID: String) {
invokedSetKochavaDeviceID = true
invokedSetKochavaDeviceIDCount += 1
invokedSetKochavaDeviceIDParameters = (kochavaDeviceID, appUserID)
invokedSetKochavaDeviceIDParametersList.append((kochavaDeviceID, appUserID))
}

var invokedSetMixpanelDistinctID = false
var invokedSetMixpanelDistinctIDCount = 0
var invokedSetMixpanelDistinctIDParameters: (mixpanelDistinctID: String?, appUserID: String?)?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"X-Is-Sandbox" : "true",
"X-Observer-Mode-Enabled" : "false",
"X-Platform" : "iOS",
"X-Platform-Device" : "x86_64",
"X-Platform-Flavor" : "native",
"X-Platform-Version" : "Version 17.0.0 (Build 21A342)",
"X-Preferred-Locales" : "en_EN",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"X-Is-Sandbox" : "true",
"X-Observer-Mode-Enabled" : "false",
"X-Platform" : "iOS",
"X-Platform-Device" : "x86_64",
"X-Platform-Flavor" : "native",
"X-Platform-Version" : "Version 17.0.0 (Build 21A342)",
"X-Preferred-Locales" : "en_EN",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"X-Is-Sandbox" : "true",
"X-Observer-Mode-Enabled" : "false",
"X-Platform" : "iOS",
"X-Platform-Device" : "x86_64",
"X-Platform-Flavor" : "native",
"X-Platform-Version" : "Version 17.0.0 (Build 21A342)",
"X-Preferred-Locales" : "en_EN",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"X-Is-Sandbox" : "true",
"X-Observer-Mode-Enabled" : "false",
"X-Platform" : "iOS",
"X-Platform-Device" : "x86_64",
"X-Platform-Flavor" : "native",
"X-Platform-Version" : "Version 17.0.0 (Build 21A342)",
"X-Preferred-Locales" : "en_EN",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"X-Is-Sandbox" : "true",
"X-Observer-Mode-Enabled" : "false",
"X-Platform" : "iOS",
"X-Platform-Device" : "x86_64",
"X-Platform-Flavor" : "native",
"X-Platform-Version" : "Version 17.0.0 (Build 21A342)",
"X-Preferred-Locales" : "en_EN",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"X-Is-Sandbox" : "true",
"X-Observer-Mode-Enabled" : "false",
"X-Platform" : "iOS",
"X-Platform-Device" : "x86_64",
"X-Platform-Flavor" : "native",
"X-Platform-Version" : "Version 17.0.0 (Build 21A342)",
"X-Preferred-Locales" : "en_EN",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"X-Is-Sandbox" : "true",
"X-Observer-Mode-Enabled" : "false",
"X-Platform" : "iOS",
"X-Platform-Device" : "x86_64",
"X-Platform-Flavor" : "native",
"X-Platform-Version" : "Version 17.0.0 (Build 21A342)",
"X-Preferred-Locales" : "en_EN,es_ES",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"X-Is-Sandbox" : "true",
"X-Observer-Mode-Enabled" : "false",
"X-Platform" : "iOS",
"X-Platform-Device" : "x86_64",
"X-Platform-Flavor" : "native",
"X-Platform-Version" : "Version 17.0.0 (Build 21A342)",
"X-Preferred-Locales" : "en_EN",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"X-Is-Sandbox" : "true",
"X-Observer-Mode-Enabled" : "false",
"X-Platform" : "iOS",
"X-Platform-Device" : "x86_64",
"X-Platform-Flavor" : "native",
"X-Platform-Version" : "Version 17.0.0 (Build 21A342)",
"X-Preferred-Locales" : "en_EN",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"X-Is-Sandbox" : "true",
"X-Observer-Mode-Enabled" : "false",
"X-Platform" : "iOS",
"X-Platform-Device" : "x86_64",
"X-Platform-Flavor" : "native",
"X-Platform-Version" : "Version 17.0.0 (Build 21A342)",
"X-Preferred-Locales" : "en_EN",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"X-Is-Sandbox" : "true",
"X-Observer-Mode-Enabled" : "false",
"X-Platform" : "iOS",
"X-Platform-Device" : "arm64",
"X-Platform-Flavor" : "native",
"X-Platform-Version" : "Version 17.0.0 (Build 21A342)",
"X-Preferred-Locales" : "en_EN",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"X-Is-Sandbox" : "true",
"X-Observer-Mode-Enabled" : "false",
"X-Platform" : "iOS",
"X-Platform-Device" : "arm64",
"X-Platform-Flavor" : "native",
"X-Platform-Version" : "Version 17.0.0 (Build 21A342)",
"X-Preferred-Locales" : "en_EN",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"X-Is-Sandbox" : "true",
"X-Observer-Mode-Enabled" : "false",
"X-Platform" : "iOS",
"X-Platform-Device" : "arm64",
"X-Platform-Flavor" : "native",
"X-Platform-Version" : "Version 17.0.0 (Build 21A342)",
"X-Preferred-Locales" : "en_EN",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"X-Is-Sandbox" : "true",
"X-Observer-Mode-Enabled" : "false",
"X-Platform" : "iOS",
"X-Platform-Device" : "arm64",
"X-Platform-Flavor" : "native",
"X-Platform-Version" : "Version 17.0.0 (Build 21A342)",
"X-Preferred-Locales" : "en_EN",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"X-Is-Sandbox" : "true",
"X-Observer-Mode-Enabled" : "false",
"X-Platform" : "iOS",
"X-Platform-Device" : "arm64",
"X-Platform-Flavor" : "native",
"X-Platform-Version" : "Version 17.0.0 (Build 21A342)",
"X-Preferred-Locales" : "en_EN",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"X-Is-Sandbox" : "true",
"X-Observer-Mode-Enabled" : "false",
"X-Platform" : "iOS",
"X-Platform-Device" : "arm64",
"X-Platform-Flavor" : "native",
"X-Platform-Version" : "Version 17.0.0 (Build 21A342)",
"X-Preferred-Locales" : "en_EN",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"X-Is-Sandbox" : "true",
"X-Observer-Mode-Enabled" : "false",
"X-Platform" : "iOS",
"X-Platform-Device" : "arm64",
"X-Platform-Flavor" : "native",
"X-Platform-Version" : "Version 17.0.0 (Build 21A342)",
"X-Preferred-Locales" : "en_EN,es_ES",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"X-Is-Sandbox" : "true",
"X-Observer-Mode-Enabled" : "false",
"X-Platform" : "iOS",
"X-Platform-Device" : "arm64",
"X-Platform-Flavor" : "native",
"X-Platform-Version" : "Version 17.0.0 (Build 21A342)",
"X-Preferred-Locales" : "en_EN",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"X-Is-Sandbox" : "true",
"X-Observer-Mode-Enabled" : "false",
"X-Platform" : "iOS",
"X-Platform-Device" : "arm64",
"X-Platform-Flavor" : "native",
"X-Platform-Version" : "Version 17.0.0 (Build 21A342)",
"X-Preferred-Locales" : "en_EN",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"X-Is-Sandbox" : "true",
"X-Observer-Mode-Enabled" : "false",
"X-Platform" : "iOS",
"X-Platform-Device" : "arm64",
"X-Platform-Flavor" : "native",
"X-Platform-Version" : "Version 17.0.0 (Build 21A342)",
"X-Preferred-Locales" : "en_EN",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"X-Is-Sandbox" : "true",
"X-Observer-Mode-Enabled" : "false",
"X-Platform" : "iOS",
"X-Platform-Device" : "arm64",
"X-Platform-Flavor" : "native",
"X-Platform-Version" : "Version 17.0.0 (Build 21A342)",
"X-Preferred-Locales" : "en_EN",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"X-Is-Sandbox" : "true",
"X-Observer-Mode-Enabled" : "false",
"X-Platform" : "iOS",
"X-Platform-Device" : "arm64",
"X-Platform-Flavor" : "native",
"X-Platform-Version" : "Version 17.0.0 (Build 21A342)",
"X-Preferred-Locales" : "en_EN",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"X-Is-Sandbox" : "true",
"X-Observer-Mode-Enabled" : "false",
"X-Platform" : "iOS",
"X-Platform-Device" : "arm64",
"X-Platform-Flavor" : "native",
"X-Platform-Version" : "Version 17.0.0 (Build 21A342)",
"X-Preferred-Locales" : "en_EN",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"X-Is-Sandbox" : "true",
"X-Observer-Mode-Enabled" : "false",
"X-Platform" : "iOS",
"X-Platform-Device" : "arm64",
"X-Platform-Flavor" : "native",
"X-Platform-Version" : "Version 17.0.0 (Build 21A342)",
"X-Preferred-Locales" : "en_EN",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"X-Is-Sandbox" : "true",
"X-Observer-Mode-Enabled" : "false",
"X-Platform" : "iOS",
"X-Platform-Device" : "arm64",
"X-Platform-Flavor" : "native",
"X-Platform-Version" : "Version 17.0.0 (Build 21A342)",
"X-Preferred-Locales" : "en_EN",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"X-Is-Sandbox" : "true",
"X-Observer-Mode-Enabled" : "false",
"X-Platform" : "iOS",
"X-Platform-Device" : "arm64",
"X-Platform-Flavor" : "native",
"X-Platform-Version" : "Version 17.0.0 (Build 21A342)",
"X-Preferred-Locales" : "en_EN",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"X-Is-Sandbox" : "true",
"X-Observer-Mode-Enabled" : "false",
"X-Platform" : "iOS",
"X-Platform-Device" : "arm64",
"X-Platform-Flavor" : "native",
"X-Platform-Version" : "Version 17.0.0 (Build 21A342)",
"X-Preferred-Locales" : "en_EN,es_ES",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"X-Is-Sandbox" : "true",
"X-Observer-Mode-Enabled" : "false",
"X-Platform" : "iOS",
"X-Platform-Device" : "arm64",
"X-Platform-Flavor" : "native",
"X-Platform-Version" : "Version 17.0.0 (Build 21A342)",
"X-Preferred-Locales" : "en_EN",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"X-Is-Sandbox" : "true",
"X-Observer-Mode-Enabled" : "false",
"X-Platform" : "iOS",
"X-Platform-Device" : "arm64",
"X-Platform-Flavor" : "native",
"X-Platform-Version" : "Version 17.0.0 (Build 21A342)",
"X-Preferred-Locales" : "en_EN",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"X-Is-Sandbox" : "true",
"X-Observer-Mode-Enabled" : "false",
"X-Platform" : "iOS",
"X-Platform-Device" : "arm64",
"X-Platform-Flavor" : "native",
"X-Platform-Version" : "Version 17.0.0 (Build 21A342)",
"X-Preferred-Locales" : "en_EN",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"X-Is-Sandbox" : "true",
"X-Observer-Mode-Enabled" : "false",
"X-Platform" : "iOS",
"X-Platform-Device" : "arm64",
"X-Platform-Flavor" : "native",
"X-Platform-Version" : "Version 17.0.0 (Build 21A342)",
"X-Preferred-Locales" : "en_EN",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"X-Is-Sandbox" : "true",
"X-Observer-Mode-Enabled" : "false",
"X-Platform" : "iOS",
"X-Platform-Device" : "arm64",
"X-Platform-Flavor" : "native",
"X-Platform-Version" : "Version 17.0.0 (Build 21A342)",
"X-Preferred-Locales" : "en_EN",
Expand Down
Loading

0 comments on commit f2d5e48

Please sign in to comment.