-
-
Notifications
You must be signed in to change notification settings - Fork 52
Support profiles custom events filters #482
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4940,6 +4940,7 @@ export class AnalyticsService { | |
| take = 30, | ||
| skip = 0, | ||
| profileType: 'all' | 'anonymous' | 'identified' = 'all', | ||
| customEVFilterApplied = false, | ||
| ): Promise<object[]> { | ||
| let profileTypeFilter = '' | ||
| if (profileType === 'anonymous') { | ||
|
|
@@ -4948,42 +4949,94 @@ export class AnalyticsService { | |
| profileTypeFilter = `AND profileId LIKE '${AnalyticsService.PROFILE_PREFIX_USER}%'` | ||
| } | ||
|
|
||
| let allProfileDataCTE: string | ||
|
|
||
| if (customEVFilterApplied) { | ||
| allProfileDataCTE = ` | ||
| all_profile_data AS ( | ||
| SELECT | ||
| profileId, | ||
| psid, | ||
| cc, | ||
| os, | ||
| br, | ||
| dv, | ||
| created, | ||
| 1 AS isPageview, | ||
| 0 AS isEvent | ||
| FROM analytics | ||
| WHERE pid = {pid:FixedString(12)} | ||
| AND profileId IS NOT NULL | ||
| AND profileId != '' | ||
| ${profileTypeFilter} | ||
| AND profileId IN ( | ||
| SELECT DISTINCT profileId | ||
| FROM customEV | ||
| WHERE pid = {pid:FixedString(12)} | ||
| AND profileId IS NOT NULL | ||
| AND profileId != '' | ||
| ${profileTypeFilter} | ||
| ${filtersQuery} | ||
| ) | ||
| UNION ALL | ||
| SELECT | ||
| profileId, | ||
| psid, | ||
| cc, | ||
| os, | ||
| br, | ||
| dv, | ||
| created, | ||
| 0 AS isPageview, | ||
| 1 AS isEvent | ||
| FROM customEV | ||
| WHERE pid = {pid:FixedString(12)} | ||
| AND profileId IS NOT NULL | ||
| AND profileId != '' | ||
| ${profileTypeFilter} | ||
| ${filtersQuery} | ||
| )` | ||
| } else { | ||
| allProfileDataCTE = ` | ||
| all_profile_data AS ( | ||
| SELECT | ||
| profileId, | ||
| psid, | ||
| cc, | ||
| os, | ||
| br, | ||
| dv, | ||
| created, | ||
| 1 AS isPageview, | ||
| 0 AS isEvent | ||
| FROM analytics | ||
| WHERE pid = {pid:FixedString(12)} | ||
| AND profileId IS NOT NULL | ||
| AND profileId != '' | ||
| ${profileTypeFilter} | ||
| ${filtersQuery} | ||
| UNION ALL | ||
| SELECT | ||
| profileId, | ||
| psid, | ||
| cc, | ||
| os, | ||
| br, | ||
| dv, | ||
| created, | ||
| 0 AS isPageview, | ||
| 1 AS isEvent | ||
| FROM customEV | ||
| WHERE pid = {pid:FixedString(12)} | ||
| AND profileId IS NOT NULL | ||
| AND profileId != '' | ||
| ${profileTypeFilter} | ||
| ${filtersQuery} | ||
| )` | ||
|
Comment on lines
+4954
to
+5035
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Constrain
🐛 Proposed fix all_profile_data AS (
SELECT
profileId,
@@
FROM analytics
WHERE pid = {pid:FixedString(12)}
AND profileId IS NOT NULL
AND profileId != ''
${profileTypeFilter}
+ AND created BETWEEN {groupFrom:String} AND {groupTo:String}
AND profileId IN (
SELECT DISTINCT profileId
FROM customEV
WHERE pid = {pid:FixedString(12)}
AND profileId IS NOT NULL
AND profileId != ''
${profileTypeFilter}
+ AND created BETWEEN {groupFrom:String} AND {groupTo:String}
${filtersQuery}
)
@@
FROM customEV
WHERE pid = {pid:FixedString(12)}
AND profileId IS NOT NULL
AND profileId != ''
${profileTypeFilter}
+ AND created BETWEEN {groupFrom:String} AND {groupTo:String}
${filtersQuery}
)`
@@
all_profile_data AS (
SELECT
profileId,
@@
FROM analytics
WHERE pid = {pid:FixedString(12)}
AND profileId IS NOT NULL
AND profileId != ''
${profileTypeFilter}
+ AND created BETWEEN {groupFrom:String} AND {groupTo:String}
${filtersQuery}
@@
FROM customEV
WHERE pid = {pid:FixedString(12)}
AND profileId IS NOT NULL
AND profileId != ''
${profileTypeFilter}
+ AND created BETWEEN {groupFrom:String} AND {groupTo:String}
${filtersQuery}
)`🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
| const query = ` | ||
| WITH all_profile_data AS ( | ||
| SELECT | ||
| profileId, | ||
| psid, | ||
| cc, | ||
| os, | ||
| br, | ||
| dv, | ||
| created, | ||
| 1 AS isPageview, | ||
| 0 AS isEvent | ||
| FROM analytics | ||
| WHERE pid = {pid:FixedString(12)} | ||
| AND profileId IS NOT NULL | ||
| AND profileId != '' | ||
| ${profileTypeFilter} | ||
| ${filtersQuery} | ||
| UNION ALL | ||
| SELECT | ||
| profileId, | ||
| psid, | ||
| cc, | ||
| os, | ||
| br, | ||
| dv, | ||
| created, | ||
| 0 AS isPageview, | ||
| 1 AS isEvent | ||
| FROM customEV | ||
| WHERE pid = {pid:FixedString(12)} | ||
| AND profileId IS NOT NULL | ||
| AND profileId != '' | ||
| ${profileTypeFilter} | ||
| ${filtersQuery} | ||
| ), | ||
| WITH ${allProfileDataCTE}, | ||
| profile_aggregated AS ( | ||
| SELECT | ||
| profileId, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid mixing filtered event totals with unfiltered analytics totals.
In this branch,
${filtersQuery}is applied to thecustomEVarm but not to theanalyticsarm. Once a profile matches one filtered event, the row starts accumulating unfiltered pageviews/sessions whileeventsCountstays filtered, so the profile totals no longer describe the same slice of data.🤖 Prompt for AI Agents