Skip to content

Commit

Permalink
Create new view for desktop conversion events (#6309)
Browse files Browse the repository at this point in the history
* Create new view for desktop conversion events

* Update view.sql

* Update view.sql

* Update view.sql
  • Loading branch information
kwindau authored Oct 8, 2024
1 parent 94f6066 commit 815a075
Showing 1 changed file with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
CREATE OR REPLACE VIEW
`moz-fx-data-shared-prod.mozilla_org.desktop_conversion_events`
AS
-- Get all clicks not originating from Europe and the first session date associated with that click
WITH all_clicks_not_originating_in_europe AS (
SELECT
gclid,
MIN(session_date) AS first_session_date
FROM
`moz-fx-data-shared-prod.mozilla_org_derived.ga_sessions_v2` AS ga_sessions_v2,
UNNEST(gclid_array) AS gclid
JOIN
`moz-fx-data-shared-prod.static.country_codes_v1` c
ON ga_sessions_v2.country = c.name
WHERE
region_name != 'Europe'
GROUP BY
gclid
)
--Get all conversion events and associated clicks in the last 89 days
--where the click ID did not originate in Europe
--and the click's first seen session date is more recent than 89 days ago
SELECT
a.activity_datetime AS activity_date,
a.gclid,
a.conversion_name
FROM
`moz-fx-data-shared-prod.mozilla_org_derived.ga_desktop_conversions_v1` a
JOIN
all_clicks_not_originating_in_europe b
ON a.gclid = b.gclid
WHERE
a.activity_date >= DATE_SUB(CURRENT_DATE, INTERVAL 89 DAY)
AND b.first_session_date >= DATE_SUB(current_date, INTERVAL 89 day)

1 comment on commit 815a075

@dataops-ci-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Integration report for "Create new view for desktop conversion events (#6309)"

sql.diff

Click to expand!
Only in /tmp/workspace/generated-sql/sql/moz-fx-data-shared-prod/mozilla_org: desktop_conversion_events
diff -bur --no-dereference --new-file /tmp/workspace/main-generated-sql/sql/moz-fx-data-shared-prod/mozilla_org/desktop_conversion_events/metadata.yaml /tmp/workspace/generated-sql/sql/moz-fx-data-shared-prod/mozilla_org/desktop_conversion_events/metadata.yaml
--- /tmp/workspace/main-generated-sql/sql/moz-fx-data-shared-prod/mozilla_org/desktop_conversion_events/metadata.yaml	1970-01-01 00:00:00.000000000 +0000
+++ /tmp/workspace/generated-sql/sql/moz-fx-data-shared-prod/mozilla_org/desktop_conversion_events/metadata.yaml	2024-10-08 17:52:28.000000000 +0000
@@ -0,0 +1,15 @@
+friendly_name: Desktop Conversion Events
+description: |-
+  Please provide a description for the query
+owners: []
+labels: {}
+bigquery: null
+workgroup_access:
+- role: roles/bigquery.dataViewer
+  members:
+  - workgroup:mozilla-confidential
+references:
+  view.sql:
+  - moz-fx-data-shared-prod.mozilla_org_derived.ga_desktop_conversions_v1
+  - moz-fx-data-shared-prod.mozilla_org_derived.ga_sessions_v2
+  - moz-fx-data-shared-prod.static.country_codes_v1
diff -bur --no-dereference --new-file /tmp/workspace/main-generated-sql/sql/moz-fx-data-shared-prod/mozilla_org/desktop_conversion_events/view.sql /tmp/workspace/generated-sql/sql/moz-fx-data-shared-prod/mozilla_org/desktop_conversion_events/view.sql
--- /tmp/workspace/main-generated-sql/sql/moz-fx-data-shared-prod/mozilla_org/desktop_conversion_events/view.sql	1970-01-01 00:00:00.000000000 +0000
+++ /tmp/workspace/generated-sql/sql/moz-fx-data-shared-prod/mozilla_org/desktop_conversion_events/view.sql	2024-10-08 17:50:19.000000000 +0000
@@ -0,0 +1,34 @@
+CREATE OR REPLACE VIEW
+  `moz-fx-data-shared-prod.mozilla_org.desktop_conversion_events`
+AS
+-- Get all clicks not originating from Europe and the first session date associated with that click
+WITH all_clicks_not_originating_in_europe AS (
+  SELECT
+    gclid,
+    MIN(session_date) AS first_session_date
+  FROM
+    `moz-fx-data-shared-prod.mozilla_org_derived.ga_sessions_v2` AS ga_sessions_v2,
+    UNNEST(gclid_array) AS gclid
+  JOIN
+    `moz-fx-data-shared-prod.static.country_codes_v1` c
+    ON ga_sessions_v2.country = c.name
+  WHERE
+    region_name != 'Europe'
+  GROUP BY
+    gclid
+)
+--Get all conversion events and associated clicks in the last 89 days
+--where the click ID did not originate in Europe
+--and the click's first seen session date is more recent than 89 days ago
+SELECT
+  a.activity_datetime AS activity_date,
+  a.gclid,
+  a.conversion_name
+FROM
+  `moz-fx-data-shared-prod.mozilla_org_derived.ga_desktop_conversions_v1` a
+JOIN
+  all_clicks_not_originating_in_europe b
+  ON a.gclid = b.gclid
+WHERE
+  a.activity_date >= DATE_SUB(CURRENT_DATE, INTERVAL 89 DAY)
+  AND b.first_session_date >= DATE_SUB(current_date, INTERVAL 89 day)

Link to full diff

Please sign in to comment.