Add new analytics parameters pathSuffix
Some checks failed
openium/resgen.swift/pipeline/head There was a failure building this commit
Some checks failed
openium/resgen.swift/pipeline/head There was a failure building this commit
This commit is contained in:
@@ -6,16 +6,16 @@ extension ColorYolo {
|
|||||||
|
|
||||||
/// Color red is #FF0000 (light) or #FF0000 (dark)"
|
/// Color red is #FF0000 (light) or #FF0000 (dark)"
|
||||||
public var red: Color {
|
public var red: Color {
|
||||||
Color("red")
|
Color("red", bundle: Bundle.main)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Color green_alpha_50 is #A000FF00 (light) or #A000FF00 (dark)"
|
/// Color green_alpha_50 is #A000FF00 (light) or #A000FF00 (dark)"
|
||||||
public var green_alpha_50: Color {
|
public var green_alpha_50: Color {
|
||||||
Color("green_alpha_50")
|
Color("green_alpha_50", bundle: Bundle.main)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Color blue_light_dark is #0000FF (light) or #0000AA (dark)"
|
/// Color blue_light_dark is #0000FF (light) or #0000AA (dark)"
|
||||||
public var blue_light_dark: Color {
|
public var blue_light_dark: Color {
|
||||||
Color("blue_light_dark")
|
Color("blue_light_dark", bundle: Bundle.main)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,16 +6,16 @@ extension UIColorYolo {
|
|||||||
|
|
||||||
/// Color red is #FF0000 (light) or #FF0000 (dark)"
|
/// Color red is #FF0000 (light) or #FF0000 (dark)"
|
||||||
@objc public var red: UIColor {
|
@objc public var red: UIColor {
|
||||||
UIColor(named: "red")!
|
UIColor(named: "red", in: Bundle.main, compatibleWith: nil)!
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Color green_alpha_50 is #A000FF00 (light) or #A000FF00 (dark)"
|
/// Color green_alpha_50 is #A000FF00 (light) or #A000FF00 (dark)"
|
||||||
@objc public var green_alpha_50: UIColor {
|
@objc public var green_alpha_50: UIColor {
|
||||||
UIColor(named: "green_alpha_50")!
|
UIColor(named: "green_alpha_50", in: Bundle.main, compatibleWith: nil)!
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Color blue_light_dark is #0000FF (light) or #0000AA (dark)"
|
/// Color blue_light_dark is #0000FF (light) or #0000AA (dark)"
|
||||||
@objc public var blue_light_dark: UIColor {
|
@objc public var blue_light_dark: UIColor {
|
||||||
UIColor(named: "blue_light_dark")!
|
UIColor(named: "blue_light_dark", in: Bundle.main, compatibleWith: nil)!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,26 +6,26 @@ import SwiftUI
|
|||||||
extension ImageYolo {
|
extension ImageYolo {
|
||||||
|
|
||||||
public var article_notification_pull_detail: Image {
|
public var article_notification_pull_detail: Image {
|
||||||
Image("article_notification_pull_detail")
|
Image("article_notification_pull_detail", bundle: Bundle.main)
|
||||||
}
|
}
|
||||||
|
|
||||||
public var article_notification_pull: Image {
|
public var article_notification_pull: Image {
|
||||||
Image("article_notification_pull")
|
Image("article_notification_pull", bundle: Bundle.main)
|
||||||
}
|
}
|
||||||
|
|
||||||
public var new_article: Image {
|
public var new_article: Image {
|
||||||
Image("new_article")
|
Image("new_article", bundle: Bundle.main)
|
||||||
}
|
}
|
||||||
|
|
||||||
public var welcome_background: Image {
|
public var welcome_background: Image {
|
||||||
Image("welcome_background")
|
Image("welcome_background", bundle: Bundle.main)
|
||||||
}
|
}
|
||||||
|
|
||||||
public var article_trash: Image {
|
public var article_trash: Image {
|
||||||
Image("article_trash")
|
Image("article_trash", bundle: Bundle.main)
|
||||||
}
|
}
|
||||||
|
|
||||||
public var ic_close_article: Image {
|
public var ic_close_article: Image {
|
||||||
Image("ic_close_article")
|
Image("ic_close_article", bundle: Bundle.main)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,26 +6,26 @@ import UIKit
|
|||||||
extension UIImageYolo {
|
extension UIImageYolo {
|
||||||
|
|
||||||
public var article_notification_pull_detail: UIImage {
|
public var article_notification_pull_detail: UIImage {
|
||||||
UIImage(named: "article_notification_pull_detail")!
|
UIImage(named: "article_notification_pull_detail", in: Bundle.main, with: nil)!
|
||||||
}
|
}
|
||||||
|
|
||||||
public var article_notification_pull: UIImage {
|
public var article_notification_pull: UIImage {
|
||||||
UIImage(named: "article_notification_pull")!
|
UIImage(named: "article_notification_pull", in: Bundle.main, with: nil)!
|
||||||
}
|
}
|
||||||
|
|
||||||
public var new_article: UIImage {
|
public var new_article: UIImage {
|
||||||
UIImage(named: "new_article")!
|
UIImage(named: "new_article", in: Bundle.main, with: nil)!
|
||||||
}
|
}
|
||||||
|
|
||||||
public var welcome_background: UIImage {
|
public var welcome_background: UIImage {
|
||||||
UIImage(named: "welcome_background")!
|
UIImage(named: "welcome_background", in: Bundle.main, with: nil)!
|
||||||
}
|
}
|
||||||
|
|
||||||
public var article_trash: UIImage {
|
public var article_trash: UIImage {
|
||||||
UIImage(named: "article_trash")!
|
UIImage(named: "article_trash", in: Bundle.main, with: nil)!
|
||||||
}
|
}
|
||||||
|
|
||||||
public var ic_close_article: UIImage {
|
public var ic_close_article: UIImage {
|
||||||
UIImage(named: "ic_close_article")!
|
UIImage(named: "ic_close_article", in: Bundle.main, with: nil)!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ fileprivate let kStringsFileName = "sampleStrings"
|
|||||||
|
|
||||||
extension String {
|
extension String {
|
||||||
|
|
||||||
internal enum KeyGenAllScript: String {
|
public enum KeyGenAllScript: String {
|
||||||
case param_lang = "param_lang"
|
case param_lang = "param_lang"
|
||||||
case generic_back = "generic_back"
|
case generic_back = "generic_back"
|
||||||
case generic_loading_data = "generic_loading_data"
|
case generic_loading_data = "generic_loading_data"
|
||||||
@@ -14,7 +14,7 @@ extension String {
|
|||||||
case test_equal_symbol = "test_equal_symbol"
|
case test_equal_symbol = "test_equal_symbol"
|
||||||
case placeholders_test_one = "placeholders_test_one"
|
case placeholders_test_one = "placeholders_test_one"
|
||||||
|
|
||||||
internal var keyPath: KeyPath<String, String> {
|
public var keyPath: KeyPath<String, String> {
|
||||||
switch self {
|
switch self {
|
||||||
case .param_lang: return \String.param_lang
|
case .param_lang: return \String.param_lang
|
||||||
case .generic_back: return \String.generic_back
|
case .generic_back: return \String.generic_back
|
||||||
@@ -33,7 +33,7 @@ extension String {
|
|||||||
///
|
///
|
||||||
/// Comment :
|
/// Comment :
|
||||||
/// No comment
|
/// No comment
|
||||||
internal var param_lang: String {
|
public var param_lang: String {
|
||||||
NSLocalizedString("param_lang", tableName: kStringsFileName, bundle: Bundle.main, value: "en", comment: "")
|
NSLocalizedString("param_lang", tableName: kStringsFileName, bundle: Bundle.main, value: "en", comment: "")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,7 +44,7 @@ extension String {
|
|||||||
///
|
///
|
||||||
/// Comment :
|
/// Comment :
|
||||||
/// No comment
|
/// No comment
|
||||||
internal var generic_back: String {
|
public var generic_back: String {
|
||||||
NSLocalizedString("generic_back", tableName: kStringsFileName, bundle: Bundle.main, value: "Back", comment: "")
|
NSLocalizedString("generic_back", tableName: kStringsFileName, bundle: Bundle.main, value: "Back", comment: "")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,7 +53,7 @@ extension String {
|
|||||||
///
|
///
|
||||||
/// Comment :
|
/// Comment :
|
||||||
/// No comment
|
/// No comment
|
||||||
internal var generic_loading_data: String {
|
public var generic_loading_data: String {
|
||||||
NSLocalizedString("generic_loading_data", tableName: kStringsFileName, bundle: Bundle.main, value: "Loading\ndata...", comment: "")
|
NSLocalizedString("generic_loading_data", tableName: kStringsFileName, bundle: Bundle.main, value: "Loading\ndata...", comment: "")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,7 +62,7 @@ extension String {
|
|||||||
///
|
///
|
||||||
/// Comment :
|
/// Comment :
|
||||||
/// No comment
|
/// No comment
|
||||||
internal var generic_welcome_firstname_format: String {
|
public var generic_welcome_firstname_format: String {
|
||||||
NSLocalizedString("generic_welcome_firstname_format", tableName: kStringsFileName, bundle: Bundle.main, value: "Welcome \"%@\" !", comment: "")
|
NSLocalizedString("generic_welcome_firstname_format", tableName: kStringsFileName, bundle: Bundle.main, value: "Welcome \"%@\" !", comment: "")
|
||||||
}
|
}
|
||||||
/// Translation in en :
|
/// Translation in en :
|
||||||
@@ -70,7 +70,7 @@ extension String {
|
|||||||
///
|
///
|
||||||
/// Comment :
|
/// Comment :
|
||||||
/// No comment
|
/// No comment
|
||||||
internal func generic_welcome_firstname_format(arg0: String) -> String {
|
public func generic_welcome_firstname_format(arg0: String) -> String {
|
||||||
String(format: self.generic_welcome_firstname_format, arg0)
|
String(format: self.generic_welcome_firstname_format, arg0)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,7 +81,7 @@ extension String {
|
|||||||
///
|
///
|
||||||
/// Comment :
|
/// Comment :
|
||||||
/// No comment
|
/// No comment
|
||||||
internal var test_equal_symbol: String {
|
public var test_equal_symbol: String {
|
||||||
NSLocalizedString("test_equal_symbol", tableName: kStringsFileName, bundle: Bundle.main, value: "1€ = 1 point !", comment: "")
|
NSLocalizedString("test_equal_symbol", tableName: kStringsFileName, bundle: Bundle.main, value: "1€ = 1 point !", comment: "")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,7 +92,7 @@ extension String {
|
|||||||
///
|
///
|
||||||
/// Comment :
|
/// Comment :
|
||||||
/// No comment
|
/// No comment
|
||||||
internal var placeholders_test_one: String {
|
public var placeholders_test_one: String {
|
||||||
NSLocalizedString("placeholders_test_one", tableName: kStringsFileName, bundle: Bundle.main, value: "You %%: %2$@ %1$@ Age: %3$d", comment: "")
|
NSLocalizedString("placeholders_test_one", tableName: kStringsFileName, bundle: Bundle.main, value: "You %%: %2$@ %1$@ Age: %3$d", comment: "")
|
||||||
}
|
}
|
||||||
/// Translation in en :
|
/// Translation in en :
|
||||||
@@ -100,7 +100,7 @@ extension String {
|
|||||||
///
|
///
|
||||||
/// Comment :
|
/// Comment :
|
||||||
/// No comment
|
/// No comment
|
||||||
internal func placeholders_test_one(arg0: String, arg1: String, arg2: Int) -> String {
|
public func placeholders_test_one(arg0: String, arg1: String, arg2: Int) -> String {
|
||||||
String(format: self.placeholders_test_one, arg0, arg1, arg2)
|
String(format: self.placeholders_test_one, arg0, arg1, arg2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
// Generated by ResgenSwift.Analytics 2.2.0
|
// Generated by ResgenSwift.Analytics 2.2.0
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
import MatomoTracker
|
||||||
import FirebaseAnalytics
|
import FirebaseAnalytics
|
||||||
import os
|
import os
|
||||||
|
|
||||||
@@ -24,6 +25,72 @@ internal protocol AnalyticsManagerProtocol {
|
|||||||
func setEnable(_ enable: Bool)
|
func setEnable(_ enable: Bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MARK: - Matomo
|
||||||
|
|
||||||
|
class MatomoAnalyticsManager: AnalyticsManagerProtocol {
|
||||||
|
|
||||||
|
// MARK: - Properties
|
||||||
|
|
||||||
|
private var tracker: MatomoTracker
|
||||||
|
|
||||||
|
// MARK: - Init
|
||||||
|
|
||||||
|
init(siteId: String, url: String) {
|
||||||
|
debugPrint("[Matomo service] Server URL: \(url)")
|
||||||
|
debugPrint("[Matomo service] Site ID: \(siteId)")
|
||||||
|
tracker = MatomoTracker(
|
||||||
|
siteId: siteId,
|
||||||
|
baseURL: URL(string: url)!
|
||||||
|
)
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
tracker.dispatchInterval = 5
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
tracker.logger = DefaultLogger(minLevel: .verbose)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
debugPrint("[Matomo service] Configured with content base: \(tracker.contentBase?.absoluteString ?? "-")")
|
||||||
|
debugPrint("[Matomo service] Opt out: \(tracker.isOptedOut)")
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: - Methods
|
||||||
|
|
||||||
|
func logScreen(
|
||||||
|
name: String,
|
||||||
|
path: String,
|
||||||
|
params: [String: Any]?
|
||||||
|
) {
|
||||||
|
guard let trackerUrl = tracker.contentBase?.absoluteString else { return }
|
||||||
|
|
||||||
|
let urlString = URL(string: "\(trackerUrl)" + "/" + "\(path)" + "yolo"
|
||||||
|
tracker.track(
|
||||||
|
view: [name],
|
||||||
|
url: urlString
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func logEvent(
|
||||||
|
name: String,
|
||||||
|
action: String,
|
||||||
|
category: String,
|
||||||
|
params: [String: Any]?
|
||||||
|
) {
|
||||||
|
tracker.track(
|
||||||
|
eventWithCategory: category,
|
||||||
|
action: action,
|
||||||
|
name: name,
|
||||||
|
number: nil,
|
||||||
|
url: nil
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func setEnable(_ enable: Bool) {
|
||||||
|
tracker.isOptedOut = !enable
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: - Firebase
|
// MARK: - Firebase
|
||||||
|
|
||||||
class FirebaseAnalyticsManager: AnalyticsManagerProtocol {
|
class FirebaseAnalyticsManager: AnalyticsManagerProtocol {
|
||||||
@@ -40,7 +107,7 @@ class FirebaseAnalyticsManager: AnalyticsManagerProtocol {
|
|||||||
]
|
]
|
||||||
|
|
||||||
if path.isEmpty == false {
|
if path.isEmpty == false {
|
||||||
parameters["path"] = path + "/iOS" as NSObject
|
parameters["path"] = path + "/yolo" as NSObject
|
||||||
}
|
}
|
||||||
|
|
||||||
if let supplementaryParameters = params {
|
if let supplementaryParameters = params {
|
||||||
@@ -106,6 +173,7 @@ class FirebaseAnalyticsManager: AnalyticsManagerProtocol {
|
|||||||
|
|
||||||
internal enum TrackerType: CaseIterable {
|
internal enum TrackerType: CaseIterable {
|
||||||
|
|
||||||
|
case matomo
|
||||||
case firebase
|
case firebase
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,6 +181,7 @@ internal enum TrackerType: CaseIterable {
|
|||||||
|
|
||||||
internal class AnalyticsManager {
|
internal class AnalyticsManager {
|
||||||
|
|
||||||
|
@MainActor
|
||||||
internal static var shared = AnalyticsManager()
|
internal static var shared = AnalyticsManager()
|
||||||
|
|
||||||
private init() {}
|
private init() {}
|
||||||
@@ -153,8 +222,12 @@ internal class AnalyticsManager {
|
|||||||
setAnalytics(enable: false, analytics)
|
setAnalytics(enable: false, analytics)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal func configure(isDebugMode: Bool = false) {
|
internal func configure(siteId: String, url: String, isDebugMode: Bool = false) {
|
||||||
self.isDebugMode = isDebugMode
|
self.isDebugMode = isDebugMode
|
||||||
|
managers[TrackerType.matomo] = MatomoAnalyticsManager(
|
||||||
|
siteId: siteId,
|
||||||
|
url: url
|
||||||
|
)
|
||||||
managers[TrackerType.firebase] = FirebaseAnalyticsManager()
|
managers[TrackerType.firebase] = FirebaseAnalyticsManager()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -162,12 +235,12 @@ internal class AnalyticsManager {
|
|||||||
|
|
||||||
private func formattedParams(_ params: [String: Any]?) -> String {
|
private func formattedParams(_ params: [String: Any]?) -> String {
|
||||||
guard let params = params, !params.isEmpty else { return "-" }
|
guard let params = params, !params.isEmpty else { return "-" }
|
||||||
|
|
||||||
let formattedParams = params.map { key, value in
|
let formattedParams = params.map { key, value in
|
||||||
" \(key): \(value)"
|
" \(key): \(value)"
|
||||||
}
|
}
|
||||||
.joined(separator: "\n")
|
.joined(separator: "\n")
|
||||||
|
|
||||||
return "\n" + formattedParams
|
return "\n" + formattedParams
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -180,11 +253,11 @@ internal class AnalyticsManager {
|
|||||||
if isDebugMode {
|
if isDebugMode {
|
||||||
logger.log("Analytics disabled")
|
logger.log("Analytics disabled")
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
managers.values.forEach { manager in
|
managers.values.forEach { manager in
|
||||||
|
|
||||||
if isDebugMode {
|
if isDebugMode {
|
||||||
logger.debug("""
|
logger.debug("""
|
||||||
🖥️ Screen:
|
🖥️ Screen:
|
||||||
@@ -212,11 +285,11 @@ internal class AnalyticsManager {
|
|||||||
if isDebugMode {
|
if isDebugMode {
|
||||||
logger.log("Analytics disabled")
|
logger.log("Analytics disabled")
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
managers.values.forEach { manager in
|
managers.values.forEach { manager in
|
||||||
|
|
||||||
if isDebugMode {
|
if isDebugMode {
|
||||||
logger.debug("""
|
logger.debug("""
|
||||||
📊 Event:
|
📊 Event:
|
||||||
@@ -269,7 +342,7 @@ internal class AnalyticsManager {
|
|||||||
internal func logScreenS2DefOne() {
|
internal func logScreenS2DefOne() {
|
||||||
logScreen(
|
logScreen(
|
||||||
name: "s2 def one",
|
name: "s2 def one",
|
||||||
path: "s2_def_one/",
|
path: "s2_def_one",
|
||||||
params: nil
|
params: nil
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
29
SampleFiles/Tags/R.swift
Normal file
29
SampleFiles/Tags/R.swift
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
// Generated by ResgenSwift.Generate 2.2.0
|
||||||
|
|
||||||
|
class R: Sendable {
|
||||||
|
static let images = R2Image()
|
||||||
|
static let strings = R2String()
|
||||||
|
static let fonts = R2Font()
|
||||||
|
static let images = R2Image()
|
||||||
|
static let ui = R2UI()
|
||||||
|
}
|
||||||
|
|
||||||
|
final class R2Image: Sendable {}
|
||||||
|
|
||||||
|
final class R2String: Sendable {}
|
||||||
|
|
||||||
|
final class R2Font: Sendable {}
|
||||||
|
|
||||||
|
final class R2Image: Sendable {}
|
||||||
|
|
||||||
|
class R2UI: Sendable {
|
||||||
|
let images = R2UIImage()
|
||||||
|
let fonts = R2UIFont()
|
||||||
|
let images = R2UIImage()
|
||||||
|
}
|
||||||
|
|
||||||
|
final class R2UIImage: Sendable {}
|
||||||
|
|
||||||
|
final class R2UIFont: Sendable {}
|
||||||
|
|
||||||
|
final class R2UIImage: Sendable {}
|
||||||
@@ -33,7 +33,7 @@ categories:
|
|||||||
screens:
|
screens:
|
||||||
- id: s2_def_one
|
- id: s2_def_one
|
||||||
name: s2 def one
|
name: s2 def one
|
||||||
path: s2_def_one/
|
path: s2_def_one///
|
||||||
tags: ios
|
tags: ios
|
||||||
|
|
||||||
events:
|
events:
|
||||||
|
|||||||
@@ -54,8 +54,9 @@ FORCE_FLAG="$1"
|
|||||||
#
|
#
|
||||||
## Analytics
|
## Analytics
|
||||||
swift run -c release ResgenSwift analytics -f "./Tags/sampleTags.yml" \
|
swift run -c release ResgenSwift analytics -f "./Tags/sampleTags.yml" \
|
||||||
--target "firebase" \
|
--target "firebase matomo" \
|
||||||
--output-file "./Tags/Generated/Analytics+GenAllScript.swift"
|
--output-file "./Tags/Generated/Analytics+GenAllScript.swift" \
|
||||||
|
--path-suffix "sampleApp"
|
||||||
#
|
#
|
||||||
#echo "\n-------------------------\n"
|
#echo "\n-------------------------\n"
|
||||||
#
|
#
|
||||||
|
|||||||
@@ -91,6 +91,7 @@ analytics:
|
|||||||
target: "matomo firebase"
|
target: "matomo firebase"
|
||||||
outputFile: ./Tags/Generated/Analytics+GenAllScript.swift
|
outputFile: ./Tags/Generated/Analytics+GenAllScript.swift
|
||||||
visibility: internal
|
visibility: internal
|
||||||
|
pathSuffix: "yolo"
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|||||||
@@ -39,7 +39,10 @@ struct Analytics: ParsableCommand {
|
|||||||
print("[\(Self.toolName)] Will generate analytics")
|
print("[\(Self.toolName)] Will generate analytics")
|
||||||
|
|
||||||
// Parse input file
|
// Parse input file
|
||||||
let sections = AnalyticsFileParser().parse(options.inputFile, target: options.target)
|
let sections = AnalyticsFileParser().parse(
|
||||||
|
options.inputFile,
|
||||||
|
target: options.target
|
||||||
|
)
|
||||||
|
|
||||||
// Generate extension
|
// Generate extension
|
||||||
AnalyticsGenerator.writeExtensionFiles(
|
AnalyticsGenerator.writeExtensionFiles(
|
||||||
@@ -48,7 +51,8 @@ struct Analytics: ParsableCommand {
|
|||||||
tags: ["ios", "iosonly"],
|
tags: ["ios", "iosonly"],
|
||||||
isStatic: options.staticMembers,
|
isStatic: options.staticMembers,
|
||||||
outputFile: options.outputFile,
|
outputFile: options.outputFile,
|
||||||
visibility: options.extensionVisibility
|
visibility: options.extensionVisibility,
|
||||||
|
pathSuffix: options.pathSuffix
|
||||||
)
|
)
|
||||||
|
|
||||||
print("[\(Self.toolName)] Analytics generated")
|
print("[\(Self.toolName)] Analytics generated")
|
||||||
|
|||||||
@@ -44,4 +44,9 @@ struct AnalyticsOptions: ParsableArguments {
|
|||||||
completion: .list(["public", "private", "package", "internal"])
|
completion: .list(["public", "private", "package", "internal"])
|
||||||
)
|
)
|
||||||
var extensionVisibility: ExtensionVisibility = .internal
|
var extensionVisibility: ExtensionVisibility = .internal
|
||||||
|
|
||||||
|
@Option(
|
||||||
|
help: "Suffix to add to every path parameters. Default is 'iOS'."
|
||||||
|
)
|
||||||
|
var pathSuffix: String = "iOS"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,8 @@ enum AnalyticsGenerator {
|
|||||||
tags: [String],
|
tags: [String],
|
||||||
isStatic: Bool,
|
isStatic: Bool,
|
||||||
outputFile: String,
|
outputFile: String,
|
||||||
visibility: ExtensionVisibility
|
visibility: ExtensionVisibility,
|
||||||
|
pathSuffix: String
|
||||||
) {
|
) {
|
||||||
// Get target type from enum
|
// Get target type from enum
|
||||||
let targetsString: [String] = target.components(separatedBy: " ")
|
let targetsString: [String] = target.components(separatedBy: " ")
|
||||||
@@ -44,7 +45,8 @@ enum AnalyticsGenerator {
|
|||||||
sections: sections,
|
sections: sections,
|
||||||
tags: tags,
|
tags: tags,
|
||||||
isStatic: isStatic,
|
isStatic: isStatic,
|
||||||
visibility: visibility
|
visibility: visibility,
|
||||||
|
pathSuffix: pathSuffix
|
||||||
)
|
)
|
||||||
|
|
||||||
// Write content
|
// Write content
|
||||||
@@ -65,13 +67,15 @@ enum AnalyticsGenerator {
|
|||||||
sections: [AnalyticsCategory],
|
sections: [AnalyticsCategory],
|
||||||
tags: [String],
|
tags: [String],
|
||||||
isStatic: Bool,
|
isStatic: Bool,
|
||||||
visibility: ExtensionVisibility
|
visibility: ExtensionVisibility,
|
||||||
|
pathSuffix: String
|
||||||
) -> String {
|
) -> String {
|
||||||
[
|
[
|
||||||
getHeader(
|
getHeader(
|
||||||
targets: targets,
|
targets: targets,
|
||||||
isStatic: isStatic,
|
isStatic: isStatic,
|
||||||
visibility: visibility
|
visibility: visibility,
|
||||||
|
pathSuffix: pathSuffix
|
||||||
),
|
),
|
||||||
getProperties(
|
getProperties(
|
||||||
sections: sections,
|
sections: sections,
|
||||||
@@ -89,14 +93,15 @@ enum AnalyticsGenerator {
|
|||||||
private static func getHeader(
|
private static func getHeader(
|
||||||
targets: [TrackerType],
|
targets: [TrackerType],
|
||||||
isStatic: Bool,
|
isStatic: Bool,
|
||||||
visibility: ExtensionVisibility
|
visibility: ExtensionVisibility,
|
||||||
|
pathSuffix: String
|
||||||
) -> String {
|
) -> String {
|
||||||
"""
|
"""
|
||||||
// Generated by ResgenSwift.\(Analytics.toolName) \(ResgenSwiftVersion)
|
// Generated by ResgenSwift.\(Analytics.toolName) \(ResgenSwiftVersion)
|
||||||
|
|
||||||
\(Self.getImport(targets: targets))
|
\(Self.getImport(targets: targets))
|
||||||
|
|
||||||
\(Self.getAnalyticsProtocol(targets: targets, visibility: visibility))
|
\(Self.getAnalyticsProtocol(targets: targets, visibility: visibility, pathSuffix: pathSuffix))
|
||||||
|
|
||||||
\(Self.getTrackerTypeEnum(targets: targets, visibility: visibility))
|
\(Self.getTrackerTypeEnum(targets: targets, visibility: visibility))
|
||||||
|
|
||||||
@@ -317,7 +322,8 @@ enum AnalyticsGenerator {
|
|||||||
|
|
||||||
private static func getAnalyticsProtocol(
|
private static func getAnalyticsProtocol(
|
||||||
targets: [TrackerType],
|
targets: [TrackerType],
|
||||||
visibility: ExtensionVisibility
|
visibility: ExtensionVisibility,
|
||||||
|
pathSuffix: String
|
||||||
) -> String {
|
) -> String {
|
||||||
let proto = """
|
let proto = """
|
||||||
// MARK: - Protocol
|
// MARK: - Protocol
|
||||||
@@ -344,11 +350,11 @@ enum AnalyticsGenerator {
|
|||||||
var result: [String] = [proto]
|
var result: [String] = [proto]
|
||||||
|
|
||||||
if targets.contains(TrackerType.matomo) {
|
if targets.contains(TrackerType.matomo) {
|
||||||
result.append(MatomoGenerator.service)
|
result.append(MatomoGenerator.service(pathSuffix: pathSuffix))
|
||||||
}
|
}
|
||||||
|
|
||||||
if targets.contains(TrackerType.firebase) {
|
if targets.contains(TrackerType.firebase) {
|
||||||
result.append(FirebaseGenerator.service)
|
result.append(FirebaseGenerator.service(pathSuffix: pathSuffix))
|
||||||
}
|
}
|
||||||
|
|
||||||
return result.joined(separator: "\n\n")
|
return result.joined(separator: "\n\n")
|
||||||
|
|||||||
@@ -11,10 +11,10 @@ import Foundation
|
|||||||
|
|
||||||
enum FirebaseGenerator {
|
enum FirebaseGenerator {
|
||||||
|
|
||||||
static var service: String {
|
static func service(pathSuffix: String) -> String {
|
||||||
[
|
[
|
||||||
Self.header,
|
Self.header,
|
||||||
Self.logScreen,
|
Self.logScreen(pathSuffix: pathSuffix),
|
||||||
Self.logEvent,
|
Self.logEvent,
|
||||||
Self.enable,
|
Self.enable,
|
||||||
Self.footer
|
Self.footer
|
||||||
@@ -35,8 +35,14 @@ enum FirebaseGenerator {
|
|||||||
"""
|
"""
|
||||||
}
|
}
|
||||||
|
|
||||||
private static var logScreen: String {
|
private static func logScreen(pathSuffix: String) -> String {
|
||||||
"""
|
let pathSuffixCode: String = if pathSuffix.isEmpty == false {
|
||||||
|
" + \"/\(pathSuffix)\""
|
||||||
|
} else {
|
||||||
|
""
|
||||||
|
}
|
||||||
|
|
||||||
|
return """
|
||||||
func logScreen(
|
func logScreen(
|
||||||
name: String,
|
name: String,
|
||||||
path: String,
|
path: String,
|
||||||
@@ -47,7 +53,7 @@ enum FirebaseGenerator {
|
|||||||
]
|
]
|
||||||
|
|
||||||
if path.isEmpty == false {
|
if path.isEmpty == false {
|
||||||
parameters["path"] = path + "/iOS" as NSObject
|
parameters["path"] = path\(pathSuffixCode) as NSObject
|
||||||
}
|
}
|
||||||
|
|
||||||
if let supplementaryParameters = params {
|
if let supplementaryParameters = params {
|
||||||
|
|||||||
@@ -11,11 +11,11 @@ import Foundation
|
|||||||
|
|
||||||
enum MatomoGenerator {
|
enum MatomoGenerator {
|
||||||
|
|
||||||
static var service: String {
|
static func service(pathSuffix: String) -> String {
|
||||||
[
|
[
|
||||||
Self.header,
|
Self.header,
|
||||||
Self.setup,
|
Self.setup,
|
||||||
Self.logScreen,
|
Self.logScreen(pathSuffix: pathSuffix),
|
||||||
Self.logEvent,
|
Self.logEvent,
|
||||||
Self.enable,
|
Self.enable,
|
||||||
Self.footer
|
Self.footer
|
||||||
@@ -67,8 +67,14 @@ enum MatomoGenerator {
|
|||||||
"""
|
"""
|
||||||
}
|
}
|
||||||
|
|
||||||
private static var logScreen: String {
|
private static func logScreen(pathSuffix: String) -> String {
|
||||||
"""
|
let pathSuffixCode: String = if pathSuffix.isEmpty == false {
|
||||||
|
" + \"/\(pathSuffix)\""
|
||||||
|
} else {
|
||||||
|
""
|
||||||
|
}
|
||||||
|
|
||||||
|
return """
|
||||||
func logScreen(
|
func logScreen(
|
||||||
name: String,
|
name: String,
|
||||||
path: String,
|
path: String,
|
||||||
@@ -76,7 +82,7 @@ enum MatomoGenerator {
|
|||||||
) {
|
) {
|
||||||
guard let trackerUrl = tracker.contentBase?.absoluteString else { return }
|
guard let trackerUrl = tracker.contentBase?.absoluteString else { return }
|
||||||
|
|
||||||
let urlString = URL(string: "\\(trackerUrl)" + "/" + "\\(path)" + "iOS")
|
let urlString = URL(string: "\\(trackerUrl)" + "/" + "\\(path)"\(pathSuffixCode)
|
||||||
tracker.track(
|
tracker.track(
|
||||||
view: [name],
|
view: [name],
|
||||||
url: urlString
|
url: urlString
|
||||||
|
|||||||
@@ -169,7 +169,6 @@ class AnalyticsFileParser {
|
|||||||
|
|
||||||
if target.contains(TrackerType.matomo.value) {
|
if target.contains(TrackerType.matomo.value) {
|
||||||
// Path
|
// Path
|
||||||
|
|
||||||
guard let path = screen.path else {
|
guard let path = screen.path else {
|
||||||
let error = AnalyticsError.missingElement("screen path")
|
let error = AnalyticsError.missingElement("screen path")
|
||||||
print(error.description)
|
print(error.description)
|
||||||
@@ -181,6 +180,10 @@ class AnalyticsFileParser {
|
|||||||
definition.path = path
|
definition.path = path
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while definition.path.last == "/" {
|
||||||
|
definition.path = String(definition.path.dropLast())
|
||||||
|
}
|
||||||
|
|
||||||
return definition
|
return definition
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,19 +89,22 @@ struct AnalyticsConfiguration: Codable, CustomDebugStringConvertible {
|
|||||||
let outputFile: String
|
let outputFile: String
|
||||||
let visibility: String?
|
let visibility: String?
|
||||||
let staticMembers: Bool?
|
let staticMembers: Bool?
|
||||||
|
let pathSuffix: String?
|
||||||
|
|
||||||
internal init(
|
internal init(
|
||||||
inputFile: String,
|
inputFile: String,
|
||||||
target: String,
|
target: String,
|
||||||
outputFile: String,
|
outputFile: String,
|
||||||
visibility: String?,
|
visibility: String?,
|
||||||
staticMembers: Bool?
|
staticMembers: Bool?,
|
||||||
|
pathSuffix: String?
|
||||||
) {
|
) {
|
||||||
self.inputFile = inputFile
|
self.inputFile = inputFile
|
||||||
self.target = target
|
self.target = target
|
||||||
self.outputFile = outputFile
|
self.outputFile = outputFile
|
||||||
self.visibility = visibility
|
self.visibility = visibility
|
||||||
self.staticMembers = staticMembers
|
self.staticMembers = staticMembers
|
||||||
|
self.pathSuffix = pathSuffix
|
||||||
}
|
}
|
||||||
|
|
||||||
var debugDescription: String {
|
var debugDescription: String {
|
||||||
@@ -112,6 +115,7 @@ struct AnalyticsConfiguration: Codable, CustomDebugStringConvertible {
|
|||||||
- Output file: \(outputFile)
|
- Output file: \(outputFile)
|
||||||
- Visiblity: \(visibility ?? "default")
|
- Visiblity: \(visibility ?? "default")
|
||||||
- Static members: \(staticMembers != nil ? "\(String(describing: staticMembers))" : "default")
|
- Static members: \(staticMembers != nil ? "\(String(describing: staticMembers))" : "default")
|
||||||
|
- Path suffix: \(pathSuffix != nil ? "\(String(describing: pathSuffix))" : "default")
|
||||||
"""
|
"""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,8 @@ extension AnalyticsConfiguration: Runnable {
|
|||||||
// Add optional parameters
|
// Add optional parameters
|
||||||
[
|
[
|
||||||
("--visibility", visibility),
|
("--visibility", visibility),
|
||||||
("--static-members", staticMembers?.description)
|
("--static-members", staticMembers?.description),
|
||||||
|
("--path-suffix", pathSuffix)
|
||||||
].forEach { argumentName, argumentValue in
|
].forEach { argumentName, argumentValue in
|
||||||
if let argumentValue {
|
if let argumentValue {
|
||||||
args += [
|
args += [
|
||||||
|
|||||||
@@ -234,7 +234,8 @@ final class AnalyticsGeneratorTests: XCTestCase {
|
|||||||
sections: [sectionOne, sectionTwo, sectionThree],
|
sections: [sectionOne, sectionTwo, sectionThree],
|
||||||
tags: ["ios", "iosonly"],
|
tags: ["ios", "iosonly"],
|
||||||
isStatic: false,
|
isStatic: false,
|
||||||
visibility: .internal
|
visibility: .internal,
|
||||||
|
pathSuffix: "iOS"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Expect Analytics
|
// Expect Analytics
|
||||||
@@ -448,7 +449,8 @@ final class AnalyticsGeneratorTests: XCTestCase {
|
|||||||
sections: [sectionOne, sectionTwo, sectionThree],
|
sections: [sectionOne, sectionTwo, sectionThree],
|
||||||
tags: ["ios", "iosonly"],
|
tags: ["ios", "iosonly"],
|
||||||
isStatic: false,
|
isStatic: false,
|
||||||
visibility: .internal
|
visibility: .internal,
|
||||||
|
pathSuffix: "iOS"
|
||||||
)
|
)
|
||||||
// Expect Analytics
|
// Expect Analytics
|
||||||
let expect = """
|
let expect = """
|
||||||
@@ -664,7 +666,8 @@ final class AnalyticsGeneratorTests: XCTestCase {
|
|||||||
sections: [sectionOne, sectionTwo, sectionThree],
|
sections: [sectionOne, sectionTwo, sectionThree],
|
||||||
tags: ["ios", "iosonly"],
|
tags: ["ios", "iosonly"],
|
||||||
isStatic: false,
|
isStatic: false,
|
||||||
visibility: .internal
|
visibility: .internal,
|
||||||
|
pathSuffix: "iOS"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Expect Analytics
|
// Expect Analytics
|
||||||
|
|||||||
@@ -20,7 +20,8 @@ final class AnalyticsConfigurationTests: XCTestCase {
|
|||||||
target: "matomo firebase",
|
target: "matomo firebase",
|
||||||
outputFile: "Analytics/Generated/AnalyticsManager.swift",
|
outputFile: "Analytics/Generated/AnalyticsManager.swift",
|
||||||
visibility: nil,
|
visibility: nil,
|
||||||
staticMembers: nil
|
staticMembers: nil,
|
||||||
|
pathSuffix: nil
|
||||||
)
|
)
|
||||||
|
|
||||||
// When
|
// When
|
||||||
@@ -48,7 +49,8 @@ final class AnalyticsConfigurationTests: XCTestCase {
|
|||||||
target: "matomo firebase",
|
target: "matomo firebase",
|
||||||
outputFile: "Analytics/Generated/AnalyticsManager.swift",
|
outputFile: "Analytics/Generated/AnalyticsManager.swift",
|
||||||
visibility: "public",
|
visibility: "public",
|
||||||
staticMembers: false
|
staticMembers: false,
|
||||||
|
pathSuffix: "mySuffix"
|
||||||
)
|
)
|
||||||
|
|
||||||
// When
|
// When
|
||||||
@@ -68,7 +70,9 @@ final class AnalyticsConfigurationTests: XCTestCase {
|
|||||||
"--visibility",
|
"--visibility",
|
||||||
"public",
|
"public",
|
||||||
"--static-members",
|
"--static-members",
|
||||||
"false"
|
"false",
|
||||||
|
"--path-suffix",
|
||||||
|
"mySuffix"
|
||||||
]
|
]
|
||||||
|
|
||||||
XCTAssertEqual(arguments, expectedArguments)
|
XCTAssertEqual(arguments, expectedArguments)
|
||||||
|
|||||||
Reference in New Issue
Block a user