@@ -1,20 +1,28 @@
|
||||
import { gtmHeadSnippet } from '@/lib/google-tag-manager'
|
||||
import { Metadata } from '@typebot.io/schemas'
|
||||
import Head from 'next/head'
|
||||
import Script from 'next/script'
|
||||
import React from 'react'
|
||||
import { isNotEmpty } from '@typebot.io/lib'
|
||||
import { getViewerUrl } from '@typebot.io/lib/getViewerUrl'
|
||||
import { Settings } from '@typebot.io/schemas'
|
||||
import { defaultSettings } from '@typebot.io/schemas/features/typebot/settings/constants'
|
||||
|
||||
type SEOProps = {
|
||||
url: string
|
||||
typebotName: string
|
||||
metadata: Metadata
|
||||
metadata?: Settings['metadata']
|
||||
}
|
||||
|
||||
export const SEO = ({
|
||||
url,
|
||||
typebotName,
|
||||
metadata: { title, description, favIconUrl, imageUrl, googleTagManagerId },
|
||||
metadata: {
|
||||
title,
|
||||
description,
|
||||
favIconUrl,
|
||||
imageUrl,
|
||||
googleTagManagerId,
|
||||
} = {},
|
||||
}: SEOProps) => (
|
||||
<>
|
||||
<Head key="seo">
|
||||
@@ -23,7 +31,7 @@ export const SEO = ({
|
||||
<link
|
||||
rel="icon"
|
||||
type="image/png"
|
||||
href={favIconUrl ?? 'https://viewer.typebot.io/favicon.png'}
|
||||
href={favIconUrl ?? defaultSettings.metadata.favIconUrl(getViewerUrl())}
|
||||
/>
|
||||
<meta name="title" content={title ?? typebotName} />
|
||||
<meta
|
||||
@@ -48,7 +56,7 @@ export const SEO = ({
|
||||
<meta
|
||||
property="og:image"
|
||||
itemProp="image"
|
||||
content={imageUrl ?? 'https://bot.typebot.io/site-preview.png'}
|
||||
content={imageUrl ?? defaultSettings.metadata.imageUrl(getViewerUrl())}
|
||||
/>
|
||||
|
||||
<meta property="twitter:card" content="summary_large_image" />
|
||||
@@ -63,7 +71,7 @@ export const SEO = ({
|
||||
/>
|
||||
<meta
|
||||
property="twitter:image"
|
||||
content={imageUrl ?? 'https://bot.typebot.io/site-preview.png'}
|
||||
content={imageUrl ?? defaultSettings.metadata.imageUrl(getViewerUrl())}
|
||||
/>
|
||||
</Head>
|
||||
{isNotEmpty(googleTagManagerId) && (
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
//@ts-ignore
|
||||
import { TypebotViewer } from 'bot-engine'
|
||||
import {
|
||||
AnswerInput,
|
||||
@@ -23,6 +25,7 @@ import {
|
||||
import { upsertAnswerQuery } from '@/features/answers/queries/upsertAnswerQuery'
|
||||
import { createResultQuery } from '@/features/results/queries/createResultQuery'
|
||||
import { updateResultQuery } from '@/features/results/queries/updateResultQuery'
|
||||
import { defaultSettings } from '@typebot.io/schemas/features/typebot/settings/constants'
|
||||
|
||||
export type TypebotPageProps = {
|
||||
publishedTypebot: Omit<PublicTypebot, 'createdAt' | 'updatedAt'> & {
|
||||
@@ -64,7 +67,7 @@ export const TypebotPageV2 = ({
|
||||
setPredefinedVariables(predefinedVariables)
|
||||
initializeResult().then()
|
||||
if (isDefined(customHeadCode)) injectCustomHeadCode(customHeadCode)
|
||||
const gtmId = publishedTypebot.settings.metadata.googleTagManagerId
|
||||
const gtmId = publishedTypebot.settings.metadata?.googleTagManagerId
|
||||
if (isNotEmpty(gtmId)) document.body.prepend(gtmBodyElement(gtmId))
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [])
|
||||
@@ -73,7 +76,8 @@ export const TypebotPageV2 = ({
|
||||
const hasQueryParams = asPath.includes('?')
|
||||
if (
|
||||
hasQueryParams &&
|
||||
publishedTypebot.settings.general.isHideQueryParamsEnabled !== false
|
||||
(publishedTypebot.settings.general?.isHideQueryParamsEnabled ??
|
||||
defaultSettings.general.isHideQueryParamsEnabled) !== false
|
||||
)
|
||||
push(asPath.split('?')[0], undefined, { shallow: true })
|
||||
}
|
||||
@@ -91,7 +95,8 @@ export const TypebotPageV2 = ({
|
||||
if (data?.result) {
|
||||
setResultId(data.result.id)
|
||||
if (
|
||||
publishedTypebot.settings.general.isNewResultOnRefreshEnabled !== true
|
||||
publishedTypebot.settings.general?.isNewResultOnRefreshEnabled !==
|
||||
true
|
||||
)
|
||||
setResultInSession(data.result.id)
|
||||
}
|
||||
|
||||
@@ -2,14 +2,15 @@ import { Standard } from '@typebot.io/nextjs'
|
||||
import { useRouter } from 'next/router'
|
||||
import { SEO } from './Seo'
|
||||
import { Typebot } from '@typebot.io/schemas/features/typebot/typebot'
|
||||
import { BackgroundType } from '@typebot.io/schemas/features/typebot/theme/enums'
|
||||
import { BackgroundType } from '@typebot.io/schemas/features/typebot/theme/constants'
|
||||
import { defaultSettings } from '@typebot.io/schemas/features/typebot/settings/constants'
|
||||
|
||||
export type TypebotV3PageProps = {
|
||||
url: string
|
||||
name: string
|
||||
publicId: string | null
|
||||
isHideQueryParamsEnabled: boolean | null
|
||||
background: Typebot['theme']['general']['background']
|
||||
background: NonNullable<Typebot['theme']['general']>['background']
|
||||
metadata: Typebot['settings']['metadata']
|
||||
}
|
||||
|
||||
@@ -25,7 +26,14 @@ export const TypebotPageV3 = ({
|
||||
|
||||
const clearQueryParamsIfNecessary = () => {
|
||||
const hasQueryParams = asPath.includes('?')
|
||||
if (!hasQueryParams || !(isHideQueryParamsEnabled ?? true)) return
|
||||
if (
|
||||
!hasQueryParams ||
|
||||
!(
|
||||
isHideQueryParamsEnabled ??
|
||||
defaultSettings.general.isHideQueryParamsEnabled
|
||||
)
|
||||
)
|
||||
return
|
||||
push(asPath.split('?')[0], undefined, { shallow: true })
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user