Skip to content

Commit

Permalink
Restored tracking pixel helper methods for js-util
Browse files Browse the repository at this point in the history
  • Loading branch information
nicksantan committed Apr 8, 2024
1 parent 7fd18dc commit 47be0ed
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/util/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ export {
} from './gif-utils'
export * from './log'
export * from './sdk-headers'
export { default as injectTrackingPixel } from './tracking-pixel'
export { checkIfWebP } from './webp-check'
15 changes: 15 additions & 0 deletions packages/util/src/tracking-pixel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { sanitize } from 'dompurify'

const injectTrackingPixel = (tags: string[] = []) => {
tags.forEach((tag) => {
const el = document.createElement('html')
tag = tag.replace('%%CACHEBUSTER%%', Date.now().toString())
el.innerHTML = sanitize(tag)
const pixel = el.querySelector('img')
if (pixel) {
document?.querySelector('head')?.appendChild(pixel)
}
})
}

export default injectTrackingPixel

0 comments on commit 47be0ed

Please sign in to comment.