Skip to content

Commit d12c892

Browse files
marandanetoeakurnikov
authored andcommitted
fix: rename groupProperties to groups for capture methods (PostHog#140)
1 parent 6f30e1e commit d12c892

File tree

4 files changed

+27
-23
lines changed

4 files changed

+27
-23
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## Next
22

33
- chore: change host to new address ([#139](https://github.com/PostHog/posthog-ios/pull/139))
4+
- fix: rename groupProperties to groups for capture methods ([#140](https://github.com/PostHog/posthog-android/pull/140))
45

56
## 3.4.0 - 2024-05-23
67

PostHog/PostHogSDK.swift

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// swiftlint:disable file_length
2+
13
//
24
// PostHogSDK.swift
35
// PostHogSDK
@@ -234,7 +236,7 @@ private let sessionChangeThreshold: TimeInterval = 60 * 30
234236
properties: [String: Any]?,
235237
userProperties: [String: Any]? = nil,
236238
userPropertiesSetOnce: [String: Any]? = nil,
237-
groupProperties: [String: Any]? = nil,
239+
groups: [String: String]? = nil,
238240
appendSharedProps: Bool = true) -> [String: Any]
239241
{
240242
var props: [String: Any] = [:]
@@ -257,10 +259,10 @@ private let sessionChangeThreshold: TimeInterval = 60 * 30
257259
if userPropertiesSetOnce != nil {
258260
props["$set_once"] = (userPropertiesSetOnce ?? [:])
259261
}
260-
if groupProperties != nil {
262+
if groups != nil {
261263
// $groups are also set via the dynamicContext
262-
let currentGroups = props["$groups"] as? [String: Any] ?? [:]
263-
let mergedGroups = currentGroups.merging(groupProperties ?? [:]) { current, _ in current }
264+
let currentGroups = props["$groups"] as? [String: String] ?? [:]
265+
let mergedGroups = currentGroups.merging(groups ?? [:]) { current, _ in current }
264266
props["$groups"] = mergedGroups
265267
}
266268
}
@@ -396,22 +398,22 @@ private let sessionChangeThreshold: TimeInterval = 60 * 30
396398
}
397399

398400
@objc public func capture(_ event: String) {
399-
capture(event, properties: nil, userProperties: nil, userPropertiesSetOnce: nil, groupProperties: nil)
401+
capture(event, properties: nil, userProperties: nil, userPropertiesSetOnce: nil, groups: nil)
400402
}
401403

402404
@objc(captureWithEvent:properties:)
403405
public func capture(_ event: String,
404406
properties: [String: Any]? = nil)
405407
{
406-
capture(event, properties: properties, userProperties: nil, userPropertiesSetOnce: nil, groupProperties: nil)
408+
capture(event, properties: properties, userProperties: nil, userPropertiesSetOnce: nil, groups: nil)
407409
}
408410

409411
@objc(captureWithEvent:properties:userProperties:)
410412
public func capture(_ event: String,
411413
properties: [String: Any]? = nil,
412414
userProperties: [String: Any]? = nil)
413415
{
414-
capture(event, properties: properties, userProperties: userProperties, userPropertiesSetOnce: nil, groupProperties: nil)
416+
capture(event, properties: properties, userProperties: userProperties, userPropertiesSetOnce: nil, groups: nil)
415417
}
416418

417419
@objc(captureWithEvent:properties:userProperties:userPropertiesSetOnce:)
@@ -420,7 +422,7 @@ private let sessionChangeThreshold: TimeInterval = 60 * 30
420422
userProperties: [String: Any]? = nil,
421423
userPropertiesSetOnce: [String: Any]? = nil)
422424
{
423-
capture(event, properties: properties, userProperties: userProperties, userPropertiesSetOnce: userPropertiesSetOnce, groupProperties: nil)
425+
capture(event, properties: properties, userProperties: userProperties, userPropertiesSetOnce: userPropertiesSetOnce, groups: nil)
424426
}
425427

426428
private func isOptOutState() -> Bool {
@@ -431,12 +433,12 @@ private let sessionChangeThreshold: TimeInterval = 60 * 30
431433
return false
432434
}
433435

434-
@objc(captureWithEvent:properties:userProperties:userPropertiesSetOnce:groupProperties:)
436+
@objc(captureWithEvent:properties:userProperties:userPropertiesSetOnce:groups:)
435437
public func capture(_ event: String,
436438
properties: [String: Any]? = nil,
437439
userProperties: [String: Any]? = nil,
438440
userPropertiesSetOnce: [String: Any]? = nil,
439-
groupProperties: [String: Any]? = nil)
441+
groups: [String: String]? = nil)
440442
{
441443
if !isEnabled() {
442444
return
@@ -474,7 +476,7 @@ private let sessionChangeThreshold: TimeInterval = 60 * 30
474476
properties: sanitizeDicionary(properties),
475477
userProperties: sanitizeDicionary(userProperties),
476478
userPropertiesSetOnce: sanitizeDicionary(userPropertiesSetOnce),
477-
groupProperties: sanitizeDicionary(groupProperties),
479+
groups: groups,
478480
appendSharedProps: !snapshotEvent)
479481
)
480482

@@ -1002,3 +1004,5 @@ private let sessionChangeThreshold: TimeInterval = 60 * 30
10021004
}
10031005
#endif
10041006
}
1007+
1008+
// swiftlint:enable file_length

PostHogExampleStoryboard/SceneDelegate.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
1414
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
1515
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
1616
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
17+
// swiftlint:disable:next unused_optional_binding
1718
guard let _ = (scene as? UIWindowScene) else { return }
1819
}
1920

PostHogTests/PostHogSDKTest.swift

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class PostHogSDKTest: QuickSpec {
5959
properties: ["foo": "bar"],
6060
userProperties: ["userProp": "value"],
6161
userPropertiesSetOnce: ["userPropOnce": "value"],
62-
groupProperties: ["groupProp": "value"])
62+
groups: ["groupProp": "value"])
6363

6464
let events = getBatchedEvents(server)
6565

@@ -76,8 +76,8 @@ class PostHogSDKTest: QuickSpec {
7676
let setOnce = event.properties["$set_once"] as? [String: Any] ?? [:]
7777
expect(setOnce["userPropOnce"] as? String) == "value"
7878

79-
let groupProps = event.properties["$groups"] as? [String: Any] ?? [:]
80-
expect(groupProps["groupProp"] as? String) == "value"
79+
let groupProps = event.properties["$groups"] as? [String: String] ?? [:]
80+
expect(groupProps["groupProp"]) == "value"
8181

8282
sut.reset()
8383
sut.close()
@@ -163,7 +163,7 @@ class PostHogSDKTest: QuickSpec {
163163
expect(groupEvent.event) == "$groupidentify"
164164
expect(groupEvent.properties["$group_type"] as? String?) == "some-type"
165165
expect(groupEvent.properties["$group_key"] as? String?) == "some-key"
166-
expect((groupEvent.properties["$group_set"] as? [String: String])?["name"] as? String) == "some-company-name"
166+
expect((groupEvent.properties["$group_set"] as? [String: Any])?["name"] as? String) == "some-company-name"
167167

168168
sut.reset()
169169
sut.close()
@@ -451,8 +451,8 @@ class PostHogSDKTest: QuickSpec {
451451
expect(requests.count) == 1
452452
let request = requests.first
453453

454-
let groups = request!["$groups"] as? [String: Any]
455-
expect(groups!["some-type"] as? String) == "some-key"
454+
let groups = request!["$groups"] as? [String: String] ?? [:]
455+
expect(groups["some-type"]) == "some-key"
456456

457457
sut.reset()
458458
sut.close()
@@ -472,9 +472,9 @@ class PostHogSDKTest: QuickSpec {
472472
expect(events.count) == 3
473473
let event = events.last!
474474

475-
let groups = event.properties["$groups"] as? [String: Any]
476-
expect(groups!["some-type"] as? String) == "some-key"
477-
expect(groups!["some-type-2"] as? String) == "some-key-2"
475+
let groups = event.properties["$groups"] as? [String: String]
476+
expect(groups!["some-type"]) == "some-key"
477+
expect(groups!["some-type-2"]) == "some-key-2"
478478

479479
sut.reset()
480480
sut.close()
@@ -541,9 +541,7 @@ class PostHogSDKTest: QuickSpec {
541541
userProperties: ["userProp": "value",
542542
"test2": UserDefaults.standard],
543543
userPropertiesSetOnce: ["userPropOnce": "value",
544-
"test3": UserDefaults.standard],
545-
groupProperties: ["groupProp": "value",
546-
"test4": UserDefaults.standard])
544+
"test3": UserDefaults.standard])
547545

548546
let events = getBatchedEvents(server)
549547

0 commit comments

Comments
 (0)