Repository: gradio-app/gradio

Issue:
[Blocks] Blocks-specifics Analytics
Our segment analytics should differentiate based on what kind of `Launchable()` is launched: `Block` vs. `Interface` vs. others in the future.  

In addition, are there other, Block-specific analytics we want to measure?
* What kind of components are being used?
* What kind of static components are being used?
* More error logging? I anticipate that a lot more errors will happen with Blocks compared to regular Interfaces.



Discussion:

Resolving patch:
diff --git a/gradio/blocks.py b/gradio/blocks.py
--- a/gradio/blocks.py
+++ b/gradio/blocks.py
@@ -158,16 +158,30 @@ def change(self, fn: Callable, inputs: List[Component], outputs: List[Component]
 
 
 class Blocks(Launchable, BlockContext):
-    def __init__(self, theme="default"):
+    def __init__(
+        self,
+        theme: str = "default",
+        analytics_enabled: Optional[bool] = None,
+        mode: str = "blocks",
+    ):
+
         # Cleanup shared parameters with Interface
         self.save_to = None
         self.ip_address = utils.get_local_ip_address()
         self.api_mode = False
-        self.analytics_enabled = True
         self.theme = theme
         self.requires_permissions = False  # TODO: needs to be implemented
         self.enable_queue = False
         self.is_space = True if os.getenv("SYSTEM") == "spaces" else False
+        self.mode = mode
+
+        # For analytics_enabled and allow_flagging: (1) first check for
+        # parameter, (2) check for env variable, (3) default to True/"manual"
+        self.analytics_enabled = (
+            analytics_enabled
+            if analytics_enabled is not None
+            else os.getenv("GRADIO_ANALYTICS_ENABLED", "True") == "True"
+        )
 
         super().__init__()
         self.blocks = {}
diff --git a/gradio/interface.py b/gradio/interface.py
--- a/gradio/interface.py
+++ b/gradio/interface.py
@@ -166,7 +166,7 @@ def __init__(
         server_name (str): DEPRECATED. Name of the server to use for serving the interface - pass in launch() instead.
         server_port (int): DEPRECATED. Port of the server to use for serving the interface - pass in launch() instead.
         """
-        super().__init__()
+        super().__init__(analytics_enabled=analytics_enabled, mode="interface")
 
         if not isinstance(fn, list):
             fn = [fn]
@@ -394,7 +394,6 @@ def clean_html(raw_html):
         self.share = None
         self.share_url = None
         self.local_url = None
-        self.ip_address = utils.get_local_ip_address()
 
         if show_tips is not None:
             warnings.warn(
diff --git a/gradio/launchable.py b/gradio/launchable.py
--- a/gradio/launchable.py
+++ b/gradio/launchable.py
@@ -197,13 +197,14 @@ def launch(
             "is_google_colab": is_colab,
             "is_sharing_on": share,
             "share_url": share_url,
-            "ip_address": self.ip_address,
+            "ip_address": self.ip_address if hasattr(self, "ip_address") else "",
             "enable_queue": self.enable_queue,
             "show_tips": self.show_tips,
-            "api_mode": self.api_mode,
+            "api_mode": self.api_mode if hasattr(self, "api_mode") else "",
             "server_name": server_name,
             "server_port": server_port,
-            "is_spaces": self.is_space,
+            "is_spaces": self.is_space if hasattr(self, "is_space") else "",
+            "mode": self.mode if hasattr(self, "mode") else "",
         }
         if self.analytics_enabled:
             utils.launch_analytics(data)


Test patch: