Skip to content

Commit

Permalink
fix(REACH-578): Update error message for shareGaInstance (#596)
Browse files Browse the repository at this point in the history
* fix(REACH-578): Update error message for shareGaInstance

Inform developers their adblock might be preventing the Google Analytics from being loaded.

* Update packages/embed/src/utils/setup-google-analytics-instance.ts

Co-authored-by: Leandro Serafim <[email protected]>

---------

Co-authored-by: Leandro Serafim <[email protected]>
  • Loading branch information
mathio and leandro-serafim authored Jul 10, 2023
1 parent 0feacc3 commit 5b80582
Showing 1 changed file with 13 additions and 23 deletions.
36 changes: 13 additions & 23 deletions packages/embed/src/utils/setup-google-analytics-instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,23 @@ const getTrackingFromDataLayer = (): string | undefined => {
}
}

const logErrorMessage = (reason?: string) => {
logError(
`Whoops! You enabled the shareGaInstance feature in your typeform embed but ${reason}.\n\n` +
'Make sure to include Google Analytics Javascript code before the Typeform Embed Javascript ' +
'code in your page and use correct tracker ID.\n\n' +
'It is also possible the Google Analytics was blocked by your adblock plugin.'
)
}

export const setupGaInstance = (iframe: HTMLIFrameElement, embedId: string, shareGaInstance?: string | boolean) => {
let trackingId = typeof shareGaInstance === 'string' ? shareGaInstance : undefined
if (window.gtag) {
if (!trackingId) {
trackingId = getTrackingFromDataLayer()
}
if (!trackingId) {
logError(
'Whoops! You enabled the shareGaInstance feature in your' +
'typeform embed but the tracker ID could not be retrieved. ' +
'Make sure to include Google Analytics Javascript code before the Typeform Embed Javascript' +
'code in your page and use correct tracker ID. '
)
logErrorMessage('the tracking ID could not be retrieved')
return
}
let fetchedAccountId = false
Expand All @@ -68,12 +72,7 @@ export const setupGaInstance = (iframe: HTMLIFrameElement, embedId: string, shar
})
setTimeout(() => {
if (!fetchedAccountId) {
logError(
`Whoops! You enabled the shareGaInstance feature in your` +
`typeform embed but the tracker with ID ${trackingId} was not found. ` +
'Make sure to include Google Analytics Javascript code before the Typeform Embed Javascript' +
'code in your page and use correct tracker ID. '
)
logErrorMessage(`the tracker with ID ${trackingId} was not found`)
}
}, G4A_CALLBACK_TIMEOUT)
} else {
Expand All @@ -84,19 +83,10 @@ export const setupGaInstance = (iframe: HTMLIFrameElement, embedId: string, shar
if (tracker) {
sendGaIdMessage(embedId, tracker.get('clientId'), iframe)
} else {
logError(
`Whoops! You enabled the shareGaInstance feature in your` +
`typeform embed but the tracker with ID ${trackingId} was not found. ` +
'Make sure to include Google Analytics Javascript code before the Typeform Embed Javascript' +
'code in your page and use correct tracker ID. '
)
logErrorMessage(`the tracker with ID ${trackingId} was not found`)
}
} catch (exception) {
logError(
'Whoops! You enabled the shareGaInstance feature in your typeform embed but the Google Analytics ' +
'object has not been found. Make sure to include Google Analytics Javascript code before the ' +
'Typeform Embed Javascript code in your page. '
)
logErrorMessage('the Google Analytics object was not found')
logError(exception as string)
}
}
Expand Down

0 comments on commit 5b80582

Please sign in to comment.