Skip to content

Commit

Permalink
fix: Load intercom when adblockers on (#2457)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyaiox authored Dec 2, 2022
1 parent c6d0465 commit ef4fff4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/components/Intercom/Intercom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,26 @@ import React, { useState, useCallback, useEffect } from 'react'
import IntercomWidget from 'decentraland-dapps/dist/components/Intercom'
import { getAnalytics, getAnonymousId } from 'decentraland-dapps/dist/modules/analytics/utils'
import { config } from 'config'
import { IntercomUserData } from './Intercom.types'

const APP_ID = config.get('INTERCOM_APP_ID', '')
const analytics = getAnalytics()

export const Intercom: React.FC = () => {
const [dclAnonymousUserID, setDclAnonymousUserID] = useState('')
const [intercomUserData, setIntercomUserData] = useState<IntercomUserData>()

const analyticsReadyCallback = useCallback(() => {
const dclAnonymousUserID = getAnonymousId()
if (dclAnonymousUserID) {
setDclAnonymousUserID(dclAnonymousUserID)
setIntercomUserData({ ...intercomUserData, anon_id: dclAnonymousUserID })
}
}, [])
}, [intercomUserData])

useEffect(() => {
analytics.ready(analyticsReadyCallback)
}, [analyticsReadyCallback])

return dclAnonymousUserID ? (
<IntercomWidget appId={APP_ID} data={{ anon_id: dclAnonymousUserID }} settings={{ alignment: 'right' }} />
) : null
return <IntercomWidget appId={APP_ID} data={intercomUserData} settings={{ alignment: 'right' }} />
}

export default Intercom
3 changes: 3 additions & 0 deletions src/components/Intercom/Intercom.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface IntercomUserData {
anon_id: string | undefined
}

1 comment on commit ef4fff4

@vercel
Copy link

@vercel vercel bot commented on ef4fff4 Dec 2, 2022

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 – ./

builder-git-master-decentraland1.vercel.app
builder-decentraland1.vercel.app

Please sign in to comment.