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