Skip to content

Commit

Permalink
Merge pull request #17612 from wordpress-mobile/issue/17503-add-site-…
Browse files Browse the repository at this point in the history
…tracking

Adds tracking to the Add Site buttons
  • Loading branch information
Emily Laguna authored Dec 2, 2021
2 parents 30ed540 + db3f221 commit e554d88
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 10 deletions.
5 changes: 5 additions & 0 deletions WordPress/Classes/Utility/Analytics/WPAnalyticsEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,8 @@ import Foundation
// Preview WebKitView
case previewWebKitViewDeviceChanged

case addSiteAlertDisplayed

/// A String that represents the event
var value: String {
switch self {
Expand Down Expand Up @@ -778,6 +780,9 @@ import Foundation
case .previewWebKitViewDeviceChanged:
return "preview_webkitview_device_changed"

case .addSiteAlertDisplayed:
return "add_site_alert_displayed"

} // END OF SWITCH
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class AddSiteAlertFactory: NSObject {

@objc
func makeAddSiteAlert(
source: String?,
canCreateWPComSite: Bool,
createWPComSite: @escaping () -> Void,
addSelfHostedSite: @escaping () -> Void) -> UIAlertController {
Expand All @@ -20,6 +21,8 @@ class AddSiteAlertFactory: NSObject {
alertController.addAction(addSelfHostedSiteAction(handler: addSelfHostedSite))
alertController.addAction(cancelAction())

WPAnalytics.track(.addSiteAlertDisplayed, properties: ["source": source ?? "unknown"])

return alertController
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ extension BlogListViewController {
return
}
present(wizard, animated: true)
WPAnalytics.track(.enhancedSiteCreationAccessed)
WPAnalytics.track(.enhancedSiteCreationAccessed, withProperties: ["source": "my_sites"])
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -995,13 +995,15 @@ - (void)showAddSiteAlertFrom:(id)source
[self setEditing:YES animated:YES];
} else {
AddSiteAlertFactory *factory = [AddSiteAlertFactory new];
UIAlertController *alertController = [factory makeAddSiteAlertWithCanCreateWPComSite:[self defaultWordPressComAccount]
createWPComSite:^{
BOOL canCreateWPComSite = [self defaultWordPressComAccount] ? YES : NO;
UIAlertController *alertController = [factory makeAddSiteAlertWithSource:@"my_site"
canCreateWPComSite:canCreateWPComSite
createWPComSite:^{
[self launchSiteCreation];
} addSelfHostedSite:^{
[self showLoginControllerForAddingSelfHostedSite];
}];

if ([source isKindOfClass:[UIView class]]) {
UIView *sourceView = (UIView *)source;
alertController.popoverPresentationController.sourceView = sourceView;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class MySiteViewController: UIViewController, NoResultsViewHost {
}

private func subscribeToPostSignupNotifications() {
NotificationCenter.default.addObserver(self, selector: #selector(launchSiteCreation), name: .createSite, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(launchSiteCreationFromNotification), name: .createSite, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(showAddSelfHostedSite), name: .addSelfHosted, object: nil)
}

Expand Down Expand Up @@ -280,8 +280,8 @@ class MySiteViewController: UIViewController, NoResultsViewHost {

@objc
func presentInterfaceForAddingNewSite() {
let addSiteAlert = AddSiteAlertFactory().makeAddSiteAlert(canCreateWPComSite: defaultAccount() != nil) { [weak self] in
self?.launchSiteCreation()
let addSiteAlert = AddSiteAlertFactory().makeAddSiteAlert(source: "my_site_no_sites", canCreateWPComSite: defaultAccount() != nil) { [weak self] in
self?.launchSiteCreation(source: "my_site_no_sites")
} addSelfHostedSite: {
WordPressAuthenticator.showLoginForSelfHostedSite(self)
}
Expand All @@ -298,13 +298,17 @@ class MySiteViewController: UIViewController, NoResultsViewHost {
}

@objc
func launchSiteCreation() {
func launchSiteCreationFromNotification() {
self.launchSiteCreation(source: "signup_epilogue")
}

func launchSiteCreation(source: String) {
let wizardLauncher = SiteCreationWizardLauncher()
guard let wizard = wizardLauncher.ui else {
return
}
present(wizard, animated: true)
WPAnalytics.track(.enhancedSiteCreationAccessed)
WPAnalytics.track(.enhancedSiteCreationAccessed, withProperties: ["source": source])
}

@objc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ extension WordPressAuthenticationManager: WordPressAuthenticatorDelegate {
}

navigationController.present(wizard, animated: true)
WPAnalytics.track(.enhancedSiteCreationAccessed, withProperties: ["source": "login_epilogue"])
}

navigationController.pushViewController(epilogueViewController, animated: true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ class MySitesCoordinator: NSObject {

func showSiteCreation() {
showRootViewController()
mySiteViewController.launchSiteCreation()
mySiteViewController.launchSiteCreation(source: "my_site")
}

@objc
Expand Down

0 comments on commit e554d88

Please sign in to comment.