Skip to content

Commit

Permalink
Merge branch 'analytics' of https://github.com/umami-software/umami i…
Browse files Browse the repository at this point in the history
…nto qa
  • Loading branch information
franciscao633 committed Oct 21, 2024
2 parents 7f15c82 + 9a5d18f commit 498245d
Show file tree
Hide file tree
Showing 95 changed files with 14,359 additions and 625 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/cd-cloud.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Create docker images

on:
push:
branches:
- analytics

jobs:
build:
name: Build, push, and deploy
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Generate random hash
id: random_hash
run: echo "hash=$(openssl rand -hex 4)" >> $GITHUB_OUTPUT

- uses: mr-smithers-excellent/docker-build-push@v6
name: Build & push Docker image to docker.io
with:
image: umamisoftware/umami
tags: cloud-${{ steps.random_hash.outputs.hash }}, cloud-latest
buildArgs: DATABASE_TYPE=postgresql
registry: docker.io
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
77 changes: 77 additions & 0 deletions db/clickhouse/migrations/04_add_tag.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
-- add tag column
ALTER TABLE umami.website_event ADD COLUMN "tag" String AFTER "event_name";
ALTER TABLE umami.website_event_stats_hourly ADD COLUMN "tag" SimpleAggregateFunction(groupArrayArray, Array(String)) AFTER "max_time";

-- update materialized view
DROP TABLE umami.website_event_stats_hourly_mv;

CREATE MATERIALIZED VIEW umami.website_event_stats_hourly_mv
TO umami.website_event_stats_hourly
AS
SELECT
website_id,
session_id,
visit_id,
hostname,
browser,
os,
device,
screen,
language,
country,
subdivision1,
city,
entry_url,
exit_url,
url_paths as url_path,
url_query,
referrer_domain,
page_title,
event_type,
event_name,
views,
min_time,
max_time,
tag,
timestamp as created_at
FROM (SELECT
website_id,
session_id,
visit_id,
hostname,
browser,
os,
device,
screen,
language,
country,
subdivision1,
city,
argMinState(url_path, created_at) entry_url,
argMaxState(url_path, created_at) exit_url,
arrayFilter(x -> x != '', groupArray(url_path)) as url_paths,
arrayFilter(x -> x != '', groupArray(url_query)) url_query,
arrayFilter(x -> x != '', groupArray(referrer_domain)) referrer_domain,
arrayFilter(x -> x != '', groupArray(page_title)) page_title,
event_type,
if(event_type = 2, groupArray(event_name), []) event_name,
sumIf(1, event_type = 1) views,
min(created_at) min_time,
max(created_at) max_time,
arrayFilter(x -> x != '', groupArray(tag)) tag,
toStartOfHour(created_at) timestamp
FROM umami.website_event
GROUP BY website_id,
session_id,
visit_id,
hostname,
browser,
os,
device,
screen,
language,
country,
subdivision1,
city,
event_type,
timestamp);
4 changes: 4 additions & 0 deletions db/clickhouse/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ CREATE TABLE umami.website_event
--events
event_type UInt32,
event_name String,
tag String,
created_at DateTime('UTC'),
job_id Nullable(UUID)
)
Expand Down Expand Up @@ -96,6 +97,7 @@ CREATE TABLE umami.website_event_stats_hourly
views SimpleAggregateFunction(sum, UInt64),
min_time SimpleAggregateFunction(min, DateTime('UTC')),
max_time SimpleAggregateFunction(max, DateTime('UTC')),
tag SimpleAggregateFunction(groupArrayArray, Array(String)),
created_at Datetime('UTC')
)
ENGINE = AggregatingMergeTree
Expand Down Expand Up @@ -136,6 +138,7 @@ SELECT
views,
min_time,
max_time,
tag,
timestamp as created_at
FROM (SELECT
website_id,
Expand All @@ -161,6 +164,7 @@ FROM (SELECT
sumIf(1, event_type = 1) views,
min(created_at) min_time,
max(created_at) max_time,
arrayFilter(x -> x != '', groupArray(tag)) tag,
toStartOfHour(created_at) timestamp
FROM umami.website_event
GROUP BY website_id,
Expand Down
5 changes: 5 additions & 0 deletions db/mysql/migrations/07_add_tag/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- AlterTable
ALTER TABLE `website_event` ADD COLUMN `tag` VARCHAR(50) NULL;

-- CreateIndex
CREATE INDEX `website_event_website_id_created_at_tag_idx` ON `website_event`(`website_id`, `created_at`, `tag`);
2 changes: 2 additions & 0 deletions db/mysql/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ model WebsiteEvent {
pageTitle String? @map("page_title") @db.VarChar(500)
eventType Int @default(1) @map("event_type") @db.UnsignedInt
eventName String? @map("event_name") @db.VarChar(50)
tag String? @db.VarChar(50)
eventData EventData[]
session Session @relation(fields: [sessionId], references: [id])
Expand All @@ -116,6 +117,7 @@ model WebsiteEvent {
@@index([websiteId, createdAt, referrerDomain])
@@index([websiteId, createdAt, pageTitle])
@@index([websiteId, createdAt, eventName])
@@index([websiteId, createdAt, tag])
@@index([websiteId, sessionId, createdAt])
@@index([websiteId, visitId, createdAt])
@@map("website_event")
Expand Down
5 changes: 5 additions & 0 deletions db/postgresql/migrations/07_add_tag/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- AlterTable
ALTER TABLE "website_event" ADD COLUMN "tag" VARCHAR(50);

-- CreateIndex
CREATE INDEX "website_event_website_id_created_at_tag_idx" ON "website_event"("website_id", "created_at", "tag");
3 changes: 3 additions & 0 deletions db/postgresql/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ model WebsiteEvent {
pageTitle String? @map("page_title") @db.VarChar(500)
eventType Int @default(1) @map("event_type") @db.Integer
eventName String? @map("event_name") @db.VarChar(50)
tag String? @db.VarChar(50)
eventData EventData[]
session Session @relation(fields: [sessionId], references: [id])
Expand All @@ -111,11 +112,13 @@ model WebsiteEvent {
@@index([visitId])
@@index([websiteId])
@@index([websiteId, createdAt])
@@index([websiteId, createdAt, urlPath])
@@index([websiteId, createdAt, urlQuery])
@@index([websiteId, createdAt, referrerDomain])
@@index([websiteId, createdAt, pageTitle])
@@index([websiteId, createdAt, eventName])
@@index([websiteId, createdAt, tag])
@@index([websiteId, sessionId, createdAt])
@@index([websiteId, visitId, createdAt])
@@map("website_event")
Expand Down
2 changes: 1 addition & 1 deletion next-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
/// <reference types="next/navigation-types/compat/navigation" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
// see https://nextjs.org/docs/app/building-your-application/configuring/typescript for more information.
6 changes: 5 additions & 1 deletion next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ if (trackerScriptName) {
names.forEach(name => {
rewrites.push({
source: `/${name.replace(/^\/+/, '')}`,
destination: '/script.js',
destination: '/tracker.js',
});
});
}
Expand Down Expand Up @@ -163,6 +163,10 @@ const config = {
async rewrites() {
return [
...rewrites,
{
source: '/script.js',
destination: 'https://tracker-script.umami.dev/',
},
{
source: '/telemetry.js',
destination: '/api/scripts/telemetry',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
"maxmind": "^4.3.6",
"md5": "^2.3.0",
"moment-timezone": "^0.5.35",
"next": "14.2.5",
"next": "14.2.10",
"next-basics": "^0.39.0",
"node-fetch": "^3.2.8",
"npm-run-all": "^4.1.5",
Expand Down
13,371 changes: 13,191 additions & 180 deletions public/datamaps.world.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions public/intl/messages/ko-KR.json
Original file line number Diff line number Diff line change
Expand Up @@ -1012,7 +1012,7 @@
"label.retention-description": [
{
"type": 0,
"value": "사용자가 얼마나 자주 돌아오는지를 추적하여 웹사이트의 리텐션을 측정하십시오."
"value": "사용자가 얼마나 자주 돌아오는지를 추적하여 웹사이트의 리텐션을 측정하세요."
}
],
"label.revenue": [
Expand Down Expand Up @@ -1372,7 +1372,7 @@
"label.utm-description": [
{
"type": 0,
"value": "UTM 매개변수를 통해 캠페인을 추적합니다."
"value": "UTM 매개변수를 통해 캠페인을 추적하세요."
}
],
"label.value": [
Expand Down Expand Up @@ -1414,7 +1414,7 @@
"label.visit-duration": [
{
"type": 0,
"value": "평균 방문 시간"
"value": "방문 시간"
}
],
"label.visitors": [
Expand Down Expand Up @@ -1548,7 +1548,7 @@
"message.error": [
{
"type": 0,
"value": "오류가 발생했습니다."
"value": "문제가 발생했습니다."
}
],
"message.event-log": [
Expand Down
2 changes: 1 addition & 1 deletion rollup.tracker.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { terser } from 'rollup-plugin-terser';
export default {
input: 'src/tracker/index.js',
output: {
file: 'public/script.js',
file: 'public/tracker.js',
format: 'iife',
},
plugins: [
Expand Down
6 changes: 3 additions & 3 deletions scripts/telemetry.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ async function sendTelemetry(type) {
node: process.version,
platform: os.platform(),
arch: os.arch(),
os: `${os.type()} (${os.version()})`,
isDocker: isDocker(),
isCi: isCI,
os: `${os.type()} ${os.version()}`,
is_docker: isDocker(),
is_ci: isCI,
},
};

Expand Down
54 changes: 53 additions & 1 deletion src/app/(main)/console/TestConsole.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,46 @@ export function TestConsole({ websiteId }: { websiteId: string }) {
});
}

function handleRunRevenue() {
window['umami'].track(props => ({
...props,
url: '/checkout-cart',
referrer: 'https://www.google.com',
}));
window['umami'].track('checkout-cart', {
revenue: parseFloat((Math.random() * 1000).toFixed(2)),
currency: 'USD',
});
window['umami'].track('affiliate-link', {
revenue: parseFloat((Math.random() * 1000).toFixed(2)),
currency: 'USD',
});
window['umami'].track('promotion-link', {
revenue: parseFloat((Math.random() * 1000).toFixed(2)),
currency: 'USD',
});
window['umami'].track('checkout-cart', {
revenue: parseFloat((Math.random() * 1000).toFixed(2)),
currency: 'EUR',
});
window['umami'].track('promotion-link', {
revenue: parseFloat((Math.random() * 1000).toFixed(2)),
currency: 'EUR',
});
window['umami'].track('affiliate-link', {
item1: {
productIdentity: 'ABC424',
revenue: parseFloat((Math.random() * 10000).toFixed(2)),
currency: 'JPY',
},
item2: {
productIdentity: 'ZYW684',
revenue: parseFloat((Math.random() * 10000).toFixed(2)),
currency: 'JPY',
},
});
}

function handleRunIdentify() {
window['umami'].identify({
userId: 123,
Expand Down Expand Up @@ -127,10 +167,19 @@ export function TestConsole({ websiteId }: { websiteId: string }) {
>
Send event with data
</Button>
<Button
id="generate-revenue-button"
data-umami-event="checkout-cart"
data-umami-event-revenue={(Math.random() * 10000).toFixed(2).toString()}
data-umami-event-currency="USD"
variant="primary"
>
Generate revenue data
</Button>
<Button
id="button-with-div-button"
data-umami-event="button-click"
data-umami-event-name="bob"
data-umami-event-name={'bob'}
data-umami-event-id="123"
variant="primary"
>
Expand All @@ -155,6 +204,9 @@ export function TestConsole({ websiteId }: { websiteId: string }) {
<Button id="manual-button" variant="primary" onClick={handleRunIdentify}>
Run identify
</Button>
<Button id="manual-button" variant="primary" onClick={handleRunRevenue}>
Revenue script
</Button>
</div>
</div>
<WebsiteChart websiteId={website.id} />
Expand Down
13 changes: 7 additions & 6 deletions src/app/(main)/reports/create/ReportTemplates.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Funnel from 'assets/funnel.svg';
import Money from 'assets/money.svg';
import Lightbulb from 'assets/lightbulb.svg';
import Magnet from 'assets/magnet.svg';
import Path from 'assets/path.svg';
Expand Down Expand Up @@ -51,12 +52,12 @@ export function ReportTemplates({ showHeader = true }: { showHeader?: boolean })
url: renderTeamUrl('/reports/journey'),
icon: <Path />,
},
// {
// title: formatMessage(labels.revenue),
// description: formatMessage(labels.revenueDescription),
// url: renderTeamUrl('/reports/revenue'),
// icon: <Money />,
// },
{
title: formatMessage(labels.revenue),
description: formatMessage(labels.revenueDescription),
url: renderTeamUrl('/reports/revenue'),
icon: <Money />,
},
];

return (
Expand Down
Loading

0 comments on commit 498245d

Please sign in to comment.