diff --git a/gutenberg b/gutenberg index 5870cafa74..67a36f387d 160000 --- a/gutenberg +++ b/gutenberg @@ -1 +1 @@ -Subproject commit 5870cafa74aee22b1c59c26451561a722c769c73 +Subproject commit 67a36f387d5e4f7828e4c25fe5f89743a839412e diff --git a/react-native-gutenberg-bridge/index.js b/react-native-gutenberg-bridge/index.js index f8ff33fc1b..b3d9ae3e45 100644 --- a/react-native-gutenberg-bridge/index.js +++ b/react-native-gutenberg-bridge/index.js @@ -16,6 +16,10 @@ export const mediaSources = { siteMediaLibrary: 'SITE_MEDIA_LIBRARY', }; +export const userEvents = { + pageTemplateApplied: 'page_template_applied', +}; + export const showMediaEditorButton = isIOS; // Console polyfill from react-native @@ -118,4 +122,8 @@ export function fetchRequest( path ) { return RNReactNativeGutenbergBridge.fetchRequest( path ); } +export function logUserEvent( event, properties ) { + return RNReactNativeGutenbergBridge.logUserEvent( event, properties ); +} + export default RNReactNativeGutenbergBridge; diff --git a/react-native-gutenberg-bridge/ios/GutenbergBridgeDelegate.swift b/react-native-gutenberg-bridge/ios/GutenbergBridgeDelegate.swift index ee0e161ba2..a3635e1bca 100644 --- a/react-native-gutenberg-bridge/ios/GutenbergBridgeDelegate.swift +++ b/react-native-gutenberg-bridge/ios/GutenbergBridgeDelegate.swift @@ -64,6 +64,10 @@ extension RCTLogLevel { } } +public enum GutenbergUserEvent: String { + case pageTemplateApplied = "page_template_applied" +} + public protocol GutenbergBridgeDelegate: class { /// Tells the delegate that Gutenberg had returned the requested HTML content. /// You can request HTML content by calling `requestHTML()` on a Gutenberg bridge instance. @@ -138,6 +142,12 @@ public protocol GutenbergBridgeDelegate: class { /// Tells the delegate to display the media editor from a given URL /// func gutenbergDidRequestMediaEditor(with mediaUrl: URL, callback: @escaping MediaPickerDidPickMediaCallback) + + + /// Tells the delegate that the editor needs to log a custom event + /// - Parameter event: The event key to be logged + /// - Parameter properties: Any relevant properties related to the event + func gutenbergLogUserEvent(_ event: GutenbergUserEvent, properties: [AnyHashable: Any]) } // MARK: - Optional GutenbergBridgeDelegate methods diff --git a/react-native-gutenberg-bridge/ios/RNReactNativeGutenbergBridge.m b/react-native-gutenberg-bridge/ios/RNReactNativeGutenbergBridge.m index 73430cf1dd..5eead641e4 100644 --- a/react-native-gutenberg-bridge/ios/RNReactNativeGutenbergBridge.m +++ b/react-native-gutenberg-bridge/ios/RNReactNativeGutenbergBridge.m @@ -18,5 +18,6 @@ @interface RCT_EXTERN_MODULE(RNReactNativeGutenbergBridge, NSObject) RCT_EXTERN_METHOD(fetchRequest:(NSString *)path resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) RCT_EXTERN_METHOD(requestImageFullscreenPreview:(NSString *)currentImageUrlString originalImageUrlString:(NSString *)originalImageUrlString) RCT_EXTERN_METHOD(requestMediaEditor:(NSString *)mediaUrl callback:(RCTResponseSenderBlock)callback) +RCT_EXTERN_METHOD(logUserEvent:(NSString *)event properties:(NSDictionary *)properties) @end diff --git a/react-native-gutenberg-bridge/ios/RNReactNativeGutenbergBridge.swift b/react-native-gutenberg-bridge/ios/RNReactNativeGutenbergBridge.swift index e09ba4c0e0..462ebe3112 100644 --- a/react-native-gutenberg-bridge/ios/RNReactNativeGutenbergBridge.swift +++ b/react-native-gutenberg-bridge/ios/RNReactNativeGutenbergBridge.swift @@ -224,6 +224,12 @@ public class RNReactNativeGutenbergBridge: RCTEventEmitter { self.sendEvent(withName: name, body: body) } } + + @objc + func logUserEvent(_ event: String, properties:[AnyHashable: Any]?) { + guard let event = GutenbergUserEvent(rawValue: event) else { return } + self.delegate?.gutenbergLogUserEvent(event, properties: properties ?? [:]) + } } // MARK: - RCTBridgeModule delegate