diff --git a/package-lock.json b/package-lock.json index 347ab5210..c35b7077b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -48297,7 +48297,7 @@ }, "packages/components": { "name": "@portaljs/components", - "version": "0.4.0", + "version": "0.5.3", "dependencies": { "@githubocto/flat-ui": "^0.14.1", "@heroicons/react": "^2.0.17", diff --git a/packages/core/package.json b/packages/core/package.json index be989016b..72de0c00d 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@portaljs/core", - "version": "1.0.8", + "version": "1.0.9", "description": "Core Portal.JS components, configs and utils.", "repository": { "type": "git", diff --git a/packages/core/src/ui/analytics/GoogleAnalytics.tsx b/packages/core/src/ui/analytics/GoogleAnalytics.tsx new file mode 100644 index 000000000..9130cb560 --- /dev/null +++ b/packages/core/src/ui/analytics/GoogleAnalytics.tsx @@ -0,0 +1,36 @@ +import Script from 'next/script.js' + +export interface GoogleAnalyticsProps { + googleAnalyticsId: string +} + +export const GA = ({ googleAnalyticsId }: GoogleAnalyticsProps) => { + return ( + <> + + + ) +} + +// https://developers.google.com/analytics/devguides/collection/gtagjs/events +export const logEvent = (action, category, label, value) => { + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + window.gtag?.('event', action, { + event_category: category, + event_label: label, + value: value, + }) +} diff --git a/packages/core/src/ui/analytics/Plausible.tsx b/packages/core/src/ui/analytics/Plausible.tsx new file mode 100644 index 000000000..9b2361bf6 --- /dev/null +++ b/packages/core/src/ui/analytics/Plausible.tsx @@ -0,0 +1,41 @@ +import Script from 'next/script.js' + +export interface PlausibleProps { + plausibleDataDomain: string + dataApi?: string + src?: string +} + +/** + * Plausible analytics component. + * To proxy the requests through your own domain, you can use the dataApi and src attribute. + * See [Plausible docs](https://plausible.io/docs/proxy/guides/nextjs#step-2-adjust-your-deployed-script) + * for more information. + * + */ +export const Plausible = ({ + plausibleDataDomain, + dataApi = undefined, + src = 'https://plausible.io/js/plausible.js', +}: PlausibleProps) => { + return ( + <> + + + ) +} + +// https://plausible.io/docs/custom-event-goals +export const logEvent = (eventName, ...rest) => { + return window.plausible?.(eventName, ...rest) +} diff --git a/packages/core/src/ui/analytics/Posthog.tsx b/packages/core/src/ui/analytics/Posthog.tsx new file mode 100644 index 000000000..51b3066fd --- /dev/null +++ b/packages/core/src/ui/analytics/Posthog.tsx @@ -0,0 +1,25 @@ +import Script from 'next/script.js' + +export interface PosthogProps { + posthogProjectApiKey: string + apiHost?: string +} + +/** + * Posthog analytics component. + * See [Posthog docs](https://posthog.com/docs/libraries/js#option-1-add-javascript-snippet-to-your-html-badgerecommendedbadge) for more information. + * + */ +export const Posthog = ({ + posthogProjectApiKey, + apiHost = 'https://app.posthog.com', +}: PosthogProps) => { + return ( + + ) +} diff --git a/packages/core/src/ui/analytics/SimpleAnalytics.tsx b/packages/core/src/ui/analytics/SimpleAnalytics.tsx new file mode 100644 index 000000000..49096c209 --- /dev/null +++ b/packages/core/src/ui/analytics/SimpleAnalytics.tsx @@ -0,0 +1,29 @@ +import Script from 'next/script.js' + +export interface SimpleAnalyticsProps { + src?: string +} + +export const SimpleAnalytics = ({ + src = 'https://scripts.simpleanalyticscdn.com/latest.js', +}: SimpleAnalyticsProps) => { + return ( + <> + +