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

fix: track screen name autocapture #207

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
18 changes: 8 additions & 10 deletions Sources/Amplitude/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,14 @@ public struct Constants {
static let AMP_APP_LINK_URL_PROPERTY = "\(AMP_AMPLITUDE_PREFIX)Link URL"
static let AMP_APP_LINK_REFERRER_PROPERTY = "\(AMP_AMPLITUDE_PREFIX)Link Referrer"
static let AMP_APP_SCREEN_NAME_PROPERTY = "\(AMP_AMPLITUDE_PREFIX)Screen Name"
static let AMP_APP_VIEW_CONTROLLER = "\(AMP_AMPLITUDE_PREFIX)View Controller"
static let AMP_APP_TITLE = "\(AMP_AMPLITUDE_PREFIX)Title"
static let AMP_APP_TARGET_ACCESSIBILITY_LABEL = "\(AMP_AMPLITUDE_PREFIX)Target Accessibility Label"
static let AMP_APP_TARGET_ACCESSIBILITY_IDENTIFIER = "\(AMP_AMPLITUDE_PREFIX)Target Accessibility Identifier"
static let AMP_APP_ACTION = "\(AMP_AMPLITUDE_PREFIX)Action"
static let AMP_APP_TARGET_VIEW_CLASS = "\(AMP_AMPLITUDE_PREFIX)Target View Class"
static let AMP_APP_TARGET_TEXT = "\(AMP_AMPLITUDE_PREFIX)Target Text"
static let AMP_APP_HIERARCHY = "\(AMP_AMPLITUDE_PREFIX)Hierarchy"
static let AMP_APP_ACTION_METHOD = "\(AMP_AMPLITUDE_PREFIX)Action Method"
static let AMP_APP_GESTURE_RECOGNIZER = "\(AMP_AMPLITUDE_PREFIX)Gesture Recognizer"
static let AMP_APP_TARGET_AXLABEL_PROPERTY = "\(AMP_AMPLITUDE_PREFIX)Target Accessibility Label"
static let AMP_APP_TARGET_AXIDENTIFIER_PROPERTY = "\(AMP_AMPLITUDE_PREFIX)Target Accessibility Identifier"
static let AMP_APP_ACTION_PROPERTY = "\(AMP_AMPLITUDE_PREFIX)Action"
static let AMP_APP_TARGET_VIEW_CLASS_PROPERTY = "\(AMP_AMPLITUDE_PREFIX)Target View Class"
static let AMP_APP_TARGET_TEXT_PROPERTY = "\(AMP_AMPLITUDE_PREFIX)Target Text"
static let AMP_APP_HIERARCHY_PROPERTY = "\(AMP_AMPLITUDE_PREFIX)Hierarchy"
static let AMP_APP_ACTION_METHOD_PROPERTY = "\(AMP_AMPLITUDE_PREFIX)Action Method"
static let AMP_APP_GESTURE_RECOGNIZER_PROPERTY = "\(AMP_AMPLITUDE_PREFIX)Gesture Recognizer"

public struct Configuration {
public static let FLUSH_QUEUE_SIZE = 30
Expand Down
22 changes: 10 additions & 12 deletions Sources/Amplitude/Events/ElementInteractionEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import Foundation

public class ElementInteractionEvent: BaseEvent {
convenience init(
viewController: String? = nil,
title: String? = nil,
screenName: String? = nil,
accessibilityLabel: String? = nil,
accessibilityIdentifier: String? = nil,
action: String,
Expand All @@ -14,16 +13,15 @@ public class ElementInteractionEvent: BaseEvent {
gestureRecognizer: String? = nil
) {
self.init(eventType: Constants.AMP_ELEMENT_INTERACTED_EVENT, eventProperties: [
Constants.AMP_APP_VIEW_CONTROLLER: viewController,
Constants.AMP_APP_TITLE: title,
Constants.AMP_APP_TARGET_ACCESSIBILITY_LABEL: accessibilityLabel,
Constants.AMP_APP_TARGET_ACCESSIBILITY_IDENTIFIER: accessibilityIdentifier,
Constants.AMP_APP_ACTION: action,
Constants.AMP_APP_TARGET_VIEW_CLASS: targetViewClass,
Constants.AMP_APP_TARGET_TEXT: targetText,
Constants.AMP_APP_HIERARCHY: hierarchy,
Constants.AMP_APP_ACTION_METHOD: actionMethod,
Constants.AMP_APP_GESTURE_RECOGNIZER: gestureRecognizer
Constants.AMP_APP_SCREEN_NAME_PROPERTY: screenName,
Constants.AMP_APP_TARGET_AXLABEL_PROPERTY: accessibilityLabel,
Constants.AMP_APP_TARGET_AXIDENTIFIER_PROPERTY: accessibilityIdentifier,
Constants.AMP_APP_ACTION_PROPERTY: action,
Constants.AMP_APP_TARGET_VIEW_CLASS_PROPERTY: targetViewClass,
Constants.AMP_APP_TARGET_TEXT_PROPERTY: targetText,
Constants.AMP_APP_HIERARCHY_PROPERTY: hierarchy,
Constants.AMP_APP_ACTION_METHOD_PROPERTY: actionMethod,
Constants.AMP_APP_GESTURE_RECOGNIZER_PROPERTY: gestureRecognizer
])
}
}
13 changes: 5 additions & 8 deletions Sources/Amplitude/Plugins/iOS/UIKitElementInteractions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ class UIKitElementInteractions {
case gestureRecognizer
}

let viewController: String?

let title: String?
let screenName: String?

let accessibilityLabel: String?

Expand All @@ -25,8 +23,7 @@ class UIKitElementInteractions {

fileprivate func elementInteractionEvent(for action: String, from source: Source? = nil, withName sourceName: String? = nil) -> ElementInteractionEvent {
return ElementInteractionEvent(
viewController: viewController,
title: title,
screenName: screenName,
accessibilityLabel: accessibilityLabel,
accessibilityIdentifier: accessibilityIdentifier,
action: action,
Expand Down Expand Up @@ -155,10 +152,10 @@ extension UIView {
private static let viewHierarchyDelimiter = " → "

var eventData: UIKitElementInteractions.EventData {
let viewController = owningViewController
return UIKitElementInteractions.EventData(
viewController: viewController?.descriptiveTypeName,
title: viewController?.title,
screenName: owningViewController
.flatMap(UIViewController.amp_topViewController)
.flatMap(UIKitScreenViews.screenName),
accessibilityLabel: accessibilityLabel,
accessibilityIdentifier: accessibilityIdentifier,
targetViewClass: descriptiveTypeName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ class UIKitElementInteractionsTests: XCTestCase {

let buttonData = button.eventData

XCTAssertEqual(buttonData.viewController, "UIViewController")
XCTAssertEqual(buttonData.title, "Mock VC Title")
XCTAssertEqual(buttonData.screenName, "Mock VC Title")
XCTAssertEqual(buttonData.accessibilityLabel, "Accessibility Button")
XCTAssertEqual(buttonData.targetViewClass, "UIButton")
XCTAssertEqual(buttonData.targetText, "Test Button")
Expand All @@ -34,8 +33,7 @@ class UIKitElementInteractionsTests: XCTestCase {

let customViewData = customView.eventData

XCTAssertEqual(customViewData.viewController, "UIViewController")
XCTAssertEqual(customViewData.title, "Mock VC Title")
XCTAssertEqual(customViewData.screenName, "Mock VC Title")
XCTAssertNil(customViewData.accessibilityLabel)
XCTAssertEqual(customViewData.targetViewClass, "CustomView")
XCTAssertTrue(customViewData.hierarchy.hasSuffix("CustomView → UIView"))
Expand All @@ -45,8 +43,7 @@ class UIKitElementInteractionsTests: XCTestCase {
let orphanView = UIView()
let orphanData = orphanView.eventData

XCTAssertNil(orphanData.viewController)
XCTAssertNil(orphanData.title)
XCTAssertNil(orphanData.screenName)
XCTAssertNil(orphanData.accessibilityLabel)
XCTAssertEqual(orphanData.targetViewClass, "UIView")
XCTAssertNil(orphanData.targetText)
Expand Down
Loading