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.

update dicebear to use svg

Steven Tey935834f48553
diff --git a/apps/web/lib/analytics/get-events.ts b/apps/web/lib/analytics/get-events.ts
index 084ca3abf6..1bea3c7e78 100644
--- a/apps/web/lib/analytics/get-events.ts
+++ b/apps/web/lib/analytics/get-events.ts
@@ -2,6 +2,7 @@ import { tb } from "@/lib/tinybird";
import { prisma } from "@dub/prisma";
import { Link } from "@dub/prisma/client";
import { transformLink } from "../api/links";
+import { generateRandomName } from "../names";
import { tbDemo } from "../tinybird/demo-client";
import z from "../zod";
import { eventsFilterTB } from "../zod/schemas/analytics";
@@ -200,16 +201,14 @@ const getCustomersMap = async (customerIds: string[]) => {
return customers.reduce(
(acc, customer) => {
- // TODO:
- // Can we do CustomerSchema.parse(customer) instead?
acc[customer.id] = CustomerSchema.parse({
id: customer.id,
externalId: customer.externalId,
- name: customer.name || "",
+ name: customer.name || customer.email || generateRandomName(),
email: customer.email || "",
avatar:
customer.avatar ||
- `https://api.dicebear.com/9.x/notionists/png?seed=${customer.id}`,
+ `https://api.dicebear.com/9.x/notionists/svg?seed=${customer.id}`,
country: customer.country || "",
createdAt: customer.createdAt,
});
diff --git a/apps/web/lib/api/customers/get-customer-or-throw.ts b/apps/web/lib/api/customers/get-customer-or-throw.ts
index 7d67561d73..3fa9f2ac18 100644
--- a/apps/web/lib/api/customers/get-customer-or-throw.ts
+++ b/apps/web/lib/api/customers/get-customer-or-throw.ts
@@ -54,7 +54,7 @@ export const getCustomerOrThrow = async (
}
if (!customer.avatar) {
- customer.avatar = `https://api.dicebear.com/9.x/notionists/png?seed=${customer.id}`;
+ customer.avatar = `https://api.dicebear.com/9.x/notionists/svg?seed=${customer.id}`;
}
return customer;
diff --git a/apps/web/lib/rewardful/import-referrals.ts b/apps/web/lib/rewardful/import-referrals.ts
index 9f7be70eb3..eb7e925de5 100644
--- a/apps/web/lib/rewardful/import-referrals.ts
+++ b/apps/web/lib/rewardful/import-referrals.ts
@@ -5,7 +5,7 @@ import { nanoid } from "@dub/utils";
import { Program, Project } from "@prisma/client";
import { createId } from "../api/utils";
import { recordClick } from "../tinybird/record-click";
-import { recordLead } from "../tinybird/record-lead";
+import { recordLeadWithTimestamp } from "../tinybird/record-lead";
import { clickEventSchemaTB } from "../zod/schemas/clicks";
import { RewardfulApi } from "./api";
import { MAX_BATCHES, rewardfulImporter } from "./importer";
@@ -173,11 +173,12 @@ async function createReferral({
},
}),
- recordLead({
+ recordLeadWithTimestamp({
...clickEvent,
event_id: nanoid(16),
event_name: "Sign up",
customer_id: customerId,
+ timestamp: new Date(referral.became_lead_at).toISOString(),
}),
prisma.link.update({
diff --git a/apps/web/lib/tinybird/record-lead.ts b/apps/web/lib/tinybird/record-lead.ts
index 5e11e52f66..4f476b3119 100644
--- a/apps/web/lib/tinybird/record-lead.ts
+++ b/apps/web/lib/tinybird/record-lead.ts
@@ -1,3 +1,4 @@
+import { z } from "zod";
import { leadEventSchemaTB } from "../zod/schemas/leads";
import { tb } from "./client";
@@ -5,3 +6,10 @@ export const recordLead = tb.buildIngestEndpoint({
datasource: "dub_lead_events",
event: leadEventSchemaTB,
});
+
+export const recordLeadWithTimestamp = tb.buildIngestEndpoint({
+ datasource: "dub_lead_events",
+ event: leadEventSchemaTB.extend({
+ timestamp: z.string(),
+ }),
+});
diff --git a/apps/web/lib/webhook/sample-events/lead-created.json b/apps/web/lib/webhook/sample-events/lead-created.json
index d46d5ff55a..209cdedee9 100644
--- a/apps/web/lib/webhook/sample-events/lead-created.json
+++ b/apps/web/lib/webhook/sample-events/lead-created.json
@@ -5,7 +5,7 @@
"externalId": "cus_BH6tDUWc9n0Y2pf55tVbk1hc",
"name": "Tiny Beige Badger",
"email": "[email protected]",
- "avatar": "https://api.dicebear.com/9.x/notionists/png?seed=cus_BH6tDUWc9n0Y2pf55tVbk1hc",
+ "avatar": "https://api.dicebear.com/9.x/notionists/svg?seed=cus_BH6tDUWc9n0Y2pf55tVbk1hc",
"createdAt": "2025-01-14T04:49:23.385Z"
},
"click": {
diff --git a/apps/web/lib/webhook/sample-events/sale-created.json b/apps/web/lib/webhook/sample-events/sale-created.json
index e3c8162ff9..27163a2f67 100644
--- a/apps/web/lib/webhook/sample-events/sale-created.json
+++ b/apps/web/lib/webhook/sample-events/sale-created.json
@@ -5,7 +5,7 @@
"externalId": "cus_jTrfVKYN3Buc3F80JoqBiY0g",
"name": "Rural Red Goldfish",
"email": "[email protected]",
- "avatar": "https://api.dicebear.com/9.x/notionists/png?seed=cus_jTrfVKYN3Buc3F80JoqBiY0g",
+ "avatar": "https://api.dicebear.com/9.x/notionists/svg?seed=cus_jTrfVKYN3Buc3F80JoqBiY0g",
"createdAt": "2024-10-12T04:55:36.007Z"
},
"click": {
diff --git a/apps/web/lib/zod/schemas/leads.ts b/apps/web/lib/zod/schemas/leads.ts
index 62c3be27a4..f7f85e2c56 100644
--- a/apps/web/lib/zod/schemas/leads.ts
+++ b/apps/web/lib/zod/schemas/leads.ts
@@ -76,7 +76,7 @@ export const trackLeadResponseSchema = z.object({
export const leadEventSchemaTB = clickEventSchemaTB
.omit({ timestamp: true }) // remove timestamp from lead data because tinybird will generate its own at ingestion time
- .and(
+ .merge(
z.object({
event_id: z.string(),
event_name: z.string(),
diff --git a/apps/web/tests/utils/helpers.ts b/apps/web/tests/utils/helpers.ts
index ba002698c0..27ee792563 100644
--- a/apps/web/tests/utils/helpers.ts
+++ b/apps/web/tests/utils/helpers.ts
@@ -12,7 +12,7 @@ export const randomCustomer = () => {
id: customerId,
name: customerName,
email: `${customerName.split(" ").join(".").toLowerCase()}@example.com`,
- avatar: `https://api.dicebear.com/9.x/notionists/png?seed=${customerId}`,
+ avatar: `https://api.dicebear.com/9.x/notionists/svg?seed=${customerId}`,
};
};