-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
KSRAnalytics.swift
1653 lines (1425 loc) · 51.1 KB
/
KSRAnalytics.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
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import AppboySegment
import KsApi
import PassKit
import Prelude
import UIKit
public final class KSRAnalytics {
private let bundle: NSBundleType
internal private(set) var config: Config?
private let device: UIDeviceType
private(set) var loggedInUser: User?
public var logEventCallback: ((String, [String: Any]) -> Void)?
private let screen: UIScreenType
private var segmentClient: (TrackingClientType & IdentifyingTrackingClient)?
/// Configures `KSRAnalytics` with a Segment tracking client. Call is idempotent and will only set once.
public func configureSegmentClient(_ segmentClient: TrackingClientType & IdentifyingTrackingClient) {
guard self.segmentClient == nil else { return }
self.segmentClient = segmentClient
}
private enum SegmentEvent: String, CaseIterable {
case cardClicked = "Card Clicked"
case ctaClicked = "CTA Clicked"
case pageViewed = "Page Viewed"
case videoPlaybackStarted = "Video Playback Started"
}
/// Determines the screen from which the event is sent.
public enum PageContext: String {
case activities = "activity_feed" // ActivitiesViewController
case addOnsSelection = "add_ons" // RewardAddOnSelectionViewController
case campaign // ProjectDescriptionViewController
case changePayment = "change_payment" // PledgeViewController
case checkout // // PledgeViewController
case creatorDashboard = "creator_dashboard" // DashboardViewController
case discovery = "discover" // DiscoveryViewController
case forgotPassword = "forgot_password" // ResetPasswordViewController
case landingPage = "landing_page" // LandingViewController
case login = "log_in" // LoginViewController
case loginTout = "log_in_sign_up" // LoginToutViewController
case managePledgeScreen = "manage_pledge" // ManagePledgeViewController
case onboarding // CategorySelectionViewController, CuratedProjectsViewController
case pledgeAddNewCard = "pledge_add_new_card" // AddNewCardViewController
case pledgeScreen = "pledge" // PledgeViewController
case projectPage = "project" // ProjectPageViewController
case profile // BackerDashboardProjectsViewController
case rewards // RewardsViewController
case search // SearchViewController
case settingsAddNewCard = "settings_add_new_card" // AddNewCardViewController
case signup = "sign_up" // SignupViewController
case thanks // ThanksViewController
case twoFactorAuth = "two_factor_auth" // TwoFactorViewController
case updatePledge = "update_pledge" // PledgeViewController
}
/// Determines the authentication type for login or signup events.
public enum AuthType {
case email
case facebook
var trackingString: String {
switch self {
case .email: return "Email"
case .facebook: return "Facebook"
}
}
}
/**
Determines the place from which the external link was presented.
- projectCreator: The creator profile, usually seen by pressing the creator's name on the project page.
- projectDescription: The project description page.
- projectUpdates: The project updates page.
**/
public enum ExternalLinkContext {
case projectCreator
case projectDescription
case projectUpdate
case projectUpdates
var trackingString: String {
switch self {
case .projectCreator:
return "project_creator"
case .projectDescription:
return "project_description"
case .projectUpdate:
return "project_update"
case .projectUpdates:
return "project_updates"
}
}
}
/**
Determines the place from which the message dialog was presented.
- backerModal: The backing view, usually seen by pressing "View pledge" on the project page.
- creatorActivity: The creator's activity feed.
- messages: The messages inbox.
- projectMessages: The messages inbox for a particular project of a creator's.
- projectPage: The project page.
*/
public enum MessageDialogContext: String, Equatable {
case backerModal = "backer_modal"
case creatorActivity = "creator_activity"
case messages
case projectMessages = "project_messages"
case projectPage = "project_page"
}
/**
Determines the place from which the comments dialog was presented.
- projectActivity: The creator's project activity screen.
- projectComments: The comments screen for a project.
- updateComments: The comments screen for an update.
*/
public enum CommentDialogContext {
case projectActivity
case projectComments
case updateComments
var trackingString: String {
switch self {
case .projectActivity: return "project_activity"
case .projectComments: return "project_comments"
case .updateComments: return "update_comments"
}
}
}
/**
Indicates which button or link the user has clicked or tapped; describes CTA Clicked events.
*/
public enum CTAContext {
case addOnsContinue
case campaignDetails
case creatorDashboard
case creatorDetails
case discover
case discoverFilter
case discoverSort
case forgotPassword
case logInInitiate
case logInOrSignUp
case logInSubmit
case pledgeConfirm
case pledgeInitiate
case pledgeSubmit
case project
case projectSelect
case projectUpdateCreateDraft
case rewardContinue
case search
case signUpInitiate
case signUpSubmit
case watchProject
var trackingString: String {
switch self {
case .addOnsContinue: return "add_ons_continue"
case .campaignDetails: return "campaign_details"
case .creatorDashboard: return "creator_dashboard"
case .creatorDetails: return "creator_details"
case .discover: return "discover"
case .discoverFilter: return "discover_filter"
case .discoverSort: return "discover_sort"
case .forgotPassword: return "forgot_password"
case .pledgeInitiate: return "pledge_initiate"
case .pledgeConfirm: return "pledge_confirm"
case .pledgeSubmit: return "pledge_submit"
case .project: return "project"
case .projectSelect: return "creator_project_select"
case .projectUpdateCreateDraft: return "creator_project_update_create_draft"
case .logInInitiate: return "log_in_initiate"
case .logInOrSignUp: return "log_in_or_sign_up"
case .logInSubmit: return "log_in_submit"
case .rewardContinue: return "reward_continue"
case .search: return "search"
case .signUpInitiate: return "sign_up_initiate"
case .signUpSubmit: return "sign_up_submit"
case .watchProject: return "watch_project"
}
}
}
/// Determines which gesture was used.
public enum GestureType: String {
case swipe
case tap
fileprivate var trackingString: String {
switch self {
case .swipe: return "swipe"
case .tap: return "tap"
}
}
}
/**
Determines the place from which the newsletter toggle was presented.
- facebook: The Facebook confirmation signup screen.
- settings: The settings screen.
- signup: The signup screen.
- thanks: The thanks page games modal.
*/
public enum NewsletterContext {
case facebookSignup
case settings
case signup
case thanks
var trackingString: String {
switch self {
case .facebookSignup: return "facebook_signup"
case .settings: return "settings"
case .signup: return "signup"
case .thanks: return "thanks"
}
}
}
public enum ManagePledgeMenuCTAType {
case cancelPledge
case changePaymentMethod
case chooseAnotherReward
case contactCreator
case updatePledge
case viewRewards
var trackingString: String {
switch self {
case .cancelPledge: return "cancel_pledge"
case .changePaymentMethod: return "change_payment_method"
case .chooseAnotherReward: return "choose_another_reward"
case .contactCreator: return "contact_creator"
case .updatePledge: return "update_pledge"
case .viewRewards: return "view_rewards"
}
}
}
public enum CheckoutPageContext {
case paymentsPage
case projectPage
case rewardSelection
fileprivate var trackingString: String {
switch self {
case .paymentsPage: return "Payments Page"
case .projectPage: return "Project Page"
case .rewardSelection: return "Reward Selection"
}
}
}
/**
A tab or section within a grouping of content.
- backed: Section of BackerDashboardProjectViewController for backed Projects
- comments: Section of Project overview screen
- campaign: Details when user clicks "Read more"
- overview: Project overview landing screen
- updates: Section of project overview screen.
- watched:Section of BackerDashboardProjectViewController for saved Projects
- tabSelected: Navigation tab of ProjectPageViewController.
*/
public enum SectionContext {
case backed
case campaign
case comments
case dashboard
case overview
case updates
case watched
case tabSelected(TabContext)
var trackingString: String {
switch self {
case .backed: return "backed"
case .campaign: return "campaign"
case .comments: return "comments"
case .dashboard: return "dashboard"
case .overview: return "overview"
case .updates: return "updates"
case .watched: return "watched"
case let .tabSelected(tabContext): return tabContext.trackingString
}
}
public enum TabContext {
case overview
case risks
case campaign
case faqs
case environmentalCommitments
var trackingString: String {
switch self {
case .overview: return "overview"
case .risks: return "risks"
case .campaign: return "campaign"
case .faqs: return "faq"
case .environmentalCommitments: return "environment"
}
}
}
}
/**
Contextual details about an event that was fired that aren't captured in other context properties
*/
public enum TypeContext {
case allProjects
case amountGoal
case amountPledged
case apple
case applePay
case backed
case categoryName
case creditCard
case discovery(DiscoverySortContext)
case facebook
case location
case percentRaised
case pledge(PledgeContext)
case projectState
case pwl
case recommended
case results
case searchTerm
case social
case subcategoryName
case subscriptionFalse
case subscriptionTrue
case tag
case unwatch
case watch
case watched
/**
Initialize a `TypeContext` value with `DiscoveryParams` for use with discovery filters..
- parameter params: a `DiscoveryParams` object
*/
init(params: DiscoveryParams) {
if let recommended = params.recommended, recommended {
self = .recommended
} else if let starred = params.starred, starred {
self = .watched
} else if let social = params.social, social {
self = .social
} else {
self = .results
}
}
public enum DiscoverySortContext {
case endingSoon
case magic
case newest
case popular
var trackingString: String {
switch self {
case .endingSoon: return "ending_soon"
case .magic: return "magic"
case .newest: return "newest"
case .popular: return "popular"
}
}
}
public enum PledgeContext {
case fixErroredPledge
case newPledge
case managePledge
var trackingString: String {
switch self {
case .fixErroredPledge: return "fix_errored_pledge"
case .newPledge: return "new_pledge"
case .managePledge: return "manage_pledge"
}
}
}
var trackingString: String {
switch self {
case .allProjects: return "all"
case .amountGoal: return "amount_goal"
case .amountPledged: return "amount_pledged"
case .apple: return "apple"
case .applePay: return "apple_pay"
case .backed: return "backed"
case .categoryName: return "category_name"
case .creditCard: return "credit_card"
case let .discovery(discoveryContext): return discoveryContext.trackingString
case .facebook: return "facebook"
case .location: return "location"
case .percentRaised: return "percent_raised"
case let .pledge(pledgeContext): return pledgeContext.trackingString
case .projectState: return "project_state"
case .pwl: return "pwl"
case .recommended: return "recommended"
case .results: return "results"
case .searchTerm: return "search_term"
case .social: return "social"
case .subcategoryName: return "subcategory_name"
case .subscriptionFalse: return "subscription_false"
case .subscriptionTrue: return "subscription_true"
case .tag: return "tag"
case .unwatch: return "unwatch"
case .watch: return "watch"
case .watched: return "watched"
}
}
}
/**
A context providing additional details about the location the event occurs.
*/
public enum LocationContext {
case accountMenu
case curated
case discoverAdvanced
case discoverOverlay
case globalNav
case recommendations
case searchResults
var trackingString: String {
switch self {
case .accountMenu: return "account_menu"
case .curated: return "curated"
case .discoverAdvanced: return "discover_advanced"
case .discoverOverlay: return "discover_overlay"
case .globalNav: return "global_nav"
case .recommendations: return "recommendations"
case .searchResults: return "search_results"
}
}
}
/**
Determines the place from which the update was presented.
- activity: The activity feed.
- activitySample: The activity sample in Discovery.
- creatorActivity: The creator's activity feed.
- deepLink: A deep link, including push notification.
- draftPreview: The update draft editor.
- updates: The updates index.
*/
public enum UpdateContext {
case activity
case activitySample
case creatorActivity
case deepLink
case draftPreview
case updates
fileprivate var trackingString: String {
switch self {
case .activity: return "activity"
case .activitySample: return "activity_sample"
case .creatorActivity: return "creator_activity"
case .deepLink: return "deep_link"
case .draftPreview: return "draft_preview"
case .updates: return "updates"
}
}
}
public enum TabBarItemLabel: String {
case discovery
case activity
case search
case dashboard
case profile
var trackingString: String {
return self.rawValue
}
}
public struct CheckoutPropertiesData: Equatable {
let addOnsCountTotal: Int?
let addOnsCountUnique: Int?
let addOnsMinimumUsd: Double
let bonusAmountInUsd: Decimal?
let checkoutId: String?
let estimatedDelivery: TimeInterval?
let facebookCAPIUserEmail: String?
let paymentType: String?
let revenueInUsd: Decimal
let rewardId: String
let rewardMinimumUsd: Decimal
let rewardTitle: String?
let shippingEnabled: Bool
let shippingAmountUsd: Double?
let userHasStoredApplePayCard: Bool
}
public init(
bundle: NSBundleType = Bundle.main,
config: Config? = nil,
device: UIDeviceType = UIDevice.current,
loggedInUser: User? = nil,
screen: UIScreenType = UIScreen.main,
segmentClient: (TrackingClientType & IdentifyingTrackingClient)? = nil
) {
self.bundle = bundle
self.config = config
self.device = device
self.loggedInUser = loggedInUser
self.screen = screen
self.segmentClient = segmentClient
}
/// Configure Tracking Client's supporting user identity
public func identify(newUser: User?) {
guard let newUser = newUser else {
self.segmentClient?.reset()
return
}
let newData = KSRAnalyticsIdentityData(newUser)
self.segmentClient?.identify(
"\(newData.userId)",
traits: newData.allTraits
)
}
// MARK: - Activity
/// Call when the user is logged out, on the `Activity` tab and taps the `Explore Projects`button.
public func trackExploreButtonClicked() {
let properties = contextProperties(ctaContext: .discover, page: .activities)
self.track(
event: SegmentEvent.ctaClicked.rawValue,
properties: properties
)
}
// MARK: - Application Lifecycle
/**
Called when the user selected a tab bar item.
- parameter tabBarItemLabel: The tab the user is navigating to.
- parameter previousTabBarItemLabel: The tab the user is navigating from.
*/
public func trackTabBarClicked(
tabBarItemLabel: TabBarItemLabel,
previousTabBarItemLabel: TabBarItemLabel
) {
let page = pageContext(from: previousTabBarItemLabel)
switch tabBarItemLabel {
case .discovery:
let properties = contextProperties(
ctaContext: .discover,
page: page,
locationContext: .globalNav
)
self.track(
event: SegmentEvent.ctaClicked.rawValue,
properties: properties
)
default:
return
}
}
/**
Called when the user specifically taps on the Search TabBarItem
- parameter prevTabBarItemLabel: The tab the user was on before clicking search.
*/
public func trackSearchTabBarClicked(prevTabBarItemLabel: TabBarItemLabel) {
let page = pageContext(from: prevTabBarItemLabel)
let properties = contextProperties(
ctaContext: .search,
page: page,
locationContext: .globalNav
)
self.track(
event: SegmentEvent.ctaClicked.rawValue,
properties: properties
)
}
// MARK: - Discovery Events
/**
Call when a discovery page is viewed and the first page is loaded.
- parameter params: The params used for the discovery search.
*/
public func trackDiscovery(params: DiscoveryParams) {
let properties = contextProperties(page: .discovery)
.withAllValuesFrom(discoveryProperties(from: params))
self.track(
event: SegmentEvent.pageViewed.rawValue,
properties: properties
)
}
/**
Call when a filter is selected from the Explore modal.
- parameter params: The params selected from the modal.
- parameter typeContext: The context of the selected filter.
- parameter locationContext: Represents additional details of the UI interaction
*/
public func trackDiscoveryModalSelectedFilter(
params: DiscoveryParams,
typeContext: TypeContext,
locationContext: LocationContext
) {
let props = discoveryProperties(from: params)
.withAllValuesFrom(
contextProperties(
ctaContext: .discoverFilter,
page: .discovery,
typeContext: typeContext,
locationContext: locationContext
)
)
self.track(
event: SegmentEvent.ctaClicked.rawValue,
properties: props
)
}
/**
Called when saved is selected from profile.
- parameter params: The params selected from the modal.
*/
public func trackProfilePageFilterSelected(
params: DiscoveryParams
) {
let props = discoveryProperties(from: params)
.withAllValuesFrom(
contextProperties(
ctaContext: .discoverFilter,
page: .discovery,
typeContext: .watched,
locationContext: .accountMenu
)
)
self.track(
event: SegmentEvent.ctaClicked.rawValue,
properties: props
)
}
/**
Call when the user swipes between sorts or selects a sort.
if a user is on Discover Advanced and has results sorted by magic, but then clicks the button to sort by popularity,
that would be discover_sort = magic, context_cta = discover_sort, context_type = popular, context_location = discover_advanced, context_page = discover.
- parameter prevSort: The last sort selected before the new sort.
- parameter params: additional parameters associated with the current selected sort.
- parameter discoverySortContext: the context of the selected sort
*/
public func trackDiscoverySelectedSort(
prevSort: DiscoveryParams.Sort,
params: DiscoveryParams,
discoverySortContext: TypeContext.DiscoverySortContext
) {
let props = discoveryProperties(from: params)
.withAllValuesFrom([
"discover_sort": prevSort.trackingString
])
.withAllValuesFrom(
contextProperties(
ctaContext: .discoverSort,
page: .discovery,
typeContext: .discovery(discoverySortContext),
locationContext: .discoverAdvanced
)
)
self.track(
event: SegmentEvent.ctaClicked.rawValue,
properties: props
)
}
/**
Call when a project card is clicked from a list of projects
- parameter page: The `PageContext` representing the specific area the UI is interacted in
- parameter checkoutData: The `CheckoutPropertiesData` associated with this specific checkout instance
- parameter project: The `Project` corresponding to the card that was clicked
- parameter typeContext: Additional information about an event that was not captured in other context properties for the `Project` tapped.
- parameter location: The optional `LocationContext` representing additional details of the UI interaction
- parameter params: The optional `DiscoveryParams ` associated with the list of projects
- parameter reward: The optional `Reward ` for the selected `Project`
- parameter section: The optional `SectionContext ` representing the grouping of content
*/
public func trackProjectCardClicked(
page: PageContext,
project: Project,
checkoutData: CheckoutPropertiesData? = nil,
typeContext: TypeContext? = nil,
location: LocationContext? = nil,
params: DiscoveryParams? = nil,
reward: Reward? = nil,
section: SectionContext? = nil
) {
var props = projectProperties(from: project, loggedInUser: self.loggedInUser)
.withAllValuesFrom(contextProperties(
ctaContext: .project,
page: page,
sectionContext: section,
typeContext: typeContext,
locationContext: location
))
if let checkoutProps = checkoutData {
props = props.withAllValuesFrom(checkoutProperties(from: checkoutProps, and: reward))
}
if let discoveryParams = params {
props = props.withAllValuesFrom(discoveryProperties(from: discoveryParams))
}
self.track(
event: SegmentEvent.ctaClicked.rawValue,
properties: props
)
}
/**
Call when a video starts playing on a project
- parameter project: The `Project` corresponding to the video that started playing.
- parameter videoLength: The length of video in seconds
- parameter videoPosition: The index position of the playhead, in seconds
*/
public func trackProjectVideoPlaybackStarted(
project: Project,
videoLength: Int,
videoPosition: Int
) {
let props = projectProperties(from: project, loggedInUser: self.loggedInUser)
.withAllValuesFrom(videoProperties(videoLength: videoLength, videoPosition: videoPosition))
.withAllValuesFrom(contextProperties(page: .projectPage))
self.track(
event: SegmentEvent.videoPlaybackStarted.rawValue,
properties: props
)
}
// MARK: - Creator Dashboard Events
/**
Call when the creator dashboard page is viewed and the first page is loaded.
*/
public func trackCreatorDashboardPageViewed() {
let props = contextProperties(
ctaContext: .creatorDashboard,
page: .creatorDashboard,
sectionContext: .dashboard
)
self.track(event: SegmentEvent.pageViewed.rawValue, properties: props)
}
/**
Call when a project is switched via dropdown at the top of the creator dashboard
- parameter project: The `Project` that the creator switched to.
- parameter refTag: The ref tag used when switching projects.
*/
public func trackCreatorDashboardSwitchProjectClicked(project: Project, refTag: RefTag?) {
let props = projectProperties(from: project, loggedInUser: self.loggedInUser)
.withAllValuesFrom(contextProperties(
ctaContext: .projectSelect,
page: .creatorDashboard,
sectionContext: .dashboard
))
self.track(
event: SegmentEvent.ctaClicked.rawValue,
properties: props,
refTag: refTag?.stringTag
)
}
/**
Call when 'Post Update' is tapped in the creator dashboard
- parameter project: The `Project` corresponding to the update.
- parameter refTag: The ref tag used when switching projects.
*/
public func trackCreatorDashboardPostUpdateClicked(project: Project, refTag: RefTag?) {
let props = projectProperties(from: project, loggedInUser: self.loggedInUser)
.withAllValuesFrom(contextProperties(
ctaContext: .projectUpdateCreateDraft,
page: .creatorDashboard,
sectionContext: .dashboard
))
self.track(
event: SegmentEvent.ctaClicked.rawValue,
properties: props,
refTag: refTag?.stringTag
)
}
// MARK: - Pledge Events
public func trackAddOnsContinueButtonClicked(
project: Project,
reward: Reward,
checkoutData: CheckoutPropertiesData,
refTag: RefTag?
) {
let props = projectProperties(from: project, loggedInUser: self.loggedInUser)
.withAllValuesFrom(contextProperties(ctaContext: .addOnsContinue, page: .addOnsSelection))
.withAllValuesFrom(checkoutProperties(from: checkoutData, and: reward))
self.track(
event: SegmentEvent.ctaClicked.rawValue,
properties: props,
refTag: refTag?.stringTag
)
}
public func trackAddOnsPageViewed(
project: Project,
reward: Reward,
checkoutData: CheckoutPropertiesData,
refTag: RefTag?
) {
let props = projectProperties(from: project, loggedInUser: self.loggedInUser)
.withAllValuesFrom(checkoutProperties(from: checkoutData, and: reward))
.withAllValuesFrom(contextProperties(page: .addOnsSelection))
self.track(
event: SegmentEvent.pageViewed.rawValue,
properties: props,
refTag: refTag?.stringTag
)
}
public func trackPledgeCTAButtonClicked(
stateType: PledgeStateCTAType,
project: Project,
optimizelyProperties _: [String: Any] = [:]
) {
let props = projectProperties(from: project, loggedInUser: self.loggedInUser)
.withAllValuesFrom(contextProperties(page: .projectPage))
switch stateType {
case .pledge:
let allProps = props
.withAllValuesFrom(optimizelyProperties() ?? [:])
.withAllValuesFrom(contextProperties(ctaContext: .pledgeInitiate))
.withAllValuesFrom(props)
self.track(
event: SegmentEvent.ctaClicked.rawValue,
properties: allProps
)
default:
return
}
}
public func trackManagePledgePageViewed(
project: Project,
reward: Reward,
checkoutData: CheckoutPropertiesData
) {
let props = projectProperties(from: project, loggedInUser: self.loggedInUser)
.withAllValuesFrom(checkoutProperties(from: checkoutData, and: reward))
.withAllValuesFrom(contextProperties(page: .managePledgeScreen))
self.track(
event: SegmentEvent.pageViewed.rawValue,
properties: props
)
}
/* Call when a reward is selected
parameters:
- project: the project being pledged to
- reward: the selected reward
- checkoutPropertiesData: the `CheckoutPropertiesData` associated with the given project and reward
- refTag: the optional RefTag associated with the pledge
*/
public func trackRewardClicked(
project: Project,
reward: Reward,
checkoutPropertiesData: KSRAnalytics.CheckoutPropertiesData,
refTag: RefTag?
) {
let props = projectProperties(from: project, loggedInUser: self.loggedInUser)
.withAllValuesFrom(contextProperties(ctaContext: .rewardContinue, page: .rewards))
.withAllValuesFrom(checkoutProperties(from: checkoutPropertiesData, and: reward))
self.track(
event: SegmentEvent.ctaClicked.rawValue,
properties: props,
refTag: refTag?.stringTag
)
}
/* Call when the rewards carousel is viewed
parameters:
- project: the project being pledged to
- checkoutPropertiesData: the `CheckoutPropertiesData` associated with the given project and reward
- refTag: the optional RefTag associated with the pledge
*/
public func trackRewardsViewed(
project: Project,
checkoutPropertiesData: KSRAnalytics.CheckoutPropertiesData,
refTag: RefTag?
) {
let props = projectProperties(from: project, loggedInUser: self.loggedInUser)
.withAllValuesFrom(checkoutProperties(from: checkoutPropertiesData))
.withAllValuesFrom(contextProperties(page: .rewards))
self.track(
event: SegmentEvent.pageViewed.rawValue,
properties: props,
refTag: refTag?.stringTag
)
}
/* Call when the PledgeViewController is shown.
parameters:
- project: the project being pledged to
- reward: the chosen reward
- pledgeViewContext: The specific context applicable to the PledgeViewModel
- checkoutData: the `CheckoutPropertiesData` associated with the given project and reward
- refTag: the associated RefTag for the pledge
*/
public func trackCheckoutPaymentPageViewed(
project: Project,
reward: Reward,
pledgeViewContext: PledgeViewContext,
checkoutData: CheckoutPropertiesData,
refTag: RefTag?
) {
var props = projectProperties(from: project, loggedInUser: self.loggedInUser)
.withAllValuesFrom(checkoutProperties(from: checkoutData, and: reward))
switch pledgeViewContext {
case .pledge:
props = props.withAllValuesFrom(contextProperties(page: .checkout))
case .changePaymentMethod:
props = props.withAllValuesFrom(contextProperties(page: .changePayment))
case .update, .updateReward:
props = props.withAllValuesFrom(contextProperties(page: .updatePledge))
default:
return
}
self.track(
event: SegmentEvent.pageViewed.rawValue,
properties: props,
refTag: refTag?.stringTag
)
}
/* Call when the Pledge button or Apple Pay button is clicked
parameters:
- project: the project being pledged to
- reward: the chosen reward
- typeContext: The context of the pledge submit button for a project.
- checkoutData: all the checkout data associated with the pledge
- refTag: the associated RefTag for the pledge
*/