Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

rearrange parseFiltersFromQuery

Steven Tey4dd148f447cb
diff --git a/apps/web/lib/analytics/get-analytics.ts b/apps/web/lib/analytics/get-analytics.ts
index 6b67511b38..1d34e46cf1 100644
--- a/apps/web/lib/analytics/get-analytics.ts
+++ b/apps/web/lib/analytics/get-analytics.ts
@@ -12,8 +12,8 @@ import {
DIMENSIONAL_ANALYTICS_FILTERS,
SINGULAR_ANALYTICS_ENDPOINTS,
} from "./constants";
+import { parseFiltersFromQuery } from "./query-parser";
import { AnalyticsFilters } from "./types";
-import { parseFiltersFromQuery } from "./utils/analytics-query-parser";
import { getStartEndDates } from "./utils/get-start-end-dates";
// Fetch data for /api/analytics
diff --git a/apps/web/lib/analytics/get-events.ts b/apps/web/lib/analytics/get-events.ts
index 1fb8628a5c..975ecd44a0 100644
--- a/apps/web/lib/analytics/get-events.ts
+++ b/apps/web/lib/analytics/get-events.ts
@@ -21,8 +21,8 @@ import {
saleEventResponseSchema,
saleEventSchemaTBEndpoint,
} from "../zod/schemas/sales";
+import { parseFiltersFromQuery } from "./query-parser";
import { EventsFilters } from "./types";
-import { parseFiltersFromQuery } from "./utils/analytics-query-parser";
import { getStartEndDates } from "./utils/get-start-end-dates";
// Fetch data for /api/events
diff --git a/apps/web/lib/analytics/utils/analytics-query-parser.ts b/apps/web/lib/analytics/query-parser.ts
similarity index 98%
rename from apps/web/lib/analytics/utils/analytics-query-parser.ts
rename to apps/web/lib/analytics/query-parser.ts
index 59153398f5..4a15728526 100644
--- a/apps/web/lib/analytics/utils/analytics-query-parser.ts
+++ b/apps/web/lib/analytics/query-parser.ts
@@ -1,4 +1,4 @@
-import { EventsFilters } from "../types";
+import { EventsFilters } from "./types";
interface InternalFilter {
operand: string;
diff --git a/apps/web/tests/misc/analytics-query-parser.test.ts b/apps/web/tests/misc/analytics-query-parser.test.ts
index d409450c59..7ef0669041 100644
--- a/apps/web/tests/misc/analytics-query-parser.test.ts
+++ b/apps/web/tests/misc/analytics-query-parser.test.ts
@@ -1,4 +1,4 @@
-import { parseFiltersFromQuery } from "@/lib/analytics/utils/analytics-query-parser";
+import { parseFiltersFromQuery } from "@/lib/analytics/query-parser";
import { describe, expect, it } from "vitest";
describe("Analytics Query Parser", () => {
diff --git a/packages/tinybird/pipes/v2_events.pipe b/packages/tinybird/pipes/v2_events.pipe
index 31a78ff10e..0ff64bcb57 100644
--- a/packages/tinybird/pipes/v2_events.pipe
+++ b/packages/tinybird/pipes/v2_events.pipe
@@ -134,14 +134,14 @@ SQL >
AND url LIKE concat('%utm_content=', encodeURLFormComponent({{ String(utm_content) }}), '%')
{% end %}
{% if defined(url) %} AND url = {{ url }} {% end %}
-
+
{% if defined(filters) %}
{% for item in JSON(filters, '[]') %}
{% if item.get('operand', '').startswith('metadata.') %}
{% set metadataKey = item.get('operand', '').split('.')[1] %}
{% set operator = item.get('operator', 'equals') %}
{% set value = item.get('value', '') %}
-
+
{% if operator == 'equals' %}
AND JSONExtractString(metadata, {{ metadataKey }}) = {{ value }}
{% elif operator == 'notEquals' %}
@@ -158,7 +158,7 @@ SQL >
{% end %}
{% end %}
{% end %}
-
+
ORDER BY timestamp {% if order == 'asc' %} ASC {% else %} DESC {% end %}
LIMIT {{ Int32(limit, 100) }}
{% if defined(offset) %} OFFSET {{ Int32(offset, 0) }} {% end %}
@@ -194,11 +194,22 @@ SQL >
{% if defined(os) %} AND os = {{ os }} {% end %}
{% if defined(referer) %} AND referer = {{ referer }} {% end %}
{% if defined(refererUrl) %} AND splitByString('?', referer_url)[1] = {{ refererUrl }} {% end %}
- {% if defined(utm_source) %} AND url LIKE concat('%utm_source=', encodeURLFormComponent({{ String(utm_source) }}), '%') {% end %}
- {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', encodeURLFormComponent({{ String(utm_medium) }}), '%') {% end %}
- {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', encodeURLFormComponent({{ String(utm_campaign) }}), '%') {% end %}
- {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', encodeURLFormComponent({{ String(utm_term) }}), '%') {% end %}
- {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', encodeURLFormComponent({{ String(utm_content) }}), '%') {% end %}
+ {% if defined(utm_source) %}
+ AND url LIKE concat('%utm_source=', encodeURLFormComponent({{ String(utm_source) }}), '%')
+ {% end %}
+ {% if defined(utm_medium) %}
+ AND url LIKE concat('%utm_medium=', encodeURLFormComponent({{ String(utm_medium) }}), '%')
+ {% end %}
+ {% if defined(utm_campaign) %}
+ AND url
+ LIKE concat('%utm_campaign=', encodeURLFormComponent({{ String(utm_campaign) }}), '%')
+ {% end %}
+ {% if defined(utm_term) %}
+ AND url LIKE concat('%utm_term=', encodeURLFormComponent({{ String(utm_term) }}), '%')
+ {% end %}
+ {% if defined(utm_content) %}
+ AND url LIKE concat('%utm_content=', encodeURLFormComponent({{ String(utm_content) }}), '%')
+ {% end %}
{% if defined(url) %} AND url = {{ url }} {% end %}
{% if defined(filters) %}
@@ -207,7 +218,7 @@ SQL >
{% set metadataKey = item.get('operand', '').split('.')[1] %}
{% set operator = item.get('operator', 'equals') %}
{% set value = item.get('value', '') %}
-
+
{% if operator == 'equals' %}
AND JSONExtractString(metadata, {{ metadataKey }}) = {{ value }}
{% elif operator == 'notEquals' %}