Skip to content

Commit 23bb51d

Browse files
committed
add sample code
1 parent 976b575 commit 23bb51d

File tree

1 file changed

+90
-1
lines changed

1 file changed

+90
-1
lines changed

README.md

Lines changed: 90 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,92 @@
11
# firebaseanalytics-swift
22

3-
Firebase Analytics client for Swift.
3+
> This Project is under development
4+
5+
Firebase Analytics Client for Swift.
6+
7+
```swift
8+
let clientInformation: ClientInformation = .init(
9+
os: "ios",
10+
osVersion: "18.3",
11+
deviceModel: "iPhone17,3",
12+
locale: "ja-jp",
13+
localeId: 540,
14+
installMethod: "manual_install",
15+
bundleId: "com.apple.SampleApp",
16+
appVersion: "1.0",
17+
googleAppId: "1:21332412389:ios:11681asd2a3cd5d8"
18+
)
19+
20+
let session: Session = .init(
21+
firstInteraction: false,
22+
firstOpenTime: 1_737_550_800_666,
23+
nonPersonalizedAds: false,
24+
sessionId: 1_737_555_666,
25+
sessionNumber: 2,
26+
lifetimeEngagement: 1_175_666,
27+
sessionEngagement: 10055,
28+
userId: "user-id"
29+
)
30+
31+
let payload = Payload(
32+
value: 1,
33+
events: [
34+
EventPayload(
35+
eventName: "login",
36+
parameters: [
37+
.method: "Google",
38+
.platform: "app",
39+
],
40+
previousTimestampMillis: UInt(Date.now.timeIntervalSince1970 * 100),
41+
timestampMillis: UInt(Date.now.timeIntervalSince1970 * 100)
42+
),
43+
EventPayload(
44+
eventName: "_e",
45+
parameters: [
46+
"_et": .uint(891),
47+
.platform: "auto"
48+
],
49+
previousTimestampMillis: UInt(Date.now.timeIntervalSince1970 * 100),
50+
timestampMillis: UInt(Date.now.timeIntervalSince1970 * 100)
51+
),
52+
],
53+
sessionInformations: session.parameters,
54+
value4: UInt(Date.now.timeIntervalSince1970 * 100), // upload_timestamp_millis
55+
value5: UInt(Date.now.timeIntervalSince1970 * 100), // start_timestamp_millis
56+
value6: UInt(Date.now.timeIntervalSince1970 * 100), // end_timestamp_millis
57+
value7: UInt(Date.now.timeIntervalSince1970 * 100), // previous_bundle_end_timestamp_millis
58+
os: clientInformation.os,
59+
osVersion: clientInformation.osVersion,
60+
deviceModel: clientInformation.deviceModel,
61+
value11: clientInformation.locale,
62+
value12: clientInformation.localeId,
63+
installMethod: clientInformation.installMethod,
64+
bundleId: clientInformation.bundleId,
65+
appVersion: clientInformation.appVersion,
66+
value17: 110700, // gmp_version
67+
value18: 110700, // uploading_gmp_version
68+
value21: "BC75E87831231231B7A179248F24080C", // fix // app_instance_id
69+
value23: 25, // count up // bundle_sequential_index
70+
googleAppId: clientInformation.googleAppId,
71+
value26: UInt(Date.now.timeIntervalSince1970 * 100), // free // previous_bundle_start_timestamp_millis
72+
value27: "CAIIJF38-E407-4954-BC16-F693A22F9FA9", // fix // resettable_device_id
73+
value30: "d4Xw8qsfsadBoMYlsYHnot", // fix // firebase_instance_id
74+
value31: 1, // app_version_major
75+
value35: 1_727_127_969_769_945, // fix // config_version
76+
value45: 42_820_019, // fix
77+
value52: "G1--", // fix // consent_signals
78+
value64: "google_signals", // fix
79+
value71: "19911", // fix // consent_diagnostics
80+
value72: 0, // fix
81+
value77: 13 // count up
82+
)
83+
84+
let analytics = Analytics(
85+
httpClient: .urlSession(.shared),
86+
userAgent: "SampleApp/1 CFNetwork/3826.400.120 Darwin/24.3.0",
87+
clientInformation: clientInformation,
88+
session: session
89+
)
90+
91+
try await analytics.log(payload: payload)
92+
```

0 commit comments

Comments
 (0)