Skip to content

Commit

Permalink
🐛 (ga) Fix gtag not initializing properly
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Jul 11, 2023
1 parent 5587bfb commit 8ce5447
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ export const GoogleAnalyticsSettings = ({
return (
<Stack spacing={4}>
<TextInput
label="Tracking ID:"
label="Measurement ID:"
moreInfoTooltip="Can be found by clicking on your data stream in Google Analytics dashboard"
defaultValue={options?.trackingId ?? ''}
placeholder="G-123456..."
onChange={updateTrackingId}
Expand Down
2 changes: 1 addition & 1 deletion packages/embeds/js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@typebot.io/js",
"version": "0.0.69",
"version": "0.0.70",
"description": "Javascript library to display typebots on your website",
"type": "module",
"main": "dist/index.js",
Expand Down
30 changes: 18 additions & 12 deletions packages/embeds/js/src/lib/gtag.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
import { isDefined, isEmpty } from '@typebot.io/lib/utils'
import type { GoogleAnalyticsOptions } from '@typebot.io/schemas'

declare const gtag: (
type: string,
action: string | undefined,
options: {
event_category: string | undefined
event_label: string | undefined
value: number | undefined
send_to: string | undefined
}
) => void
declare const window: {
gtag?: (
type: string,
action: string | undefined,
options: {
event_category: string | undefined
event_label: string | undefined
value: number | undefined
send_to: string | undefined
}
) => void
}

export const initGoogleAnalytics = (id: string): Promise<void> => {
if (isDefined(gtag)) return Promise.resolve()
if (isDefined(window.gtag)) return Promise.resolve()
return new Promise((resolve) => {
const existingScript = document.getElementById('gtag')
if (!existingScript) {
Expand All @@ -39,7 +41,11 @@ export const initGoogleAnalytics = (id: string): Promise<void> => {

export const sendGaEvent = (options: GoogleAnalyticsOptions) => {
if (!options) return
gtag('event', options.action, {
if (!window.gtag) {
console.error('Google Analytics was not properly initialized')
return
}
window.gtag('event', options.action, {
event_category: isEmpty(options.category) ? undefined : options.category,
event_label: isEmpty(options.label) ? undefined : options.label,
value: options.value as number,
Expand Down
22 changes: 14 additions & 8 deletions packages/embeds/js/src/lib/pixel.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { PixelBlock } from '@typebot.io/schemas'

declare const fbq: (
arg0: string,
arg1: string,
arg2: string,
arg3: Record<string, string> | undefined
) => void
declare const window: {
fbq?: (
arg0: string,
arg1: string,
arg2: string,
arg3: Record<string, string> | undefined
) => void
}

export const initPixel = (pixelId: string) => {
const script = document.createElement('script')
Expand All @@ -28,6 +30,10 @@ export const initPixel = (pixelId: string) => {

export const trackPixelEvent = (options: PixelBlock['options']) => {
if (!options.eventType || !options.pixelId) return
if (!window.fbq) {
console.error('Facebook Pixel was not properly initialized')
return
}
const params = options.params?.length
? options.params.reduce<Record<string, string>>((obj, param) => {
if (!param.key || !param.value) return obj
Expand All @@ -36,7 +42,7 @@ export const trackPixelEvent = (options: PixelBlock['options']) => {
: undefined
if (options.eventType === 'Custom') {
if (!options.name) return
fbq('trackCustom', options.pixelId, options.name, params)
window.fbq('trackCustom', options.pixelId, options.name, params)
}
fbq('track', options.pixelId, options.eventType, params)
window.fbq('track', options.pixelId, options.eventType, params)
}
2 changes: 1 addition & 1 deletion packages/embeds/react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@typebot.io/react",
"version": "0.0.69",
"version": "0.0.70",
"description": "React library to display typebots on your website",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down

4 comments on commit 8ce5447

@vercel
Copy link

@vercel vercel bot commented on 8ce5447 Jul 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 8ce5447 Jul 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

builder-v2 – ./apps/builder

builder-v2-typebot-io.vercel.app
builder-v2-git-main-typebot-io.vercel.app
app.typebot.io

@vercel
Copy link

@vercel vercel bot commented on 8ce5447 Jul 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

viewer-v2 – ./apps/viewer

bot.wphelpchat.com
bots.robomotion.io
cadu.uninta.edu.br
chat.hand-made.one
chat.tuanpakya.com
chat.webisharp.com
dicanatural.online
digitalhelp.com.au
goalsettingbot.com
noticiasnet.online
omarcodosanjos.com
pant.maxbot.com.br
pantherview.cr8.ai
positivobra.com.br
rollingball.cr8.ai
sub.yolozeeeer.com
survey.digienge.io
zap.techadviser.in
ai.digitaldaftar.in
app.danielnalex.com
ask.realversity.org
bot.boston-voip.com
bot.cabinpromos.com
bot.carnaval.studio
bot.digitalbled.com
bot.dsignagency.com
bot.enthrallart.com
bot.eventhub.com.au
bot.gravityatoms.in
bot.jepierre.com.br
bot.leadgenpod.site
bot.ltmidias.com.br
bot.viralsangat.com
bot.winglabs.com.br
capitaldigital.live
carsalesenquiry.com
chat.marius.digital
chat.sr7digital.com
chatbot.matthesv.de
chatbot.repplai.com
demo.botscientis.us
demo.wemakebots.xyz
hrbot.robomotion.io
inearephones.cr8.ai
kbsub.wpwakanda.com
limitenahora.com.br
live.botscientis.us
mdb.evento.progenbr.com
prebook.enthrallart.com
primitive-shapes.cr8.ai
register.kandabrand.com
sell.sellitwithgary.com
signup.hypemarketing.in
sistemacanadense.online
subfooter.wpwakanda.com
survey.hypemarketing.in
testbot.afterorigin.com
typebot.influencer.love
www.chatgpt-biliran.com
91181264.your-access.one
abg-assistent.m-vogel.de
ai.chromebookstoreph.com
bot.ativandograna.online
chat.ambassadorelena.com
viewer-v2-typebot-io.vercel.app
mdb.assessoria.girotto.progenbr.com
mdb.assessoria.marinho.progenbr.com
register.thailandmicespecialist.com
mdb.assessoria.desideri.progenbr.com
mdb.assessoria.fernanda.progenbr.com
mdb.assessoria.jbatista.progenbr.com
mdb.evento.equipeinterna.progenbr.com
bot.studiotecnicoimmobiliaremerelli.it
mdb.assessoria.boaventura.progenbr.com
mdb.assessoria.jtrebesqui.progenbr.com
pesquisa.escolamodacomproposito.com.br
anamnese.clinicaramosodontologia.com.br
gabinete.baleia.formulario.progenbr.com
mdb.assessoria.carreirinha.progenbr.com
chrome-os-inquiry-system.itschromeos.com
mdb.assessoria.paulomarques.progenbr.com
viewer-v2-git-main-typebot-io.vercel.app
main-menu-for-itschromeos.itschromeos.com
mdb.assessoria.qrcode.ademir.progenbr.com
mdb.assessoria.qrcode.arthur.progenbr.com
mdb.assessoria.qrcode.danilo.progenbr.com
mdb.assessoria.qrcode.marcao.progenbr.com
mdb.assessoria.qrcode.marcio.progenbr.com
mdb.assessoria.qrcode.aloisio.progenbr.com
mdb.assessoria.qrcode.girotto.progenbr.com
mdb.assessoria.qrcode.marinho.progenbr.com
mdb.assessoria.qrcode.desideri.progenbr.com
mdb.assessoria.qrcode.fernanda.progenbr.com
mdb.assessoria.qrcode.jbatista.progenbr.com
mdb.assessoria.fernanda.regional.progenbr.com
mdb.assessoria.qrcode.boaventura.progenbr.com
mdb.assessoria.qrcode.jtrebesqui.progenbr.com
mdb.assessoria.qrcode.carreirinha.progenbr.com
mdb.assessoria.qrcode.paulomarques.progenbr.com
mdb.assessoria.qrcode.fernanda.regional.progenbr.com

@vercel
Copy link

@vercel vercel bot commented on 8ce5447 Jul 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

docs – ./apps/docs

docs-git-main-typebot-io.vercel.app
docs-typebot-io.vercel.app
docs.typebot.io

Please sign in to comment.