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

[Product Creation AI] Tracking for M3 #13411

Merged
merged 5 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import WooFoundation

extension WooAnalyticsEvent {
enum ProductCreationAI {
Expand All @@ -10,6 +11,7 @@ extension WooAnalyticsEvent {
case shortDescription = "short_description"
case description
case field
case featureWordCount = "feature_word_count"
}

static func entryPointDisplayed() -> WooAnalyticsEvent {
Expand All @@ -32,9 +34,13 @@ extension WooAnalyticsEvent {
properties: [Key.value.rawValue: tone.rawValue.lowercased()])
}

static func generateDetailsTapped(isFirstAttempt: Bool) -> WooAnalyticsEvent {
WooAnalyticsEvent(statName: .productCreationAIGenerateDetailsTapped,
properties: [Key.isFirstAttempt.rawValue: isFirstAttempt])
static func generateDetailsTapped(isFirstAttempt: Bool,
features: String) -> WooAnalyticsEvent {
let wordCount = features.split { $0 == " " || $0.isNewline }.count
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: this can be simplified using components(separatedBy:):

Suggested change
let wordCount = features.split { $0 == " " || $0.isNewline }.count
let wordCount = features.components(separatedBy: .whitespacesAndNewlines).count

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion, Huong! Done in 2a81f1d

let properties: [String: WooAnalyticsEventPropertyType?] = [Key.isFirstAttempt.rawValue: isFirstAttempt,
Key.featureWordCount.rawValue: wordCount]
return WooAnalyticsEvent(statName: .productCreationAIGenerateDetailsTapped,
properties: properties.compactMapValues { $0 })
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❓ I wonder why the values have to be optional. We can replace WooAnalyticsEventPropertyType? with any WooAnalyticsEventPropertyType instead, right?

Copy link
Contributor Author

@selanthiraiyan selanthiraiyan Jul 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. I earlier kept the features as an optional parameter, and I missed updating it again.

Simplified code in c5aacd4

}

static func generateProductDetailsSuccess() -> WooAnalyticsEvent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ final class AddProductWithAIContainerViewModel: ObservableObject {
}

func onProductFeaturesAdded(features: String) {
analytics.track(event: .ProductCreationAI.generateDetailsTapped(isFirstAttempt: isFirstAttemptGeneratingDetails))
analytics.track(event: .ProductCreationAI.generateDetailsTapped(isFirstAttempt: isFirstAttemptGeneratingDetails,
features: features))
productFeatures = features
currentStep = .preview
isFirstAttemptGeneratingDetails = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,8 @@ final class ProductDetailPreviewViewModel: ObservableObject {
}

func didTapGenerateAgain() {
analytics.track(event: .ProductCreationAI.generateDetailsTapped(isFirstAttempt: false))
analytics.track(event: .ProductCreationAI.generateDetailsTapped(isFirstAttempt: false,
features: productFeatures))
Task { @MainActor in
await generateProductDetails()
}
Expand Down