[go: nahoru, domu]

[iOS] Add campaign token to StoreKit VC for Save to Photos

This CL sets the SKStoreProductParameterCampaignToken used by StoreKit
when Save to Photos presents the StoreKit VC with the Photos app so the
number of times the Photos app is installed from Chrome can be counted.

Fixed: 1493955
Change-Id: I2bb161c4c98b5911807e542f0511f0c8d7fead66
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4952501
Commit-Queue: Quentin Pubert <qpubert@google.com>
Reviewed-by: Sylvain Defresne <sdefresne@chromium.org>
Code-Coverage: findit-for-me@appspot.gserviceaccount.com <findit-for-me@appspot.gserviceaccount.com>
Cr-Commit-Position: refs/heads/main@{#1212636}
diff --git a/ios/chrome/browser/ui/save_to_photos/save_to_photos_coordinator.mm b/ios/chrome/browser/ui/save_to_photos/save_to_photos_coordinator.mm
index 019941a..3b53bb46 100644
--- a/ios/chrome/browser/ui/save_to_photos/save_to_photos_coordinator.mm
+++ b/ios/chrome/browser/ui/save_to_photos/save_to_photos_coordinator.mm
@@ -154,7 +154,8 @@
   _alertCoordinator = nil;
 }
 
-- (void)showStoreKitWithProductIdentifier:(NSString*)productIdentifer {
+- (void)showStoreKitWithProductIdentifier:(NSString*)productIdentifer
+                            campaignToken:(NSString*)campaignToken {
   if (_storeKitCoordinator) {
     [_storeKitCoordinator stop];
     _storeKitCoordinator = nil;
@@ -164,8 +165,10 @@
       initWithBaseViewController:self.baseViewController
                          browser:self.browser];
   _storeKitCoordinator.delegate = self;
-  _storeKitCoordinator.iTunesProductParameters =
-      @{SKStoreProductParameterITunesItemIdentifier : productIdentifer};
+  _storeKitCoordinator.iTunesProductParameters = @{
+    SKStoreProductParameterITunesItemIdentifier : productIdentifer,
+    SKStoreProductParameterCampaignToken : campaignToken
+  };
   [_storeKitCoordinator start];
 }
 
diff --git a/ios/chrome/browser/ui/save_to_photos/save_to_photos_coordinator_unittest.mm b/ios/chrome/browser/ui/save_to_photos/save_to_photos_coordinator_unittest.mm
index cbf25d4..9a30d88 100644
--- a/ios/chrome/browser/ui/save_to_photos/save_to_photos_coordinator_unittest.mm
+++ b/ios/chrome/browser/ui/save_to_photos/save_to_photos_coordinator_unittest.mm
@@ -250,6 +250,7 @@
       [coordinator conformsToProtocol:@protocol(SaveToPhotosMediatorDelegate)]);
 
   NSString* productIdentifier = @"product_identifier";
+  NSString* campaignToken = @"campaign_token";
 
   id mock_store_kit_coordinator = OCMClassMock([StoreKitCoordinator class]);
   OCMExpect([mock_store_kit_coordinator alloc])
@@ -260,14 +261,18 @@
       .andReturn(mock_store_kit_coordinator);
   OCMExpect([mock_store_kit_coordinator
       setDelegate:static_cast<id<SaveToPhotosMediatorDelegate>>(coordinator)]);
-  OCMExpect([mock_store_kit_coordinator setITunesProductParameters:@{
-    SKStoreProductParameterITunesItemIdentifier : productIdentifier
-  }]);
+  NSDictionary* expectedITunesProductParameters = @{
+    SKStoreProductParameterITunesItemIdentifier : productIdentifier,
+    SKStoreProductParameterCampaignToken : campaignToken
+  };
+  OCMExpect([mock_store_kit_coordinator
+      setITunesProductParameters:expectedITunesProductParameters]);
   OCMExpect([base::apple::ObjCCast<StoreKitCoordinator>(
       mock_store_kit_coordinator) start]);
 
   [static_cast<id<SaveToPhotosMediatorDelegate>>(coordinator)
-      showStoreKitWithProductIdentifier:productIdentifier];
+      showStoreKitWithProductIdentifier:productIdentifier
+                          campaignToken:campaignToken];
   EXPECT_OCMOCK_VERIFY(mock_store_kit_coordinator);
 
   OCMExpect([base::apple::ObjCCast<StoreKitCoordinator>(
diff --git a/ios/chrome/browser/ui/save_to_photos/save_to_photos_mediator.h b/ios/chrome/browser/ui/save_to_photos/save_to_photos_mediator.h
index 400c9d5..ce54712 100644
--- a/ios/chrome/browser/ui/save_to_photos/save_to_photos_mediator.h
+++ b/ios/chrome/browser/ui/save_to_photos/save_to_photos_mediator.h
@@ -24,6 +24,19 @@
 class WebState;
 }  // namespace web
 
+// Photos app product identifier passed to the StoreKit view.
+extern NSString* const kGooglePhotosAppProductIdentifier;
+
+// This campaign token is passed to the StoreKit view so the number of Photos
+// app installs from Chrome can be measured. This should not be modified.
+extern NSString* const kGooglePhotosStoreKitCampaignToken;
+
+// Photos app URL template to open the "Recently added" view.
+extern NSString* const kGooglePhotosRecentlyAddedURLString;
+
+// Photos app URL scheme to check if the Photos app is installed.
+extern NSString* const kGooglePhotosAppURLScheme;
+
 // Save to Photos mediator. This UI is presented when the user has selected an
 // image to be saved in their Photos library e.g. Google Photos. It lets the
 // user select an account as destination and notifies the user of progress and
diff --git a/ios/chrome/browser/ui/save_to_photos/save_to_photos_mediator.mm b/ios/chrome/browser/ui/save_to_photos/save_to_photos_mediator.mm
index ba8a6619..afdd0db 100644
--- a/ios/chrome/browser/ui/save_to_photos/save_to_photos_mediator.mm
+++ b/ios/chrome/browser/ui/save_to_photos/save_to_photos_mediator.mm
@@ -27,13 +27,6 @@
 
 namespace {
 
-NSString* const kGooglePhotosAppProductIdentifier = @"962194608";
-
-NSString* const kGooglePhotosRecentlyAddedURLString =
-    @"https://photos.google.com/search/_tra_?obfsgid=";
-
-NSString* const kGooglePhotosAppURLScheme = @"googlephotos";
-
 NSURL* GetGooglePhotosAppURL() {
   NSURLComponents* photosAppURLComponents = [[NSURLComponents alloc] init];
   photosAppURLComponents.scheme = kGooglePhotosAppURLScheme;
@@ -59,6 +52,15 @@
 
 }  // namespace
 
+NSString* const kGooglePhotosAppProductIdentifier = @"962194608";
+
+NSString* const kGooglePhotosStoreKitCampaignToken = @"chrome-x-photos";
+
+NSString* const kGooglePhotosRecentlyAddedURLString =
+    @"https://photos.google.com/search/_tra_?obfsgid=";
+
+NSString* const kGooglePhotosAppURLScheme = @"googlephotos";
+
 @implementation SaveToPhotosMediator {
   PhotosService* _photosService;
   PrefService* _prefService;
@@ -406,7 +408,8 @@
   // If the Photos app is not installed, show StoreKit.
   if (![UIApplication.sharedApplication canOpenURL:GetGooglePhotosAppURL()]) {
     [self.delegate
-        showStoreKitWithProductIdentifier:kGooglePhotosAppProductIdentifier];
+        showStoreKitWithProductIdentifier:kGooglePhotosAppProductIdentifier
+                            campaignToken:kGooglePhotosStoreKitCampaignToken];
     return;
   }
 
diff --git a/ios/chrome/browser/ui/save_to_photos/save_to_photos_mediator_delegate.h b/ios/chrome/browser/ui/save_to_photos/save_to_photos_mediator_delegate.h
index 72b476ad..c0e28517 100644
--- a/ios/chrome/browser/ui/save_to_photos/save_to_photos_mediator_delegate.h
+++ b/ios/chrome/browser/ui/save_to_photos/save_to_photos_mediator_delegate.h
@@ -33,7 +33,8 @@
 - (void)hideTryAgainOrCancelAlert;
 
 // Show and hide StoreKit.
-- (void)showStoreKitWithProductIdentifier:(NSString*)productIdentifer;
+- (void)showStoreKitWithProductIdentifier:(NSString*)productIdentifer
+                            campaignToken:(NSString*)campaignToken;
 - (void)hideStoreKit;
 
 // Show a snackbar with the given `message`, a button with label `buttonText`.
diff --git a/ios/chrome/browser/ui/save_to_photos/save_to_photos_mediator_unittest.mm b/ios/chrome/browser/ui/save_to_photos/save_to_photos_mediator_unittest.mm
index 6badb884..394a5cc 100644
--- a/ios/chrome/browser/ui/save_to_photos/save_to_photos_mediator_unittest.mm
+++ b/ios/chrome/browser/ui/save_to_photos/save_to_photos_mediator_unittest.mm
@@ -39,8 +39,6 @@
 
 namespace {
 
-NSString* const kGooglePhotosAppProductIdentifier = @"962194608";
-
 // Fake image URL.
 const char kFakeImageUrl[] = "http://example.com/image.png";
 
@@ -63,13 +61,6 @@
   return base::SysUTF8ToNSString(GURL(kFakeImageUrl).ExtractFileName());
 }
 
-// URL to open the Google Photos app.
-NSString* const kGooglePhotosRecentlyAddedURLString =
-    @"https://photos.google.com/search/_tra_?obfsgid=";
-
-// URL Scheme to test whether the Google Photos app is installed.
-NSString* const kGooglePhotosAppURLScheme = @"googlephotos";
-
 // Returns the URL to test whether the Google Photos app is installed.
 NSURL* GetGooglePhotosAppURL() {
   NSURLComponents* photosAppURLComponents = [[NSURLComponents alloc] init];
@@ -543,7 +534,8 @@
   // Expect that the mediator tries to show StoreKit with the expected product
   // identifier.
   OCMExpect([mock_save_to_photos_mediator_delegate
-      showStoreKitWithProductIdentifier:kGooglePhotosAppProductIdentifier]);
+      showStoreKitWithProductIdentifier:kGooglePhotosAppProductIdentifier
+                          campaignToken:kGooglePhotosStoreKitCampaignToken]);
 
   // Simulate the user tapped the "Open" button.
   savedMessageAction();