Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: make pixel events more resilient #2856

Merged
merged 2 commits into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/legacy/components/analytics/pixel/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// TODO: Leaving true just for testing, then i will enable for PROD and ENS
export const PIXEL_ENABLED = true // isProd || isEns

export enum PIXEL_EVENTS {
INIT = 'init',
CONNECT_WALLET = 'connect_wallet',
Expand Down
5 changes: 3 additions & 2 deletions src/legacy/components/analytics/pixel/facebook.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { PIXEL_EVENTS } from './constants'
import { sendPixel } from './utils'

const events = {
[PIXEL_EVENTS.INIT]: 'InitiateCheckout',
[PIXEL_EVENTS.CONNECT_WALLET]: 'Contact',
[PIXEL_EVENTS.POST_TRADE]: 'Lead',
}

export const sendFacebookEvent = (event: PIXEL_EVENTS) => {
export const sendFacebookEvent = sendPixel((event) => {
window.fbq?.('track', events[event])
}
})
5 changes: 3 additions & 2 deletions src/legacy/components/analytics/pixel/linkedin.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { PIXEL_EVENTS } from './constants'
import { sendPixel } from './utils'

const events = {
[PIXEL_EVENTS.INIT]: 10759506,
[PIXEL_EVENTS.CONNECT_WALLET]: 10759514,
[PIXEL_EVENTS.POST_TRADE]: 10759522,
}

export const sendLinkedinEvent = (event: PIXEL_EVENTS) => {
export const sendLinkedinEvent = sendPixel((event) => {
window.lintrk?.('track', { conversion_id: events[event] })
}
})
5 changes: 3 additions & 2 deletions src/legacy/components/analytics/pixel/microsoft.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { PIXEL_EVENTS } from './constants'
import { sendPixel } from './utils'

const events = {
[PIXEL_EVENTS.INIT]: 'page_view',
[PIXEL_EVENTS.CONNECT_WALLET]: 'begin_checkout',
[PIXEL_EVENTS.POST_TRADE]: 'purchase',
}

export const sendMicrosoftEvent = (event: PIXEL_EVENTS) => {
export const sendMicrosoftEvent = sendPixel((event) => {
window.uetq = window.uetq || []
window.uetq.push('event', events[event], {})
}
})
5 changes: 3 additions & 2 deletions src/legacy/components/analytics/pixel/paved.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { PIXEL_EVENTS } from './constants'
import { sendPixel } from './utils'

const events = {
[PIXEL_EVENTS.INIT]: 'search',
[PIXEL_EVENTS.CONNECT_WALLET]: 'sign_up',
[PIXEL_EVENTS.POST_TRADE]: 'purchase',
}

export const sendPavedEvent = (event: PIXEL_EVENTS) => {
export const sendPavedEvent = sendPixel((event: PIXEL_EVENTS) => {
window.pvd?.('event', events[event])
}
})
5 changes: 3 additions & 2 deletions src/legacy/components/analytics/pixel/reddit.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { PIXEL_EVENTS } from './constants'
import { sendPixel } from './utils'

const events = {
[PIXEL_EVENTS.INIT]: 'Lead',
[PIXEL_EVENTS.CONNECT_WALLET]: 'SignUp',
[PIXEL_EVENTS.POST_TRADE]: 'Purchase',
}

export const sendRedditEvent = (event: PIXEL_EVENTS) => {
export const sendRedditEvent = sendPixel((event) => {
window.rdt?.('track', events[event])
}
})
5 changes: 3 additions & 2 deletions src/legacy/components/analytics/pixel/twitter.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { PIXEL_EVENTS } from './constants'
import { sendPixel } from './utils'

const events = {
[PIXEL_EVENTS.INIT]: 'tw-oddz2-oddz8',
[PIXEL_EVENTS.CONNECT_WALLET]: 'tw-oddz2-oddza',
[PIXEL_EVENTS.POST_TRADE]: 'tw-oddz2-oddzb',
}

export const sendTwitterEvent = (event: PIXEL_EVENTS) => {
export const sendTwitterEvent = sendPixel((event: PIXEL_EVENTS) => {
window.twq?.('event', events[event], {})
}
})
17 changes: 17 additions & 0 deletions src/legacy/components/analytics/pixel/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { PIXEL_ENABLED, PIXEL_EVENTS } from './constants'

type SendPixelFn = (event: PIXEL_EVENTS) => void

export function sendPixel(sendFn: SendPixelFn): SendPixelFn {
return (event) => {
if (!PIXEL_ENABLED) {
return
}

try {
sendFn(event)
} catch (e: any) {
console.error('Error sending pixel event', e)
}
}
}
Loading