From b8905b126aa8c6a941f40a0973675e62f3b04c33 Mon Sep 17 00:00:00 2001 From: Igor Brasileiro Date: Thu, 6 Jul 2023 15:51:17 -0300 Subject: [PATCH] feat: Add GTAG scripts (#138) --- components/Analytics.tsx | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/components/Analytics.tsx b/components/Analytics.tsx index e79044a2..c869cfdd 100644 --- a/components/Analytics.tsx +++ b/components/Analytics.tsx @@ -1,5 +1,6 @@ import { context } from "$live/live.ts"; import GoogleTagManager from "partytown/integrations/GTM.tsx"; +import GoogleTagScript from "partytown/integrations/GTAG.tsx"; import Script from "partytown/Script.tsx"; import { sendAnalyticsEvent } from "../commerce/sdk/sendAnalyticsEvent.ts"; @@ -8,6 +9,12 @@ export interface Props { * @description google tag manager container id. For more info: https://developers.google.com/tag-platform/tag-manager/web#standard_web_page_installation . */ trackingIds?: string[]; + /** + * @title GA Measurement Ids + * @label measurement id + * @description the google analytics property measurement id. For more info: https://support.google.com/analytics/answer/9539598 + */ + googleAnalyticsIds?: string[]; /** * @description custom url for serving google tag manager. Set either this url or the tracking id */ @@ -19,13 +26,14 @@ export interface Props { } export default function Analtyics( - { trackingIds, src, dangerouslyRunOnMainThread }: Props, + { trackingIds, src, dangerouslyRunOnMainThread, googleAnalyticsIds }: Props, ) { + const isDeploy = !!context.isDeploy; return ( <> {/* TODO: Add debug from query string @author Igor Brasileiro */} {/* Add Tag Manager script during production only. To test it locally remove the condition */} - {!!context.deploymentId && trackingIds && ( + {isDeploy && trackingIds && ( trackingIds.map((trackingId) => ( )) )} - {!!context.deploymentId && src && ( + {isDeploy && googleAnalyticsIds && ( + googleAnalyticsIds.map((trackingId) => ( + + )) + )} + {isDeploy && src && (