Make trackingId begin with GTM- always (#8937)

Co-authored-by: Joe Au-Yeung <65426560+joeauyeung@users.noreply.github.com>
Co-authored-by: Omar López <zomars@me.com>
This commit is contained in:
Hariom Balhara
2023-05-29 20:30:02 -07:00
committed by GitHub
co-authored by Joe Au-Yeung Omar López
parent dd94653a48
commit d5746ed277
2 changed files with 7 additions and 2 deletions
+1 -1
View File
@@ -14,7 +14,7 @@
"tag": {
"scripts": [
{
"content": "(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src='https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);})(window,document,'script','dataLayer','GTM-{TRACKING_ID}');"
"content": "(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src='https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);})(window,document,'script','dataLayer','{TRACKING_ID}');"
}
]
}
+6 -1
View File
@@ -4,7 +4,12 @@ import { eventTypeAppCardZod } from "@calcom/app-store/eventTypeAppCardZod";
export const appDataSchema = eventTypeAppCardZod.merge(
z.object({
trackingId: z.string(),
trackingId: z.string().transform((val) => {
let trackingId = val.trim();
// Ensure that trackingId is transformed if needed to begin with "GTM-" always
trackingId = !trackingId.startsWith("GTM-") ? `GTM-${trackingId}` : trackingId;
return trackingId;
}),
})
);