Skip to content

Commit

Permalink
feat(analytics): append tag name(s) as value to tag events in Save ex…
Browse files Browse the repository at this point in the history
…tension
  • Loading branch information
David Skuza committed Apr 26, 2023
1 parent 3c937c3 commit 12fb233
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 14 deletions.
43 changes: 35 additions & 8 deletions PocketKit/Sources/Analytics/AppEvents/SaveTo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,13 @@ public extension Events.SaveTo.Tags {
}

/// Fired when a user adds tag to an input list in the `Add Tags` screen for an item
static func addTag(itemUrl: URL) -> Event {
/// - Parameters:
/// - tag: The tag added to an item.
/// - itemUrl: The url of the item to which a new tag was added.
static func addTag(_ tag: String, itemUrl: URL) -> Event {
return Engagement(
.general,
value: tag,
uiEntity: UiEntity(
.button,
identifier: "save-extension.addTags.addTag"
Expand All @@ -79,9 +83,13 @@ public extension Events.SaveTo.Tags {
}

/// Fired when user taps on a tag name and removes it from the list of input tags in `Add Tags` screen for an item
static func remoteInputTag(itemUrl: URL) -> Event {
/// - Parameters:
/// - tag: The tag that was removed from the list of input tags.
/// - itemUrl: The url of the item to which a tag was removed.
static func removeInputTag(_ tag: String, itemUrl: URL) -> Event {
return Engagement(
.general,
value: tag,
uiEntity: UiEntity(
.button,
identifier: "save-extension.addTags.removeInputTag"
Expand Down Expand Up @@ -154,9 +162,12 @@ public extension Events.SaveTo.Tags {
}

/// Fired when a user taps on a general tag from `Add Tags` screen
static func selectTagToAddToItem() -> Event {
/// - Parameters:
/// - tag: The tag selected to add to an item.
static func selectTagToAddToItem(_ tag: String) -> Event {
return Engagement(
.general,
value: tag,
uiEntity: UiEntity(
.button,
identifier: "save-extension.addTags.selectTag"
Expand All @@ -165,9 +176,12 @@ public extension Events.SaveTo.Tags {
}

/// Fired when a user taps on a recent tag from `Add Tags` screen
static func selectRecentTagToAddToItem() -> Event {
/// - Parameters:
/// - tag: The recent tag selected to add to an item.
static func selectRecentTagToAddToItem(_ tag: String) -> Event {
return Engagement(
.general,
value: tag,
uiEntity: UiEntity(
.button,
identifier: "save-extension.addTags.selectRecentTag"
Expand All @@ -176,9 +190,12 @@ public extension Events.SaveTo.Tags {
}

/// Fired when a user selects on a general tag using the `Tags` screen after tapping on `Tagged` filter
static func selectTagToFilter() -> Event {
/// - Parameters:
/// - tag: The tag that was selected as the filter.
static func selectTagToFilter(_ tag: String) -> Event {
return Engagement(
.general,
value: tag,
uiEntity: UiEntity(
.button,
identifier: "save-extension.filterTags.selectTag"
Expand All @@ -198,9 +215,12 @@ public extension Events.SaveTo.Tags {
}

/// Fired when a user selects on a recent tag using the `Tags` screen after tapping on `Tagged` filter
static func selectRecentTagToFilter() -> Event {
/// - Parameters:
/// - tag: The recent tag that was selected as the filter.
static func selectRecentTagToFilter(_ tag: String) -> Event {
return Engagement(
.general,
value: tag,
uiEntity: UiEntity(
.button,
identifier: "save-extension.filterTags.selectRecentTag"
Expand All @@ -209,9 +229,13 @@ public extension Events.SaveTo.Tags {
}

/// Fired when a user adds tag to an input list in the `Add Tags` screen for an item
static func renameTag() -> Event {
/// - Parameters:
/// - from: The previous name of the tag before rename.
/// - to: The new name of the tag after rename.
static func renameTag(from oldTag: String, to newTag: String) -> Event {
return Engagement(
.general,
value: [oldTag, newTag].joined(separator: ","),
uiEntity: UiEntity(
.button,
identifier: "save-extension.filterTags.tagRename"
Expand All @@ -220,9 +244,12 @@ public extension Events.SaveTo.Tags {
}

/// Fired when a user confirms to delete tags from 'Tags' screen after tapping on `Tagged` filter
static func deleteTags() -> Event {
/// - Parameters:
/// - tags: An array of tags that were deleted; used to generate a comma-separated string as a value.
static func deleteTags(_ tags: [String]) -> Event {
return Engagement(
.general,
value: tags.joined(separator: ","),
uiEntity: UiEntity(
.button,
identifier: "save-extension.filterTags.tagsDelete"
Expand Down
12 changes: 6 additions & 6 deletions PocketKit/Sources/SaveToPocketKit/SaveToAddTagsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,20 +105,20 @@ extension SaveToAddTagsViewModel {
tracker.track(event: Events.SaveTo.Tags.saveTags(itemUrl: url))
}

func trackAddTag() {
func trackAddTag(_ tag: String) {
guard let url = item?.url else {
Log.capture(message: "Adding tags to an item without an associated url, not logging analytics for Tags.addTag")
return
}
tracker.track(event: Events.SaveTo.Tags.addTag(itemUrl: url))
tracker.track(event: Events.SaveTo.Tags.addTag(tag, itemUrl: url))
}

func trackRemoveTag() {
func trackRemoveTag(_ tag: String) {
guard let url = item?.url else {
Log.capture(message: "Adding tags to an item without an associated url, not logging analytics for Tags.remoteInputTag")
return
}
tracker.track(event: Events.SaveTo.Tags.remoteInputTag(itemUrl: url))
tracker.track(event: Events.SaveTo.Tags.removeInputTag(tag, itemUrl: url))
}

func trackUserEnterText(with text: String) {
Expand Down Expand Up @@ -150,9 +150,9 @@ extension SaveToAddTagsViewModel {
case .notTagged:
return
case .recent:
tracker.track(event: Events.SaveTo.Tags.selectRecentTagToAddToItem())
tracker.track(event: Events.SaveTo.Tags.selectRecentTagToAddToItem(tagType.name))
case .tag:
tracker.track(event: Events.SaveTo.Tags.selectTagToAddToItem())
tracker.track(event: Events.SaveTo.Tags.selectTagToAddToItem(tagType.name))
}
}
}

0 comments on commit 12fb233

Please sign in to comment.