Repository: dbt-labs/dbt-core

Issue:
Track project ID as part of package install event
### Describe the feature
The current package install events do not include project IDs. This makes it impossible to answer the question:
"How many projects use a package?" (i.e. `count(distinct project_id) from installs`)

### Who will this benefit?
Package maintainers running analytics on package usage


Discussion:

Resolving patch:
diff --git a/core/dbt/task/deps.py b/core/dbt/task/deps.py
--- a/core/dbt/task/deps.py
+++ b/core/dbt/task/deps.py
@@ -23,16 +23,23 @@ def __init__(self, args, config: UnsetProfileConfig):
     def track_package_install(
         self, package_name: str, source_type: str, version: str
     ) -> None:
-        version = 'local' if source_type == 'local' else version
+        # Hub packages do not need to be hashed, as they are public
+        # Use the string 'local' for local package versions
+        if source_type == 'local':
+            version = 'local'
+        elif source_type != 'hub':
+            package_name = dbt.utils.md5(package_name)
+            version = dbt.utils.md5(version)
 
-        h_package_name = dbt.utils.md5(package_name)
-        h_version = dbt.utils.md5(version)
-
-        dbt.tracking.track_package_install({
-            "name": h_package_name,
-            "source": source_type,
-            "version": h_version
-        })
+        dbt.tracking.track_package_install(
+            self.config,
+            self.config.args,
+            {
+                "name": package_name,
+                "source": source_type,
+                "version": version
+            }
+        )
 
     def run(self):
         system.make_directory(self.config.modules_path)
diff --git a/core/dbt/tracking.py b/core/dbt/tracking.py
--- a/core/dbt/tracking.py
+++ b/core/dbt/tracking.py
@@ -299,11 +299,17 @@ def track_rpc_request(options):
     )
 
 
-def track_package_install(options):
-    context = [SelfDescribingJson(PACKAGE_INSTALL_SPEC, options)]
+def track_package_install(config, args, options):
     assert active_user is not None, \
         'Cannot track package installs when active user is None'
 
+    invocation_data = get_invocation_context(active_user, config, args)
+
+    context = [
+        SelfDescribingJson(INVOCATION_SPEC, invocation_data),
+        SelfDescribingJson(PACKAGE_INSTALL_SPEC, options)
+    ]
+
     track(
         active_user,
         category="dbt",


Test patch:
diff --git a/test/integration/033_event_tracking_test/test_events.py b/test/integration/033_event_tracking_test/test_events.py
--- a/test/integration/033_event_tracking_test/test_events.py
+++ b/test/integration/033_event_tracking_test/test_events.py
@@ -224,6 +224,19 @@ def test__postgres_event_tracking_compile(self):
     @use_profile("postgres")
     def test__postgres_event_tracking_deps(self):
         package_context = [
+            {
+                'schema': 'iglu:com.dbt/invocation/jsonschema/1-0-1',
+                'data': {
+                    'project_id': '098f6bcd4621d373cade4e832627b4f6',
+                    'user_id': ANY,
+                    'invocation_id': ANY,
+                    'version': ANY,
+                    'command': 'deps',
+                    'run_type': 'regular',
+                    'options': None,
+                    'adapter_type': 'postgres'
+                }
+            },
             {
                 'schema': 'iglu:com.dbt/package_install/jsonschema/1-0-0',
                 'data': {