Add external analytics url.

This commit is contained in:
Brian Cao 2023-09-18 09:51:43 -07:00
parent 7b97209d56
commit 84e13a2a10
3 changed files with 7 additions and 8 deletions

5
.gitignore vendored
View File

@ -33,10 +33,7 @@ yarn-debug.log*
yarn-error.log*
# local env files
.env
.env.development.local
.env.test.local
.env.production.local
*.env
*.dev.yml

View File

@ -3,7 +3,7 @@ import useMessages from 'components/hooks/useMessages';
import useConfig from 'components/hooks/useConfig';
import { useRouter } from 'next/router';
export function TrackingCode({ websiteId }) {
export function TrackingCode({ websiteId, analyticsUrl }) {
const { formatMessage, messages } = useMessages();
const { basePath } = useRouter();
const config = useConfig();
@ -13,7 +13,9 @@ export function TrackingCode({ websiteId }) {
const url = trackerScriptName?.startsWith('http')
? trackerScriptName
: `${process.env.analyticsUrl || location.origin}${basePath}/${trackerScriptName}`;
: `${
analyticsUrl || process.env.analyticsUrl || location.origin
}${basePath}/${trackerScriptName}`;
const code = `<script async src="${url}" data-website-id="${websiteId}"></script>`;

View File

@ -11,7 +11,7 @@ import ShareUrl from 'components/pages/settings/websites/ShareUrl';
import useApi from 'components/hooks/useApi';
import useMessages from 'components/hooks/useMessages';
export function WebsiteSettings({ websiteId, openExternal = false }) {
export function WebsiteSettings({ websiteId, openExternal = false, analyticsUrl }) {
const router = useRouter();
const { formatMessage, labels, messages } = useMessages();
const { get, useQuery } = useApi();
@ -68,7 +68,7 @@ export function WebsiteSettings({ websiteId, openExternal = false }) {
{tab === 'details' && (
<WebsiteEditForm websiteId={websiteId} data={values} onSave={handleSave} />
)}
{tab === 'tracking' && <TrackingCode websiteId={websiteId} data={values} />}
{tab === 'tracking' && <TrackingCode websiteId={websiteId} analyticsUrl={analyticsUrl} />}
{tab === 'share' && <ShareUrl websiteId={websiteId} data={values} onSave={handleSave} />}
{tab === 'data' && <WebsiteData websiteId={websiteId} onSave={handleReset} />}
</Page>