diff --git a/packages/react-components/src/components/moat-tracking.tsx b/packages/react-components/src/components/moat-tracking.tsx index 7398cc3e..71b80bcb 100644 --- a/packages/react-components/src/components/moat-tracking.tsx +++ b/packages/react-components/src/components/moat-tracking.tsx @@ -1,16 +1,24 @@ -import React from 'react' import { constructMoatData } from '@giphy/js-util' +import React from 'react' type Props = { bottleData: any } export const MoatTracking = ({ bottleData }: Props) => { const moatCompatibleData = constructMoatData(bottleData as any) - // Constructing the URL with macros replaced by their values - const url = `https://z.moatads.com/giphyjsdisplay626459778035/moatad.js#${Object.entries(moatCompatibleData) - .map(([key, value]) => `${key}=${value}`) - .join('&')}` - const scriptTag = - return scriptTag + if (moatCompatibleData) { + const partnerId = 'giphyjsdisplay626459778035' + const kvPairs = Object.entries(moatCompatibleData).map(([key, value]) => `${key}=${value}`) + // Constructing the URL with macros replaced by their values + const url = `https://z.moatads.com/${partnerId}/moatad.js#${kvPairs.join('&')}` + const noscriptClassName = `MOAT-${partnerId}?${kvPairs.join('&:')}` + return ( + <> + + + + ) + } + return null } export default MoatTracking diff --git a/packages/react-components/stories/gif.stories.tsx b/packages/react-components/stories/gif.stories.tsx index e7cbd884..90ba4575 100644 --- a/packages/react-components/stories/gif.stories.tsx +++ b/packages/react-components/stories/gif.stories.tsx @@ -19,14 +19,27 @@ type GifComponentProps = React.ComponentProps type GifDemoProps = Omit & { id: string scale: string + bottle_data: IGif['bottle_data'] } - -const GifDemo = ({ id, width, height, noLink, borderRadius, percentWidth, overlay, ...other }: GifDemoProps) => { +const GifDemo = ({ + id, + width, + height, + noLink, + borderRadius, + percentWidth, + overlay, + bottle_data, + ...other +}: GifDemoProps) => { const [gif, setGif] = useState() const fetch = useCallback(async () => { const { data: gif } = await gf.gif(id) + if (bottle_data) { + gif.bottle_data = bottle_data + } setGif(gif) }, [id]) @@ -90,6 +103,34 @@ export const GifWithOverlay: Story = { }, } +export const GifWithAd: Story = { + args: { + bottle_data: { + tid: 'd7494a8384b6906a880ff6dcc16a7151d3f2a3e8413be76e9ddb4ee1f8dc9fd0', + tags: [], + tdata: { + om: [], + bartab: [], + web: [ + { + vendor: 'Moat', + verificationParameters: { + moatClientLevel1: 'Giphy', + moatClientLevel2: 'Giphy', + moatClientLevel3: 'Giphy', + moatClientLevel4: 'Giphy', + moatClientSlicer1: 'Giphy', + moatClientSlicer2: 'Giphy', + zMoatPosition: 'Giphy', + }, + }, + ], + click_out_url: '', + }, + }, + }, +} + export const GifThatStretches: Story = { args: { percentWidth: '50%', diff --git a/packages/util/src/index.ts b/packages/util/src/index.ts index 20245dc3..41109bfa 100644 --- a/packages/util/src/index.ts +++ b/packages/util/src/index.ts @@ -14,5 +14,4 @@ export { } from './gif-utils' export * from './log' export * from './sdk-headers' -export { default as injectTrackingPixel } from './tracking-pixel' export { checkIfWebP } from './webp-check' diff --git a/packages/util/src/tracking-pixel.ts b/packages/util/src/tracking-pixel.ts deleted file mode 100644 index d556097f..00000000 --- a/packages/util/src/tracking-pixel.ts +++ /dev/null @@ -1,15 +0,0 @@ -import DOMPurify from 'dompurify' - -const injectTrackingPixel = (tags: string[] = []) => { - tags.forEach((tag) => { - const el = document.createElement('html') - tag = tag.replace('%%CACHEBUSTER%%', Date.now().toString()) - el.innerHTML = DOMPurify.sanitize(tag) - const pixel = el.querySelector('img') - if (pixel) { - document?.querySelector('head')?.appendChild(pixel) - } - }) -} - -export default injectTrackingPixel