-
Notifications
You must be signed in to change notification settings - Fork 11
/
Ampli.swift
949 lines (794 loc) · 30.7 KB
/
Ampli.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
/**
* Ampli - A strong typed wrapper for your Analytics
*
* This file is generated by Amplitude.
* To update run 'ampli pull swift-ampli'
*
* Required dependencies: Amplitude ~> 8.10
* Tracking Plan Version: 1
* Build: 1.0.0
* Runtime: ios:swift-ampli
*
* [View Tracking Plan](https://data.amplitude.com/test-codegen/Test%20Codegen/events/main/latest)
*
* [Full Setup Instructions](https://data.amplitude.com/test-codegen/Test%20Codegen/implementation/swift-ampli)
*/
import Foundation
import Amplitude
public typealias MiddlewareExtra = [String: Any]
public enum AmpliEnvironment: Int {
case prod, dev
}
let ApiKey: [AmpliEnvironment: String] = [
.prod: "",
.dev: ""
]
let AmpliObservePlan = AMPPlan()
.setBranch("main")
.setSource("swift-ampli")
.setVersion("1")
.setVersionId("a61c3908-ca4d-4c8d-8f81-54ad3ba17b9c")
public class Event {
public let eventType: String
public let eventProperties: [String:Any]?
public let options: EventOptions?
init(eventType: String, eventProperties: [String:Any?]?, options: EventOptions?) {
self.eventType = eventType
self.eventProperties = eventProperties?.compactMapValues { $0 }
self.options = options
}
}
public class GenericEvent<E> : Event {
private let eventFactory: (_ eventProperties: [String: Any?]?, _ options: EventOptions?) -> E
init(eventType: String, eventProperties: [String:Any?]?, options: EventOptions?, eventFactory: @escaping (_ eventProperties: [String: Any?]?, _ options: EventOptions?) -> E) {
self.eventFactory = eventFactory
super.init(eventType: eventType, eventProperties: eventProperties, options: options)
}
public func options(_ options: EventOptions) -> E {
return self.eventFactory(self.eventProperties, options)
}
public func options(deviceId: String? = nil, userId: String? = nil) -> E {
return self.options(EventOptions(deviceId: deviceId, userId: userId))
}
}
public class Identify : GenericEvent<Identify> {
private init(_ eventProperties: [String: Any?]?, _ options: EventOptions? = nil) {
super.init(
eventType: "$identify",
eventProperties: eventProperties,
options: options,
eventFactory: Identify.init
)
}
/**
Identify properties.
- Parameter requiredNumber: Description for identify requiredNumber
- Parameter optionalArray: Description for identify optionalArray
*/
public convenience init(
requiredNumber: Double,
optionalArray: [String]? = nil
) {
self.init([
"optionalArray": optionalArray,
"requiredNumber": requiredNumber
])
}
}
public class EventNoProperties : GenericEvent<EventNoProperties> {
private init(_ eventProperties: [String: Any?]?, _ options: EventOptions? = nil) {
super.init(
eventType: "Event No Properties",
eventProperties: eventProperties,
options: options,
eventFactory: EventNoProperties.init
)
}
/**
Event w no properties description
Owner: Test codegen
*/
public convenience init() {
self.init(nil)
}
}
public class EventObjectTypes : GenericEvent<EventObjectTypes> {
private init(_ eventProperties: [String: Any?]?, _ options: EventOptions? = nil) {
super.init(
eventType: "Event Object Types",
eventProperties: eventProperties,
options: options,
eventFactory: EventObjectTypes.init
)
}
/**
Event with Object and Object Array
Owner: Test codegen
- Parameter requiredObject: Property Object Type
- Parameter requiredObjectArray: Property Object Array Type
*/
public convenience init(
requiredObject: Any,
requiredObjectArray: [Any]
) {
self.init([
"requiredObject": requiredObject,
"requiredObjectArray": requiredObjectArray
])
}
}
public class EventWithAllProperties : GenericEvent<EventWithAllProperties> {
public enum RequiredEnum: String {
case enum1 = "Enum1"
case enum2 = "Enum2"
}
private init(_ eventProperties: [String: Any?]?, _ options: EventOptions? = nil) {
super.init(
eventType: "Event With All Properties",
eventProperties: eventProperties,
options: options,
eventFactory: EventWithAllProperties.init
)
}
/**
Event w all properties description
Owner: Test codegen
- Parameter requiredArray: Event 2 Property - Array
- Parameter requiredBoolean: Event 2 Property - Boolean
- Parameter requiredEnum: Event 2 Property - Enum
- Parameter requiredInteger: Event 2 Property - Integer * * Examples: * 5, 4, 3
- Parameter requiredNumber: Event 2 Property - Number
- Parameter requiredString: Event 2 Property - String
- Parameter optionalString: Event 2 Property - Optional String * * Examples: * Some string, or another
*/
public convenience init(
requiredArray: [String],
requiredBoolean: Bool,
requiredEnum: EventWithAllProperties.RequiredEnum,
requiredInteger: Int,
requiredNumber: Double,
requiredString: String,
optionalString: String? = nil
) {
self.init([
"optionalString": optionalString,
"requiredArray": requiredArray,
"requiredBoolean": requiredBoolean,
"requiredConst": "some-const-value",
"requiredEnum": requiredEnum.rawValue,
"requiredInteger": requiredInteger,
"requiredNumber": requiredNumber,
"requiredString": requiredString
])
}
}
public class EventWithArrayTypes : GenericEvent<EventWithArrayTypes> {
private init(_ eventProperties: [String: Any?]?, _ options: EventOptions? = nil) {
super.init(
eventType: "Event With Array Types",
eventProperties: eventProperties,
options: options,
eventFactory: EventWithArrayTypes.init
)
}
/**
Description for event with Array Types
Owner: Test codegen
- Parameter requiredBooleanArray: description for required boolean array
- Parameter requiredEnumArray: Description for enum array property
- Parameter requiredNumberArray: Description for required number array
- Parameter requiredObjectArray: Description for required object array
- Parameter requiredStringArray: description for required string array
*/
public convenience init(
requiredBooleanArray: [Bool],
requiredEnumArray: [String],
requiredNumberArray: [Double],
requiredObjectArray: [Any],
requiredStringArray: [String]
) {
self.init([
"requiredBooleanArray": requiredBooleanArray,
"requiredEnumArray": requiredEnumArray,
"requiredNumberArray": requiredNumberArray,
"requiredObjectArray": requiredObjectArray,
"requiredStringArray": requiredStringArray
])
}
}
public class EventWithConstTypes : GenericEvent<EventWithConstTypes> {
private init(_ eventProperties: [String: Any?]?, _ options: EventOptions? = nil) {
super.init(
eventType: "Event With Const Types",
eventProperties: eventProperties,
options: options,
eventFactory: EventWithConstTypes.init
)
}
/**
Description for event with const types
Owner: Test codegen
*/
public convenience init() {
self.init([
"Boolean Const": true,
"Integer Const": 10,
"Number Const": 2.2,
"String Const": "String-Constant",
"String Const WIth Quotes": "\"String \"Const With\" Quotes\"",
"String Int Const": 0
])
}
}
public class EventWithEnumTypes : GenericEvent<EventWithEnumTypes> {
public enum OptionalEnum: String {
case optionalEnum1 = "optional enum 1"
case optionalEnum2 = "optional enum 2"
}
public enum RequiredEnum: String {
case requiredEnum1 = "required enum 1"
case requiredEnum2 = "required enum 2"
}
private init(_ eventProperties: [String: Any?]?, _ options: EventOptions? = nil) {
super.init(
eventType: "Event With Enum Types",
eventProperties: eventProperties,
options: options,
eventFactory: EventWithEnumTypes.init
)
}
/**
Description for event with enum types
Owner: Test codegen
- Parameter requiredEnum: Description for optional enum
- Parameter optionalEnum: Description for required enum
*/
public convenience init(
requiredEnum: EventWithEnumTypes.RequiredEnum,
optionalEnum: EventWithEnumTypes.OptionalEnum? = nil
) {
self.init([
"optional enum": optionalEnum?.rawValue,
"required enum": requiredEnum.rawValue
])
}
}
public class EventWithOptionalArrayTypes : GenericEvent<EventWithOptionalArrayTypes> {
private init(_ eventProperties: [String: Any?]?, _ options: EventOptions? = nil) {
super.init(
eventType: "Event With Optional Array Types",
eventProperties: eventProperties,
options: options,
eventFactory: EventWithOptionalArrayTypes.init
)
}
/**
Description for event with optional array types
Owner: Test codegen
- Parameter optionalBooleanArray: Description for optional boolean array
- Parameter optionalEnumArray: Description for optional enum array
- Parameter optionalJsonArray: Description for optional object array
- Parameter optionalNumberArray: Description for optional number array
- Parameter optionalStringArray: Description for optional string array
*/
public convenience init(
optionalBooleanArray: [Bool]? = nil,
optionalEnumArray: [String]? = nil,
optionalJsonArray: [Any]? = nil,
optionalNumberArray: [Double]? = nil,
optionalStringArray: [String]? = nil
) {
self.init([
"optionalBooleanArray": optionalBooleanArray,
"optionalEnumArray": optionalEnumArray,
"optionalJSONArray": optionalJsonArray,
"optionalNumberArray": optionalNumberArray,
"optionalStringArray": optionalStringArray
])
}
}
public class EventWithOptionalProperties : GenericEvent<EventWithOptionalProperties> {
private init(_ eventProperties: [String: Any?]?, _ options: EventOptions? = nil) {
super.init(
eventType: "Event With Optional Properties",
eventProperties: eventProperties,
options: options,
eventFactory: EventWithOptionalProperties.init
)
}
/**
Event w optional properties description
Owner: Test codegen
- Parameter optionalArrayNumber: Property has no description provided in tracking plan.
- Parameter optionalArrayString: Property has no description provided in tracking plan.
- Parameter optionalBoolean: Property has no description provided in tracking plan.
- Parameter optionalNumber: Property has no description provided in tracking plan.
- Parameter optionalString: Optional String property description
*/
public convenience init(
optionalArrayNumber: [Double]? = nil,
optionalArrayString: [String]? = nil,
optionalBoolean: Bool? = nil,
optionalNumber: Double? = nil,
optionalString: String? = nil
) {
self.init([
"optionalArrayNumber": optionalArrayNumber,
"optionalArrayString": optionalArrayString,
"optionalBoolean": optionalBoolean,
"optionalNumber": optionalNumber,
"optionalString": optionalString
])
}
}
public class EventWithTemplateProperties : GenericEvent<EventWithTemplateProperties> {
private init(_ eventProperties: [String: Any?]?, _ options: EventOptions? = nil) {
super.init(
eventType: "Event With Template Properties",
eventProperties: eventProperties,
options: options,
eventFactory: EventWithTemplateProperties.init
)
}
/**
Event with template properties description
Owner: Test codegen
- Parameter requiredEventProperty: required_event_property description
- Parameter requiredTemplateProperty: required_template_property description
- Parameter optionalEventProperty: optional_event_property description
- Parameter optionalTemplateProperty: optional_template_property description
*/
public convenience init(
requiredEventProperty: String,
requiredTemplateProperty: String,
optionalEventProperty: Double? = nil,
optionalTemplateProperty: Double? = nil
) {
self.init([
"optional_event_property": optionalEventProperty,
"optional_template_property": optionalTemplateProperty,
"required_event_property": requiredEventProperty,
"required_template_property": requiredTemplateProperty
])
}
}
public class EventWithDifferentCasingTypes : GenericEvent<EventWithDifferentCasingTypes> {
public enum EnumWithSpace: String {
case enumWithSpace = "enum with space"
}
public enum EnumSnakeCase: String {
case enumSnakeCase = "enum_snake_case"
}
public enum EnumCamelCase: String {
case enumCamelCase = "enumCamelCase"
}
public enum EnumPascalCase: String {
case enumPascalCase = "EnumPascalCase"
}
private init(_ eventProperties: [String: Any?]?, _ options: EventOptions? = nil) {
super.init(
eventType: "event withDifferent_CasingTypes",
eventProperties: eventProperties,
options: options,
eventFactory: EventWithDifferentCasingTypes.init
)
}
/**
Description for case with space
Owner: Test codegen
- Parameter enumWithSpace: Description for enum with space
- Parameter enumSnakeCase: description_for_enum_snake_case
- Parameter enumCamelCase: descriptionForEnumCamelCase
- Parameter enumPascalCase: DescirptionForEnumPascalCase
- Parameter propertyWithSpace: Description for case with space
- Parameter propertyWithSnakeCase: Description_for_snake_case
- Parameter propertyWithCamelCase: descriptionForCamelCase
- Parameter propertyWithPascalCase: DescriptionForPascalCase
*/
public convenience init(
enumWithSpace: EventWithDifferentCasingTypes.EnumWithSpace,
enumSnakeCase: EventWithDifferentCasingTypes.EnumSnakeCase,
enumCamelCase: EventWithDifferentCasingTypes.EnumCamelCase,
enumPascalCase: EventWithDifferentCasingTypes.EnumPascalCase,
propertyWithSpace: String,
propertyWithSnakeCase: String,
propertyWithCamelCase: String,
propertyWithPascalCase: String
) {
self.init([
"enum with space": enumWithSpace.rawValue,
"enum_snake_case": enumSnakeCase.rawValue,
"enumCamelCase": enumCamelCase.rawValue,
"EnumPascalCase": enumPascalCase.rawValue,
"property with space": propertyWithSpace,
"property_with_snake_case": propertyWithSnakeCase,
"propertyWithCamelCase": propertyWithCamelCase,
"PropertyWithPascalCase": propertyWithPascalCase
])
}
}
public class EventMaxIntForTest : GenericEvent<EventMaxIntForTest> {
private init(_ eventProperties: [String: Any?]?, _ options: EventOptions? = nil) {
super.init(
eventType: "EventMaxIntForTest",
eventProperties: eventProperties,
options: options,
eventFactory: EventMaxIntForTest.init
)
}
/**
Event to test schema validation
Owner: Test codegen
- Parameter intMax10: property to test schema validation
*/
public convenience init(
intMax10: Int
) {
self.init([
"intMax10": intMax10
])
}
}
public struct LoadClientConfig {
public let plan: AMPPlan?
public init(plan: AMPPlan? = nil) {
self.plan = plan
}
}
public struct LoadClientOptions {
public let apiKey: String?
public let instance: Amplitude?
public let config: LoadClientConfig?
public init(apiKey: String? = nil, instance: Amplitude? = nil, config: LoadClientConfig? = nil) {
self.apiKey = apiKey
self.instance = instance
self.config = config
}
}
public struct LoadOptions {
public let environment: AmpliEnvironment?
public let disabled: Bool?
public let client: LoadClientOptions?
public init(environment: AmpliEnvironment? = nil, disabled: Bool? = nil, client: LoadClientOptions? = nil) {
self.environment = environment
self.disabled = disabled
self.client = client
}
}
public struct EventOptions {
public let deviceId: String?
public let userId: String?
public init(deviceId: String? = nil, userId: String? = nil) {
self.deviceId = deviceId
self.userId = userId
}
}
public class Ampli {
private var amplitude: Amplitude?
public var client: Amplitude {
get {
_ = isInitializedAndEnabled()
return amplitude!
}
}
public var isLoaded: Bool {
get {
return self.amplitude != nil
}
}
public private(set) var disabled: Bool
public static let instance: Ampli = Ampli()
public init() {
disabled = false
}
private func isInitializedAndEnabled() -> Bool {
if !self.isLoaded {
NSLog("Ampli is not yet initialized. Have you called `ampli.load()` on app start?")
return false
}
return !self.disabled
}
// options should have 'environment', 'client.api_key' or 'client.instance'
public func load(_ options: LoadOptions) -> Void {
self.disabled = options.disabled ?? false
if (self.isLoaded) {
NSLog("Warning: Ampli is already initialized. Ampli.instance.load() should be called once at application start up.")
return
}
var apiKey: String?
if (options.client?.apiKey != nil) {
apiKey = options.client?.apiKey
} else if (options.environment != nil) {
apiKey = ApiKey[options.environment!]
}
if (options.client?.instance != nil) {
self.amplitude = options.client?.instance
} else if (apiKey != nil) {
self.amplitude = Amplitude.instance()
self.amplitude?.initializeApiKey(apiKey!)
} else {
NSLog("ampli.load() requires 'environment', 'client.apiKey', or 'client.instance'")
return
}
self.amplitude?.setPlan(options.client?.config?.plan ?? AmpliObservePlan!)
// set ingestionMetadata information
let AmpliExtrasMiddleware = AMPBlockMiddleware { (payload, next) in
let ingestionMetadata: NSMutableDictionary = [
"source_name": "ios-swift-ampli",
"source_version": "1.0.0"
]
payload.event["ingestion_metadata"] = ingestionMetadata
// Continue to next middleware
next(payload)
}
self.amplitude?.addEventMiddleware(AmpliExtrasMiddleware)
}
public func track(_ event: Event, options: EventOptions? = nil, extra: MiddlewareExtra? = nil) -> Void {
if (!isInitializedAndEnabled()) {
return
}
self.handleEventOptions(event.options, options)
amplitude?.logEvent(event.eventType, withEventProperties: event.eventProperties, withMiddlewareExtra: extra as? NSMutableDictionary)
}
public func identify(_ userId: String?, _ event: Identify, options: EventOptions? = nil, extra: MiddlewareExtra? = nil) -> Void {
if (!isInitializedAndEnabled()) {
return
}
self.handleEventOptions(event.options, options, userId)
let identifyArgs = AMPIdentify()
event.eventProperties?.forEach{ key, value in
identifyArgs.set(key, value: value as? NSObject)
}
amplitude?.identify(identifyArgs)
}
public func flush() -> Void {
if (!isInitializedAndEnabled()) {
return
}
amplitude?.uploadEvents()
}
/**
Event No Properties
[View in Tracking Plan](https://data.amplitude.com/test-codegen/Test%20Codegen/events/main/latest/Event%20No%20Properties)
Event w no properties description
Owner: Test codegen
*/
public func eventNoProperties() {
self.track(EventNoProperties())
}
/**
Event Object Types
[View in Tracking Plan](https://data.amplitude.com/test-codegen/Test%20Codegen/events/main/latest/Event%20Object%20Types)
Event with Object and Object Array
Owner: Test codegen
- Parameter requiredObject: Property Object Type
- Parameter requiredObjectArray: Property Object Array Type
*/
public func eventObjectTypes(
requiredObject: Any,
requiredObjectArray: [Any]
) {
self.track(EventObjectTypes(
requiredObject: requiredObject,
requiredObjectArray: requiredObjectArray
))
}
/**
Event With All Properties
[View in Tracking Plan](https://data.amplitude.com/test-codegen/Test%20Codegen/events/main/latest/Event%20With%20All%20Properties)
Event w all properties description
Owner: Test codegen
- Parameter requiredArray: Event 2 Property - Array
- Parameter requiredBoolean: Event 2 Property - Boolean
- Parameter requiredEnum: Event 2 Property - Enum
- Parameter requiredInteger: Event 2 Property - Integer * * Examples: * 5, 4, 3
- Parameter requiredNumber: Event 2 Property - Number
- Parameter requiredString: Event 2 Property - String
- Parameter optionalString: Event 2 Property - Optional String * * Examples: * Some string, or another
*/
public func eventWithAllProperties(
requiredArray: [String],
requiredBoolean: Bool,
requiredEnum: EventWithAllProperties.RequiredEnum,
requiredInteger: Int,
requiredNumber: Double,
requiredString: String,
optionalString: String? = nil
) {
self.track(EventWithAllProperties(
requiredArray: requiredArray,
requiredBoolean: requiredBoolean,
requiredEnum: requiredEnum,
requiredInteger: requiredInteger,
requiredNumber: requiredNumber,
requiredString: requiredString,
optionalString: optionalString
))
}
/**
Event With Array Types
[View in Tracking Plan](https://data.amplitude.com/test-codegen/Test%20Codegen/events/main/latest/Event%20With%20Array%20Types)
Description for event with Array Types
Owner: Test codegen
- Parameter requiredBooleanArray: description for required boolean array
- Parameter requiredEnumArray: Description for enum array property
- Parameter requiredNumberArray: Description for required number array
- Parameter requiredObjectArray: Description for required object array
- Parameter requiredStringArray: description for required string array
*/
public func eventWithArrayTypes(
requiredBooleanArray: [Bool],
requiredEnumArray: [String],
requiredNumberArray: [Double],
requiredObjectArray: [Any],
requiredStringArray: [String]
) {
self.track(EventWithArrayTypes(
requiredBooleanArray: requiredBooleanArray,
requiredEnumArray: requiredEnumArray,
requiredNumberArray: requiredNumberArray,
requiredObjectArray: requiredObjectArray,
requiredStringArray: requiredStringArray
))
}
/**
Event With Const Types
[View in Tracking Plan](https://data.amplitude.com/test-codegen/Test%20Codegen/events/main/latest/Event%20With%20Const%20Types)
Description for event with const types
Owner: Test codegen
*/
public func eventWithConstTypes() {
self.track(EventWithConstTypes())
}
/**
Event With Enum Types
[View in Tracking Plan](https://data.amplitude.com/test-codegen/Test%20Codegen/events/main/latest/Event%20With%20Enum%20Types)
Description for event with enum types
Owner: Test codegen
- Parameter requiredEnum: Description for optional enum
- Parameter optionalEnum: Description for required enum
*/
public func eventWithEnumTypes(
requiredEnum: EventWithEnumTypes.RequiredEnum,
optionalEnum: EventWithEnumTypes.OptionalEnum? = nil
) {
self.track(EventWithEnumTypes(
requiredEnum: requiredEnum,
optionalEnum: optionalEnum
))
}
/**
Event With Optional Array Types
[View in Tracking Plan](https://data.amplitude.com/test-codegen/Test%20Codegen/events/main/latest/Event%20With%20Optional%20Array%20Types)
Description for event with optional array types
Owner: Test codegen
- Parameter optionalBooleanArray: Description for optional boolean array
- Parameter optionalEnumArray: Description for optional enum array
- Parameter optionalJsonArray: Description for optional object array
- Parameter optionalNumberArray: Description for optional number array
- Parameter optionalStringArray: Description for optional string array
*/
public func eventWithOptionalArrayTypes(
optionalBooleanArray: [Bool]? = nil,
optionalEnumArray: [String]? = nil,
optionalJsonArray: [Any]? = nil,
optionalNumberArray: [Double]? = nil,
optionalStringArray: [String]? = nil
) {
self.track(EventWithOptionalArrayTypes(
optionalBooleanArray: optionalBooleanArray,
optionalEnumArray: optionalEnumArray,
optionalJsonArray: optionalJsonArray,
optionalNumberArray: optionalNumberArray,
optionalStringArray: optionalStringArray
))
}
/**
Event With Optional Properties
[View in Tracking Plan](https://data.amplitude.com/test-codegen/Test%20Codegen/events/main/latest/Event%20With%20Optional%20Properties)
Event w optional properties description
Owner: Test codegen
- Parameter optionalArrayNumber: Property has no description provided in tracking plan.
- Parameter optionalArrayString: Property has no description provided in tracking plan.
- Parameter optionalBoolean: Property has no description provided in tracking plan.
- Parameter optionalNumber: Property has no description provided in tracking plan.
- Parameter optionalString: Optional String property description
*/
public func eventWithOptionalProperties(
optionalArrayNumber: [Double]? = nil,
optionalArrayString: [String]? = nil,
optionalBoolean: Bool? = nil,
optionalNumber: Double? = nil,
optionalString: String? = nil
) {
self.track(EventWithOptionalProperties(
optionalArrayNumber: optionalArrayNumber,
optionalArrayString: optionalArrayString,
optionalBoolean: optionalBoolean,
optionalNumber: optionalNumber,
optionalString: optionalString
))
}
/**
Event With Template Properties
[View in Tracking Plan](https://data.amplitude.com/test-codegen/Test%20Codegen/events/main/latest/Event%20With%20Template%20Properties)
Event with template properties description
Owner: Test codegen
- Parameter requiredEventProperty: required_event_property description
- Parameter requiredTemplateProperty: required_template_property description
- Parameter optionalEventProperty: optional_event_property description
- Parameter optionalTemplateProperty: optional_template_property description
*/
public func eventWithTemplateProperties(
requiredEventProperty: String,
requiredTemplateProperty: String,
optionalEventProperty: Double? = nil,
optionalTemplateProperty: Double? = nil
) {
self.track(EventWithTemplateProperties(
requiredEventProperty: requiredEventProperty,
requiredTemplateProperty: requiredTemplateProperty,
optionalEventProperty: optionalEventProperty,
optionalTemplateProperty: optionalTemplateProperty
))
}
/**
event withDifferent_CasingTypes
[View in Tracking Plan](https://data.amplitude.com/test-codegen/Test%20Codegen/events/main/latest/event%20withDifferent_CasingTypes)
Description for case with space
Owner: Test codegen
- Parameter enumWithSpace: Description for enum with space
- Parameter enumSnakeCase: description_for_enum_snake_case
- Parameter enumCamelCase: descriptionForEnumCamelCase
- Parameter enumPascalCase: DescirptionForEnumPascalCase
- Parameter propertyWithSpace: Description for case with space
- Parameter propertyWithSnakeCase: Description_for_snake_case
- Parameter propertyWithCamelCase: descriptionForCamelCase
- Parameter propertyWithPascalCase: DescriptionForPascalCase
*/
public func eventWithDifferentCasingTypes(
enumWithSpace: EventWithDifferentCasingTypes.EnumWithSpace,
enumSnakeCase: EventWithDifferentCasingTypes.EnumSnakeCase,
enumCamelCase: EventWithDifferentCasingTypes.EnumCamelCase,
enumPascalCase: EventWithDifferentCasingTypes.EnumPascalCase,
propertyWithSpace: String,
propertyWithSnakeCase: String,
propertyWithCamelCase: String,
propertyWithPascalCase: String
) {
self.track(EventWithDifferentCasingTypes(
enumWithSpace: enumWithSpace,
enumSnakeCase: enumSnakeCase,
enumCamelCase: enumCamelCase,
enumPascalCase: enumPascalCase,
propertyWithSpace: propertyWithSpace,
propertyWithSnakeCase: propertyWithSnakeCase,
propertyWithCamelCase: propertyWithCamelCase,
propertyWithPascalCase: propertyWithPascalCase
))
}
/**
EventMaxIntForTest
[View in Tracking Plan](https://data.amplitude.com/test-codegen/Test%20Codegen/events/main/latest/EventMaxIntForTest)
Event to test schema validation
Owner: Test codegen
- Parameter intMax10: property to test schema validation
*/
public func eventMaxIntForTest(
intMax10: Int
) {
self.track(EventMaxIntForTest(
intMax10: intMax10
))
}
private func handleEventOptions(_ options: EventOptions?, _ overrideOptions: EventOptions?, _ overrideUserId: String? = nil) {
let userId = overrideUserId ?? overrideOptions?.userId ?? options?.userId
if (userId != nil) {
amplitude?.setUserId(userId)
}
let deviceId = overrideOptions?.deviceId ?? options?.deviceId
if (deviceId != nil) {
amplitude?.setDeviceId(deviceId!)
}
}
}