Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: FullStory Integration and Analytics Implementation #471

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,4 @@ default_config/
I18N/
*.lproj/
!en.lproj/
/config_script/__pycache__
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import Foundation
import Core

public enum AuthMethod: Equatable {
case password
Expand Down Expand Up @@ -40,6 +41,7 @@ public protocol AuthorizationAnalytics {
func forgotPasswordClicked()
func resetPasswordClicked()
func resetPassword(success: Bool)
func authTrackScreenEvent(_ event: AnalyticsEvent, biValue: EventBIValue)
}

#if DEBUG
Expand All @@ -54,5 +56,6 @@ class AuthorizationAnalyticsMock: AuthorizationAnalytics {
public func forgotPasswordClicked() {}
public func resetPasswordClicked() {}
public func resetPassword(success: Bool) {}
public func authTrackScreenEvent(_ event: AnalyticsEvent, biValue: EventBIValue) {}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ public struct SignInView: View {
.hideNavigationBar()
.ignoresSafeArea(.all, edges: .horizontal)
.background(Theme.Colors.background.ignoresSafeArea(.all))
.onFirstAppear{
viewModel.trackScreenEvent()
}
}

@ViewBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,5 +147,11 @@ public class SignInViewModel: ObservableObject {
func trackForgotPasswordClicked() {
analytics.forgotPasswordClicked()
}


func trackScreenEvent() {
analytics.authTrackScreenEvent(
.logistrationSignIn,
biValue: .logistrationSignIn
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ public struct SignUpView: View {
.ignoresSafeArea(.all, edges: .horizontal)
.background(Theme.Colors.background.ignoresSafeArea(.all))
.hideNavigationBar()
.onFirstAppear{
viewModel.trackScreenEvent()
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,11 @@ public class SignUpViewModel: ObservableObject {
func trackCreateAccountClicked() {
analytics.createAccountClicked()
}

func trackScreenEvent() {
analytics.authTrackScreenEvent(
.logistrationRegister,
biValue: .logistrationRegister
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ public struct StartupView: View {
.onTapGesture {
UIApplication.shared.endEditing()
}
.onFirstAppear {
viewModel.trackScreenEvent()
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,8 @@ public class StartupViewModel: ObservableObject {
analytics.trackEvent(.logistrationExploreAllCourses, biValue: .logistrationExploreAllCourses)
}
}

func trackScreenEvent() {
analytics.trackScreenEvent(.logistration, biValue: .logistration)
}
}
95 changes: 95 additions & 0 deletions Authorization/AuthorizationTests/AuthorizationMock.generated.swift

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion Core/Core.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@
141F1D302B7328D4009E81EB /* WebviewCookiesUpdateProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 141F1D2F2B7328D4009E81EB /* WebviewCookiesUpdateProtocol.swift */; };
142EDD6C2B831D1400F9F320 /* BranchSDK in Frameworks */ = {isa = PBXBuildFile; productRef = 142EDD6B2B831D1400F9F320 /* BranchSDK */; };
14769D3C2B9822EE00AB36D4 /* CoreAnalytics.swift in Sources */ = {isa = PBXBuildFile; fileRef = 14769D3B2B9822EE00AB36D4 /* CoreAnalytics.swift */; };
14D912D92C2553C70077CCCE /* FullStoryConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = 14D912D82C2553C70077CCCE /* FullStoryConfig.swift */; };
14D912DB2C257E9E0077CCCE /* FullStoryConfigTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 14D912DA2C257E9E0077CCCE /* FullStoryConfigTests.swift */; };
A51CDBE72B6D21F2009B6D4E /* SegmentConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = A51CDBE62B6D21F2009B6D4E /* SegmentConfig.swift */; };
A53A32352B233DEC005FE38A /* ThemeConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = A53A32342B233DEC005FE38A /* ThemeConfig.swift */; };
A595689B2B6173DF00ED4F90 /* BranchConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = A595689A2B6173DF00ED4F90 /* BranchConfig.swift */; };
Expand Down Expand Up @@ -334,6 +336,8 @@
0E13E9173C9C4CFC19F8B6F2 /* Pods-App-Core.debugstage.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-App-Core.debugstage.xcconfig"; path = "Target Support Files/Pods-App-Core/Pods-App-Core.debugstage.xcconfig"; sourceTree = "<group>"; };
141F1D2F2B7328D4009E81EB /* WebviewCookiesUpdateProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebviewCookiesUpdateProtocol.swift; sourceTree = "<group>"; };
14769D3B2B9822EE00AB36D4 /* CoreAnalytics.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoreAnalytics.swift; sourceTree = "<group>"; };
14D912D82C2553C70077CCCE /* FullStoryConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FullStoryConfig.swift; sourceTree = "<group>"; };
14D912DA2C257E9E0077CCCE /* FullStoryConfigTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FullStoryConfigTests.swift; sourceTree = "<group>"; };
1A154A95AF4EE85A4A1C083B /* Pods-App-Core.releasedev.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-App-Core.releasedev.xcconfig"; path = "Target Support Files/Pods-App-Core/Pods-App-Core.releasedev.xcconfig"; sourceTree = "<group>"; };
2B7E6FE7843FC4CF2BFA712D /* Pods-App-Core.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-App-Core.debug.xcconfig"; path = "Target Support Files/Pods-App-Core/Pods-App-Core.debug.xcconfig"; sourceTree = "<group>"; };
349B90CD6579F7B8D257E515 /* Pods_App_Core.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_App_Core.framework; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -856,6 +860,7 @@
02CA59832BD7DDBE00D517AA /* DashboardConfig.swift */,
A53A32342B233DEC005FE38A /* ThemeConfig.swift */,
E0D586192B2FF74C009B4BA7 /* DiscoveryConfig.swift */,
14D912D82C2553C70077CCCE /* FullStoryConfig.swift */,
);
path = Config;
sourceTree = "<group>";
Expand All @@ -873,6 +878,7 @@
children = (
E09179FC2B0F204D002AB695 /* ConfigTests.swift */,
BAD9CA412B2B140100DE790A /* AgreementConfigTests.swift */,
14D912DA2C257E9E0077CCCE /* FullStoryConfigTests.swift */,
);
path = Configuration;
sourceTree = "<group>";
Expand Down Expand Up @@ -1060,6 +1066,7 @@
buildActionMask = 2147483647;
files = (
BAD9CA422B2B140100DE790A /* AgreementConfigTests.swift in Sources */,
14D912DB2C257E9E0077CCCE /* FullStoryConfigTests.swift in Sources */,
E09179FD2B0F204E002AB695 /* ConfigTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -1125,6 +1132,7 @@
02A4833A29B8A9AB00D33F33 /* DownloadManager.swift in Sources */,
06078B702BA49C3100576798 /* Dictionary+JSON.swift in Sources */,
027BD3AE2909475000392132 /* KeyboardScrollerOptions.swift in Sources */,
14D912D92C2553C70077CCCE /* FullStoryConfig.swift in Sources */,
BAFB99922B14E23D007D09F9 /* AppleSignInConfig.swift in Sources */,
141F1D302B7328D4009E81EB /* WebviewCookiesUpdateProtocol.swift in Sources */,
064987992B4D69FF0071642A /* WebViewScriptInjectionProtocol.swift in Sources */,
Expand Down Expand Up @@ -1211,7 +1219,6 @@
02F164372902A9EB0090DDEF /* StringExtension.swift in Sources */,
0231CDBE2922422D00032416 /* CSSInjector.swift in Sources */,
064987982B4D69FF0071642A /* CSSInjectionProtocol.swift in Sources */,
BAAD62C62AFCF00B000E6103 /* CustomDisclosureGroup.swift in Sources */,
029EE3ED2BF6650500F64F33 /* Bundle.swift in Sources */,
BADB3F5B2AD6EC56004D5CFA /* ResultExtension.swift in Sources */,
0236961928F9A26900EEF206 /* AuthRepository.swift in Sources */,
Expand Down
20 changes: 20 additions & 0 deletions Core/Core/Analytics/CoreAnalytics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import Foundation
public protocol CoreAnalytics {
func trackEvent(_ event: AnalyticsEvent, parameters: [String: Any]?)
func trackEvent(_ event: AnalyticsEvent, biValue: EventBIValue, parameters: [String: Any]?)
func trackScreenEvent(_ event: AnalyticsEvent, parameters: [String: Any]?)
func trackScreenEvent(_ event: AnalyticsEvent, biValue: EventBIValue, parameters: [String: Any]?)
func appreview(_ event: AnalyticsEvent, biValue: EventBIValue, action: String?, rating: Int?)
func videoQualityChanged(
_ event: AnalyticsEvent,
Expand All @@ -28,13 +30,23 @@ public extension CoreAnalytics {
func trackEvent(_ event: AnalyticsEvent, biValue: EventBIValue) {
trackEvent(event, biValue: biValue, parameters: nil)
}

func trackScreenEvent(_ event: AnalyticsEvent) {
trackScreenEvent(event, parameters: nil)
}

func trackScreenEvent(_ event: AnalyticsEvent, biValue: EventBIValue) {
trackScreenEvent(event, biValue: biValue, parameters: nil)
}
}

#if DEBUG
public class CoreAnalyticsMock: CoreAnalytics {
public init() {}
public func trackEvent(_ event: AnalyticsEvent, parameters: [String: Any]? = nil) {}
public func trackEvent(_ event: AnalyticsEvent, biValue: EventBIValue, parameters: [String: Any]?) {}
public func trackScreenEvent(_ event: AnalyticsEvent, parameters: [String: Any]?) {}
public func trackScreenEvent(_ event: AnalyticsEvent, biValue: EventBIValue, parameters: [String: Any]?) {}
public func appreview(_ event: AnalyticsEvent, biValue: EventBIValue, action: String? = nil, rating: Int? = 0) {}
public func videoQualityChanged(
_ event: AnalyticsEvent,
Expand Down Expand Up @@ -124,6 +136,10 @@ public enum AnalyticsEvent: String {
case whatnewPopup = "WhatsNew:Pop up Viewed"
case whatnewDone = "WhatsNew:Done"
case whatnewClose = "WhatsNew:Close"
case logistration = "Logistration"
case logistrationSignIn = "Logistration:Sign In"
case logistrationRegister = "Logistration:Register"
case profileEdit = "Profile:Edit Profile"
}

public enum EventBIValue: String {
Expand Down Expand Up @@ -205,6 +221,10 @@ public enum EventBIValue: String {
case whatnewPopup = "edx.bi.app.whats_new.popup.viewed"
case whatnewDone = "edx.bi.app.whats_new.done"
case whatnewClose = "edx.bi.app.whats_new.close"
case logistration = "edx.bi.app.logistration"
case logistrationSignIn = "edx.bi.app.logistration.signin"
case logistrationRegister = "edx.bi.app.logistration.register"
case profileEdit = "edx.bi.app.profile.edit"
}

public struct EventParamKey {
Expand Down
1 change: 1 addition & 0 deletions Core/Core/Configuration/Config/Config.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public protocol ConfigProtocol {
var segment: SegmentConfig { get }
var program: DiscoveryConfig { get }
var URIScheme: String { get }
var fullStory: FullStoryConfig { get }
}

public enum TokenType: String {
Expand Down
30 changes: 30 additions & 0 deletions Core/Core/Configuration/Config/FullStoryConfig.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// FullStoryConfig.swift
// Core
//
// Created by Saeed Bashir on 6/21/24.
//

import Foundation

private enum Keys: String, RawStringExtractable {
case enabled = "ENABLED"
case orgID = "ORG_ID"
}

public final class FullStoryConfig {
public var enabled: Bool = false
public var orgID: String = ""

init(dictionary: [String: AnyObject]) {
orgID = dictionary[Keys.orgID] as? String ?? ""
enabled = !orgID.isEmpty && dictionary[Keys.enabled] as? Bool ?? false
}
}

private let configKey = "FULLSTORY"
extension Config {
public var fullStory: FullStoryConfig {
FullStoryConfig(dictionary: self[configKey] as? [String: AnyObject] ?? [:])
}
}
57 changes: 57 additions & 0 deletions Core/CoreTests/Configuration/FullStoryConfigTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//
// FullStoryConfigTests.swift
// CoreTests
//
// Created by Saeed Bashir on 6/21/24.
//

import XCTest
@testable import Core

class FullStoryConfigTests: XCTestCase {

func testNoFullStoryConfig() {
let config = Config(properties: [:])
XCTAssertFalse(config.fullStory.enabled)
}

func testFullStoryEnabled() {
let configDictionary = [
"FULLSTORY": [
"ENABLED": true,
"ORG_ID": "org_id"
]
]

let config = Config(properties: configDictionary)

XCTAssertTrue(config.fullStory.enabled)
XCTAssertNotNil(config.fullStory.orgID)
}

func testFullStoryDisabled() {
let configDictionary = [
"FULLSTORY": [
"ENABLED": false,
"ORG_ID": "org_id"
]
]

let config = Config(properties: configDictionary)

XCTAssertFalse(config.fullStory.enabled)
XCTAssertNotNil(config.fullStory.orgID)
}

func testFullStoryMissingORGID() {
let configDictionary = [
"FULLSTORY": [
"ENABLED": true
]
]

let config = Config(properties: configDictionary)
XCTAssertFalse(config.fullStory.enabled)
XCTAssertEqual(config.fullStory.orgID, "")
}
}
3 changes: 3 additions & 0 deletions Course/Course/Presentation/CourseAnalytics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ public protocol CourseAnalytics {
snackbar: SnackbarType
)
func trackCourseEvent(_ event: AnalyticsEvent, biValue: EventBIValue, courseID: String)
func trackCourseScreenEvent(_ event: AnalyticsEvent, biValue: EventBIValue, courseID: String)

func plsEvent(
_ event: AnalyticsEvent,
bivalue: EventBIValue,
Expand Down Expand Up @@ -164,6 +166,7 @@ class CourseAnalyticsMock: CourseAnalytics {
snackbar: SnackbarType
) {}
public func trackCourseEvent(_ event: AnalyticsEvent, biValue: EventBIValue, courseID: String) {}
public func trackCourseScreenEvent(_ event: AnalyticsEvent, biValue: EventBIValue, courseID: String) {}
public func plsEvent(
_ event: AnalyticsEvent,
bivalue: EventBIValue,
Expand Down
4 changes: 2 additions & 2 deletions Course/Course/Presentation/Handouts/HandoutsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ struct HandoutsView: View {
announcements: nil,
router: viewModel.router,
cssInjector: viewModel.cssInjector)
viewModel.analytics.trackCourseEvent(
viewModel.analytics.trackCourseScreenEvent(
.courseHandouts,
biValue: .courseHandouts,
courseID: courseID
Expand All @@ -68,7 +68,7 @@ struct HandoutsView: View {
announcements: viewModel.updates,
router: viewModel.router,
cssInjector: viewModel.cssInjector)
viewModel.analytics.trackCourseEvent(
viewModel.analytics.trackCourseScreenEvent(
.courseAnnouncement,
biValue: .courseAnnouncement,
courseID: courseID
Expand Down
Loading
Loading