Skip to content

Commit

Permalink
Merge pull request #1070 from StepicOrg/release/1.195
Browse files Browse the repository at this point in the history
Release 1.195
  • Loading branch information
ivan-magda authored Oct 20, 2021
2 parents 1edb1d3 + e6094d1 commit a1f2c60
Show file tree
Hide file tree
Showing 63 changed files with 2,250 additions and 252 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
source "https://rubygems.org"
ruby "2.6.5"

gem "fastlane", "2.195.0"
gem "fastlane", "2.196.0"
gem "cocoapods", "1.11.2"
gem "generamba", "1.5.0"

Expand Down
24 changes: 12 additions & 12 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ GEM
artifactory (3.0.15)
atomos (0.1.3)
aws-eventstream (1.2.0)
aws-partitions (1.507.0)
aws-partitions (1.515.0)
aws-sdk-core (3.121.1)
aws-eventstream (~> 1, >= 1.0.2)
aws-partitions (~> 1, >= 1.239.0)
aws-sigv4 (~> 1.1)
jmespath (~> 1.0)
aws-sdk-kms (1.48.0)
aws-sdk-kms (1.49.0)
aws-sdk-core (~> 3, >= 3.120.0)
aws-sigv4 (~> 1.1)
aws-sdk-s3 (1.103.0)
Expand Down Expand Up @@ -82,11 +82,11 @@ GEM
domain_name (0.5.20190701)
unf (>= 0.0.5, < 1.0.0)
dotenv (2.7.6)
emoji_regex (3.2.2)
emoji_regex (3.2.3)
escape (0.0.4)
ethon (0.14.0)
ethon (0.15.0)
ffi (>= 1.15.0)
excon (0.85.0)
excon (0.87.0)
faraday (1.8.0)
faraday-em_http (~> 1.0)
faraday-em_synchrony (~> 1.0)
Expand All @@ -109,10 +109,10 @@ GEM
faraday-net_http_persistent (1.2.0)
faraday-patron (1.0.0)
faraday-rack (1.0.0)
faraday_middleware (1.1.0)
faraday_middleware (1.2.0)
faraday (~> 1.0)
fastimage (2.2.5)
fastlane (2.195.0)
fastlane (2.196.0)
CFPropertyList (>= 2.3, < 4.0.0)
addressable (>= 2.8, < 3.0.0)
artifactory (~> 3.0)
Expand Down Expand Up @@ -164,7 +164,7 @@ GEM
xcodeproj (>= 1.5.0, < 2.0.0)
gh_inspector (1.1.3)
git (1.2.9.1)
google-apis-androidpublisher_v3 (0.11.0)
google-apis-androidpublisher_v3 (0.12.0)
google-apis-core (>= 0.4, < 2.a)
google-apis-core (0.4.1)
addressable (~> 2.5, >= 2.5.1)
Expand Down Expand Up @@ -209,12 +209,12 @@ GEM
i18n (1.8.10)
concurrent-ruby (~> 1.0)
jmespath (1.4.0)
json (2.5.1)
jwt (2.2.3)
json (2.6.0)
jwt (2.3.0)
liquid (4.0.0)
memoist (0.16.2)
mini_magick (4.11.0)
mini_mime (1.1.1)
mini_mime (1.1.2)
minitest (5.14.4)
molinillo (0.8.0)
multi_json (1.15.0)
Expand Down Expand Up @@ -283,7 +283,7 @@ PLATFORMS

DEPENDENCIES
cocoapods (= 1.11.2)
fastlane (= 2.195.0)
fastlane (= 2.196.0)
fastlane-plugin-firebase_app_distribution
generamba (= 1.5.0)

Expand Down
2 changes: 1 addition & 1 deletion Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ end
def testing_pods
pod 'Quick', '4.0.0'
pod 'Nimble', '9.2.1'
pod 'Mockingjay', '3.0.0-alpha.1'
pod 'Mockingjay', :git => 'https://github.com/kylef/Mockingjay.git', :branch => 'master'
end

target 'Stepic' do
Expand Down
13 changes: 9 additions & 4 deletions Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ DEPENDENCIES:
- Kanna (= 5.2.7)
- Koloda (= 5.0.1)
- lottie-ios (= 3.2.3)
- Mockingjay (= 3.0.0-alpha.1)
- Mockingjay (from `https://github.com/kylef/Mockingjay.git`, branch `master`)
- Nimble (= 9.2.1)
- Nuke (= 9.5.0)
- PanModal (from `https://github.com/ivan-magda/PanModal.git`, branch `remove-presenting-appearance-transitions`)
Expand Down Expand Up @@ -298,7 +298,6 @@ SPEC REPOS:
- Kanna
- Koloda
- lottie-ios
- Mockingjay
- nanopb
- Nimble
- Nuke
Expand Down Expand Up @@ -329,6 +328,9 @@ EXTERNAL SOURCES:
Highlightr:
:git: https://github.com/ivan-magda/Highlightr.git
:tag: v2.1.3
Mockingjay:
:branch: master
:git: https://github.com/kylef/Mockingjay.git
PanModal:
:branch: remove-presenting-appearance-transitions
:git: https://github.com/ivan-magda/PanModal.git
Expand All @@ -346,6 +348,9 @@ CHECKOUT OPTIONS:
Highlightr:
:git: https://github.com/ivan-magda/Highlightr.git
:tag: v2.1.3
Mockingjay:
:commit: 291c52cb6a5d4dfb3094f3851333f1ddbf350ff1
:git: https://github.com/kylef/Mockingjay.git
PanModal:
:commit: 32fc8b5868b0254a2025c9c01b24c0e4b3fe537d
:git: https://github.com/ivan-magda/PanModal.git
Expand Down Expand Up @@ -393,7 +398,7 @@ SPEC CHECKSUMS:
Kanna: 01cfbddc127f5ff0963692f285fcbc8a9d62d234
Koloda: d07b9199a383abc5898b62aa945a599f5e7c0c4b
lottie-ios: c058aeafa76daa4cf64d773554bccc8385d0150e
Mockingjay: 0f7c5aa49c7f1b95621cee3c79b557141f5a225c
Mockingjay: 97656c6f59879923976a0a52ef09da45756cca82
nanopb: a0ba3315591a9ae0a16a309ee504766e90db0c96
Nimble: e7e615c0335ee4bf5b0d786685451e62746117d5
Nuke: 6f400a4ea957e09149ec335a3c6acdcc814d89e4
Expand All @@ -420,6 +425,6 @@ SPEC CHECKSUMS:
VK-ios-sdk: 5bcf00a2014a7323f98db9328b603d4f96635caa
YandexMobileMetrica: 9e713c16bb6aca0ba63b84c8d7b8b86d32f4ecc4

PODFILE CHECKSUM: 4ca3c532fc5e939bc8772b61325b4b84a1fa0fef
PODFILE CHECKSUM: 9f45485f08220cf29dd4c05d283f66e467fe342b

COCOAPODS: 1.11.2
172 changes: 152 additions & 20 deletions Stepic.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Stepic/Info-Develop.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.194-develop</string>
<string>1.195-develop</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleURLTypes</key>
Expand Down Expand Up @@ -62,7 +62,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>383</string>
<string>385</string>
<key>FacebookAppID</key>
<string>171127739724012</string>
<key>FacebookDisplayName</key>
Expand Down
4 changes: 2 additions & 2 deletions Stepic/Info-Production.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.194</string>
<string>1.195</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleURLTypes</key>
Expand Down Expand Up @@ -62,7 +62,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>383</string>
<string>385</string>
<key>FacebookAppID</key>
<string>171127739724012</string>
<key>FacebookDisplayName</key>
Expand Down
4 changes: 2 additions & 2 deletions Stepic/Info-Release.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.194-release</string>
<string>1.195-release</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleURLTypes</key>
Expand Down Expand Up @@ -62,7 +62,7 @@
</dict>
</array>
<key>CFBundleVersion</key>
<string>383</string>
<string>385</string>
<key>FacebookAppID</key>
<string>171127739724012</string>
<key>FacebookDisplayName</key>
Expand Down
5 changes: 5 additions & 0 deletions Stepic/Legacy/Analytics/ABAnalyticsServiceProtocol.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Foundation

protocol ABAnalyticsServiceProtocol {
func setGroup(test: String, group: String)
}
129 changes: 90 additions & 39 deletions Stepic/Legacy/Analytics/AnalyticsUserProperties.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import YandexMobileMetrica
final class AnalyticsUserProperties: ABAnalyticsServiceProtocol {
static let shared = AnalyticsUserProperties()

// MARK: ABAnalyticsServiceProtocol

func setGroup(test: String, group: String) {
self.setAmplitudeProperty(key: test, value: group)
// AppMetrica
Expand All @@ -24,34 +26,16 @@ final class AnalyticsUserProperties: ABAnalyticsServiceProtocol {
YMMYandexMetrica.report(userProfile, onFailure: nil)
}

func setAmplitudeProperty(key: String, value: Any?) {
if let value = value {
Amplitude.instance().setUserProperties([key: value])
} else if let identify = AMPIdentify().unset(key) {
Amplitude.instance().identify(identify)
}
}

private func setCrashlyticsProperty(key: String, value: Any?) {
if let value = value {
Crashlytics.crashlytics().setCustomValue(value, forKey: key)
}
}

private func incrementAmplitudeProperty(key: String, value: Int = 1) {
if let identify = AMPIdentify().add(key, value: value as NSObject) {
Amplitude.instance().identify(identify)
}
}
// MARK: Public API

func clearUserDependentProperties() {
self.setUserID(to: nil)
self.setCoursesCount(count: nil)
}

func setUserID(to id: Int?) {
self.setAmplitudeProperty(key: "stepik_id", value: id)
self.setCrashlyticsProperty(key: "stepik_id", value: id)
self.setAmplitudeProperty(key: UserPropertyKey.stepikID.rawValue, value: id)
self.setCrashlyticsProperty(key: UserPropertyKey.stepikID.rawValue, value: id)

let userProfileID: String? = id != nil ? String(id.require()) : nil
// Update AppMetrica user profile id.
Expand All @@ -61,44 +45,52 @@ final class AnalyticsUserProperties: ABAnalyticsServiceProtocol {
}

func incrementSubmissionsCount() {
self.incrementAmplitudeProperty(key: "submissions_count")
self.incrementAmplitudeProperty(key: UserPropertyKey.submissionsCount.rawValue)
}

func decrementCoursesCount() {
self.incrementAmplitudeProperty(key: "courses_count", value: -1)
self.incrementAmplitudeProperty(key: UserPropertyKey.coursesCount.rawValue, value: -1)
}

func incrementCoursesCount() {
self.incrementAmplitudeProperty(key: "courses_count")
self.incrementAmplitudeProperty(key: UserPropertyKey.coursesCount.rawValue)
}

func setCoursesCount(count: Int?) {
self.setAmplitudeProperty(key: "courses_count", value: count)
self.setAmplitudeProperty(key: UserPropertyKey.coursesCount.rawValue, value: count)
}

func setPushPermissionStatus(_ status: NotificationPermissionStatus) {
let key = "push_permission"

switch status {
case .authorized:
self.setAmplitudeProperty(key: key, value: "granted")
case .denied:
self.setAmplitudeProperty(key: key, value: "not_granted")
case .notDetermined:
self.setAmplitudeProperty(key: key, value: "not_determined")
}
let statusStringValue: String = {
switch status {
case .authorized:
return "granted"
case .denied:
return "not_granted"
case .notDetermined:
return "not_determined"
}
}()

self.setAmplitudeProperty(key: UserPropertyKey.pushPermission.rawValue, value: statusStringValue)
}

func setStreaksNotificationsEnabled(_ enabled: Bool) {
self.setAmplitudeProperty(key: "streaks_notifications_enabled", value: enabled ? "enabled" : "disabled")
self.setAmplitudeProperty(
key: UserPropertyKey.streaksNotificationsEnabled.rawValue,
value: enabled ? "enabled" : "disabled"
)
}

func setScreenOrientation(isPortrait: Bool) {
self.setAmplitudeProperty(key: "screen_orientation", value: isPortrait ? "portrait" : "landscape")
self.setAmplitudeProperty(
key: UserPropertyKey.screenOrientation.rawValue,
value: isPortrait ? "portrait" : "landscape"
)
}

func setApplicationID(id: String) {
self.setAmplitudeProperty(key: "application_id", value: id)
self.setAmplitudeProperty(key: UserPropertyKey.applicationID.rawValue, value: id)
}

func updateUserID() {
Expand All @@ -115,6 +107,65 @@ final class AnalyticsUserProperties: ABAnalyticsServiceProtocol {
return false
}()

self.setAmplitudeProperty(key: "is_night_mode_enabled", value: "\(isEnabled)")
self.setAmplitudeProperty(key: UserPropertyKey.isNightModeEnabled.rawValue, value: "\(isEnabled)")
}

func setRemoteConfigUserProperties(_ keysAndValues: [String: Any]) {
Amplitude.instance().setUserProperties(keysAndValues)
Crashlytics.crashlytics().setCustomKeysAndValues(keysAndValues)
self.setYandexMetricaProfileAttributes(keysAndValues)
}

// MARK: Private API

private func setAmplitudeProperty(key: String, value: Any?) {
if let value = value {
Amplitude.instance().setUserProperties([key: value])
} else if let identify = AMPIdentify().unset(key) {
Amplitude.instance().identify(identify)
}
}

private func incrementAmplitudeProperty(key: String, value: Int = 1) {
if let identify = AMPIdentify().add(key, value: value as NSObject) {
Amplitude.instance().identify(identify)
}
}

private func setCrashlyticsProperty(key: String, value: Any?) {
if let value = value {
Crashlytics.crashlytics().setCustomValue(value, forKey: key)
}
}

private func setYandexMetricaProfileAttributes(_ profileAttributes: [String: Any]) {
let userProfileUpdates = profileAttributes.map { key, value -> YMMUserProfileUpdate in
if let boolValue = value as? Bool {
return YMMProfileAttribute.customBool(key).withValue(boolValue)
} else if let doubleValue = value as? Double {
return YMMProfileAttribute.customNumber(key).withValue(doubleValue)
} else {
return YMMProfileAttribute.customString(key).withValue(String(describing: value))
}
}

let userProfile = YMMMutableUserProfile()
userProfile.apply(from: userProfileUpdates)
YMMYandexMetrica.report(userProfile) { error in
print("AnalyticsUserProperties :: YMMYandexMetrica :: failed report userProfile with error = \(error)")
}
}

// MARK: Inner Types

private enum UserPropertyKey: String {
case stepikID = "stepik_id"
case submissionsCount = "submissions_count"
case coursesCount = "courses_count"
case pushPermission = "push_permission"
case streaksNotificationsEnabled = "streaks_notifications_enabled"
case screenOrientation = "screen_orientation"
case applicationID = "application_id"
case isNightModeEnabled = "is_night_mode_enabled"
}
}
Loading

0 comments on commit a1f2c60

Please sign in to comment.