Compare commits

...

4 Commits

Author SHA1 Message Date
504f006345 Update README.md
Some checks failed
gitea-openium/resgen.swift/pipeline/pr-master There was a failure building this commit
2024-03-08 09:57:43 +01:00
c9ea8ef9db Update Jenkinsfile
Some checks failed
gitea-openium/resgen.swift/pipeline/head There was a failure building this commit
2024-03-07 16:37:32 +01:00
950d6ec8a6 fix: Static function
Some checks failed
gitea-openium/resgen.swift/pipeline/head There was a failure building this commit
2024-03-07 16:31:26 +01:00
e4ada4b543 fix: Use category and action if not matomo
Some checks failed
gitea-openium/resgen.swift/pipeline/head There was a failure building this commit
2024-03-07 16:08:21 +01:00
7 changed files with 55 additions and 85 deletions

2
Jenkinsfile vendored
View File

@ -1,6 +1,6 @@
library "openiumpipeline"
env.DEVELOPER_DIR="/Applications/Xcode-15.0.1.app/Contents/Developer"
env.DEVELOPER_DIR="/Applications/Xcode-15.2.0.app/Contents/Developer"
//env.SIMULATOR_DEVICE_TYPES="iPad--7th-generation-"
env.IS_PACKAGE_SWIFT=1
env.TARGETS_MACOS=1

View File

@ -131,7 +131,7 @@ swift run -c release ResgenSwift strings tags $FORCE_FLAG "./Tags/tags.txt" \
6. `--extension-suffix` *(optional)* : additional text which is added to filename (ex: `AppTags+GreatApp.swift`)
7. `--static-members` *(optional)*: generate static properties or not
> ⚠️ If extension name is not set or is `Tags`, it will generate the following typaloas `typealias Tags = String`.
> ⚠️ If extension name is not set or is `Tags`, it will generate the following typealias `typealias Tags = String`.
## Analytics
@ -139,7 +139,7 @@ swift run -c release ResgenSwift strings tags $FORCE_FLAG "./Tags/tags.txt" \
Analytics will generate all you need to analyze UX with Matomo or Firebase Analytics. Input files are formatted in YAML. This command will generate a manager for each target and an AnalyticsManager. This is this one you will need to use. And it will generate a method for all tags you have declared in the YAML file. Next, you will need to use the `configure()` method of AnalyticsManager and if you want to use matomo to set up the `siteId` and the `url` of the site.
```sh
swift run -c release ResgenSwift strings tags $FORCE_FLAG "./Tags/tags.txt" \
swift run -c release ResgenSwift analytics $FORCE_FLAG "./Tags/analytics.yml" \
--target "matomo firebase" \
--extension-output-path "./Analytics/Generated" \
--extension-name "AppAnalytics" \
@ -157,7 +157,7 @@ swift run -c release ResgenSwift strings tags $FORCE_FLAG "./Tags/tags.txt" \
6. `--extension-suffix` *(optional)* : additional text which is added to filename (ex: `AppAnalytics+GreatApp.swift`)
7. `--static-members` *(optional)*: generate static properties or not
> ⚠️ If extension name is not set or is `Analytics`, it will generate the following typaloas `typealias Analytics = String`.
> ⚠️ If extension name is not set or is `Analytics`, it will generate the following typealias `typealias Analytics = String`.
### YAML
@ -184,7 +184,7 @@ swift run -c release ResgenSwift strings tags $FORCE_FLAG "./Tags/tags.txt" \
7. `comments` *(optional)*
8. `parameters` *(optional)*
**Parameters**
**Parameters**
You can use parameters in generate methods.
@ -197,6 +197,24 @@ You can use parameters in generate methods.
This is section is equivalent of `%s | %d | %f | %@`. You can put the content of the parameter in *name*, *path*, *action*, *category*.
You need to put `_` + `NAME OF THE PARAMETER` + `_` in the target and which target you want in the value of `replaceIn`. (name need to be in uppercase)
Example:
```
events:
id: id_of_tag
name: _TITLE_
tags: ios,droid
parameters:
- name: title
type: String
replaceIn: name
```
In this sample, we want to add the parameter `title` in the field `name`. So, we need to place `_TITLE_` in the field `name`.
The generated method will be:
```
logIdOfTag(title: String)
```
## Images
@ -284,6 +302,15 @@ tags:
extensionName: String?
extensionSuffix: String?
staticMembers: Bool?
analytics:
-
inputFile: String
target: String
extensionOutputPath: String
extensionName: String?
extensionSuffix: String?
staticMembers: Bool?
```
### Multiple configurations

View File

@ -1,6 +1,5 @@
// Generated by ResgenSwift.Analytics 1.2
import MatomoTracker
import FirebaseAnalytics
// MARK: - Protocol
@ -15,72 +14,11 @@ protocol AnalyticsManagerProtocol {
)
}
// 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) {
guard !tracker.isOptedOut else { return }
guard let trackerUrl = tracker.contentBase?.absoluteString else { return }
let urlString = URL(string: "\(trackerUrl)" + "/" + "\(path)" + "iOS")
tracker.track(
view: [name],
url: urlString
)
}
func logEvent(
name: String,
action: String,
category: String,
params: [String: Any]?
) {
guard !tracker.isOptedOut else { return }
tracker.track(
eventWithCategory: category,
action: action,
name: name,
number: nil,
url: nil
)
}
}
// MARK: - Firebase
class FirebaseAnalyticsManager: AnalyticsManagerProtocol {
func logScreen(name: String, path: String) {
var parameters = [
let parameters = [
AnalyticsParameterScreenName: name as NSObject
]
@ -97,8 +35,9 @@ class FirebaseAnalyticsManager: AnalyticsManagerProtocol {
params: [String: Any]?
) {
var parameters: [String:NSObject] = [
AnalyticsParameterItemName: name.replacingOccurrences(of: " ", with: "_") as NSObject,
AnalyticsParameterItemCategory: category as NSObject,
"action": action as NSObject,
"category": category as NSObject,
]
if let supplementaryParameters = params {
@ -114,7 +53,7 @@ class FirebaseAnalyticsManager: AnalyticsManagerProtocol {
}
Analytics.logEvent(
name.replacingOccurrences(of: [" "], with: "_"),
AnalyticsEventSelectContent,
parameters: parameters
)
}
@ -137,13 +76,7 @@ class AnalyticsManager {
isEnabled = enable
}
func configure(siteId: String, url: String) {
managers.append(
MatomoAnalyticsManager(
siteId: siteId,
url: url
)
)
func configure() {
managers.append(FirebaseAnalyticsManager())
}
@ -178,7 +111,7 @@ class AnalyticsManager {
func logScreenS1DefOne(title: String) {
logScreen(
name: "s1 def one \(title)",
path: "s1_def_one/\(title)"
path: ""
)
}
@ -199,7 +132,7 @@ class AnalyticsManager {
func logScreenS2DefOne() {
logScreen(
name: "s2 def one",
path: "s2_def_one/"
path: ""
)
}
}

View File

@ -54,10 +54,11 @@ FORCE_FLAG="$1"
# Analytics
swift run -c release ResgenSwift analytics $FORCE_FLAG "./Tags/sampleTags.yml" \
--target "matomo firebase" \
--target "firebase" \
--extension-output-path "./Tags/Generated" \
--extension-name "Analytics" \
--extension-suffix "GenAllScript"
--extension-suffix "GenAllScript" \
--static-members true
#echo "\n-------------------------\n"
#

View File

@ -32,7 +32,7 @@ enum FirebaseGenerator {
private static var logScreen: String {
"""
func logScreen(name: String, path: String) {
var parameters = [
let parameters = [
AnalyticsParameterScreenName: name as NSObject
]
@ -54,8 +54,9 @@ enum FirebaseGenerator {
params: [String: Any]?
) {
var parameters: [String:NSObject] = [
AnalyticsParameterItemName: name.replacingOccurrences(of: " ", with: "_") as NSObject,
AnalyticsParameterItemCategory: category as NSObject,
"action": action as NSObject,
"category": category as NSObject,
]
if let supplementaryParameters = params {
@ -71,7 +72,7 @@ enum FirebaseGenerator {
}
Analytics.logEvent(
name.replacingOccurrences(of: [" "], with: "_"),
AnalyticsEventSelectContent,
parameters: parameters
)
}

View File

@ -150,7 +150,7 @@ class AnalyticsDefinition {
replaceIn()
return """
static func \(getFuncName())\(getParameters()) {
\(getlogFunction())
AnalyticsManager.shared.\(getlogFunction())
}
"""
}

View File

@ -139,6 +139,14 @@ class AnalyticsFileParser {
}
definition.action = action
} else {
if let category = event.category {
definition.category = category
}
if let action = event.action {
definition.action = action
}
}
return definition