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

add moat tracking #440

Merged
merged 30 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
7f370cd
Readded moat to react sdk
nicksantan Apr 8, 2024
9188331
updated package.json
nicksantan Apr 8, 2024
646b41c
Added changeset
nicksantan Apr 8, 2024
cf88c55
Restored tracking pixel helper methods for js-util
nicksantan Apr 8, 2024
07ef010
Restored construct moat data file
nicksantan Apr 9, 2024
1fa6889
relocated construct moat data file
nicksantan Apr 9, 2024
ae41ba8
Restored bottle_data to igif type
nicksantan Apr 9, 2024
f074f03
altered syntax for stopping tracking on unmount
nicksantan Apr 9, 2024
c0d5209
Restored response_id to IGif type
nicksantan Apr 9, 2024
7c22174
restored response id and pingback type to normalize/gif.ts
nicksantan Apr 9, 2024
42a1e2a
Removed pingbackeventtype from normalize.ts
nicksantan Apr 9, 2024
b82aad7
experimenting with different purify versions
nicksantan Apr 9, 2024
d8be1d6
deps: issues with dompurify imports
giannif Apr 12, 2024
700bf4b
Removed superfluous condition
nicksantan Apr 22, 2024
65ef2e4
added moat to react components gif component
nicksantan Apr 22, 2024
41f363d
updated changeset
nicksantan Apr 22, 2024
555c76c
deps: update changeset cli
giannif Apr 22, 2024
5fb67e4
changeset
giannif Apr 23, 2024
702480d
types: add tdata to IBottleData
giannif Apr 24, 2024
e436a4e
types: remove IBottleData and let host application define it
giannif Apr 24, 2024
eebcad0
Removed legacy moat code and added new tag, new component with script…
nicksantan Apr 30, 2024
c6ba8ed
Merge branch 'feat/PG-1411' of github.com:Giphy/giphy-js into feat/PG…
nicksantan Apr 30, 2024
92415ff
Added new moat tracking component to react gif component
nicksantan May 2, 2024
9a45ef4
restored vanilla js gif component to original state
nicksantan May 2, 2024
02eb77b
remove moat loader from components
giannif May 2, 2024
54a5885
recreate changeset
giannif May 2, 2024
d1851ca
moat data updates
giannif May 2, 2024
d7bab79
moat data updates
giannif May 2, 2024
94158d9
changeset
giannif May 2, 2024
6090bfa
Merge branch 'master' into feat/PG-1411
giannif May 2, 2024
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
11 changes: 11 additions & 0 deletions .changeset/witty-singers-chew.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
'@giphy/react-components': minor
'@giphy/js-fetch-api': minor
'@giphy/js-types': minor
'@giphy/js-util': minor
---

- moat tracking in react components
- remove unused deps in util
- append bottle data in fetch-api
- update types for gif to include bottle_data
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
},
"private": true,
"devDependencies": {
"@changesets/cli": "^2.26.1",
"@changesets/cli": "^2.27.1",
"@types/jest": "^29.5.1",
"@types/node": "^20.1.2",
"@typescript-eslint/eslint-plugin": "^5.59.5",
Expand Down
12 changes: 9 additions & 3 deletions packages/fetch-api/src/normalize/gif.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@ type Tag = { text: string }
// tags sometimes are objects that have a text prop, sometimes they're strings
const getTag = (tag: Tag | string) => (typeof tag === 'string' ? (tag as string) : (tag as Tag).text)

const normalize = (gif: any) => {
const normalize = (gif: any, responseId: string = '') => {
const newGif: IGif = { ...gif }
newGif.id = String(newGif.id)
newGif.tags = (newGif.tags || []).map(getTag)
if (!newGif.bottle_data) {
newGif.bottle_data = {} as any
}
newGif.response_id = responseId
nicksantan marked this conversation as resolved.
Show resolved Hide resolved
BOOL_PROPS.forEach(makeBool(newGif))
Object.keys(newGif.images || {}).forEach((name: string) => {
const img = newGif.images[name]
Expand All @@ -53,14 +57,16 @@ const normalize = (gif: any) => {
* @hidden
*/
export const normalizeGif = (result: GifResult) => {
result.data = normalize(result.data)
const { response_id } = result.meta
result.data = normalize(result.data, response_id)
return result
}

/**
* @hidden
*/
export const normalizeGifs = (result: GifsResult) => {
result.data = result.data.map((gif) => normalize(gif))
const { response_id } = result.meta
result.data = result.data.map((gif) => normalize(gif, response_id))
return result
}
7 changes: 7 additions & 0 deletions packages/react-components/src/components/gif.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ const RenderOnClient = ({ children }: { children: ReactNode }) => {

const Gif = ({
gif,
gif: { bottle_data: bottleData = {} },
width,
percentWidth,
height: forcedHeight,
Expand Down Expand Up @@ -129,6 +130,8 @@ const Gif = ({
const hoverTimeout = useRef<number>()
// fire onseen ref (changes per gif, so need a ref)
const sendOnSeen = useRef<(_: IntersectionObserverEntry) => void>(noop)
// are we displaying an ad
const isAd = Object.keys(bottleData).length > 0
// custom pingback
const { attributes } = useContext(PingbackContext)
// user's overlay
Expand Down Expand Up @@ -284,6 +287,10 @@ const Gif = ({
alt={getAltText(gif)}
onLoad={shouldShowMedia ? onImageLoad : () => {}}
/>
{isAd &&
bottleData?.tags?.map((tag: string, index: number) => (
<div dangerouslySetInnerHTML={{ __html: tag }} key={index} />
))}
</picture>
{Overlay && (
// only render the overlay on the client since it depends on shouldShowMedia
Expand Down
28 changes: 26 additions & 2 deletions packages/react-components/stories/gif.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,27 @@ type GifComponentProps = React.ComponentProps<typeof GifComponent>
type GifDemoProps = Omit<GifComponentProps, 'gif'> & {
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<IGif>()

const fetch = useCallback(async () => {
const { data: gif } = await gf.gif(id)
if (bottle_data) {
gif.bottle_data = bottle_data
}
setGif(gif)
}, [id])

Expand Down Expand Up @@ -90,6 +103,17 @@ export const GifWithOverlay: Story = {
},
}

export const GifWithAd: Story = {
args: {
bottle_data: {
tid: '8691c382d3eed000da83ecc2ceef747b91190ab0e5bc0bc95ff5c80eeda242fa',
tags: [
'<noscript class="MOAT-giphydisplay879451385633?moatClientLevel1=ff6046d1-7125-462a-809c-efa338464775&amp;moatClientLevel2=e66d47a2-1b13-4b74-a34d-23fbdc10ddb5&amp;moatClientLevel3=82&amp;moatClientLevel4=3o7WIw8TV4UJROSElW&amp;moatClientSlicer1=e26c89fe-fb01-4442-9e8f-37940600265c&amp;moatClientSlicer2=giphytrending"></noscript><script src="https://z.moatads.com/giphydisplay879451385633/moatad.js#moatClientLevel1=ff6046d1-7125-462a-809c-efa338464775&moatClientLevel2=e66d47a2-1b13-4b74-a34d-23fbdc10ddb5&moatClientLevel3=82&moatClientLevel4=3o7WIw8TV4UJROSElW&moatClientSlicer1=e26c89fe-fb01-4442-9e8f-37940600265c&moatClientSlicer2=giphytrending" type="text/javascript"></script>',
],
},
},
}

export const GifThatStretches: Story = {
args: {
percentWidth: '50%',
Expand Down
2 changes: 2 additions & 0 deletions packages/types/src/gif.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export default interface IGif {
is_scheduled: boolean
is_removed: boolean
tags: string[]
bottle_data: any
response_id: string
analytics_response_payload: string
video?: IVideo
emoji_group_id?: number
Expand Down
2 changes: 0 additions & 2 deletions packages/util/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,9 @@
},
"dependencies": {
"@giphy/js-types": "*",
"dompurify": "^2.2.2",
"uuid": "^9.0.0"
},
"devDependencies": {
"@types/dompurify": "^2.0.4",
"@types/uuid": "^8.3.0",
"typescript": "^5.0.4"
}
Expand Down
Loading
Loading