Skip to content

Commit 320283a

Browse files
committed
fix(meta-ads): use unique gradient IDs and filter conversion actions
- Use useId() for MetaAdsIcon SVG gradient IDs to prevent collisions when multiple instances render on the same page - Filter conversions to only count actual conversion action types (offsite_conversion, onsite_conversion, app_custom_event) instead of summing all actions
1 parent bb8b314 commit 320283a

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

apps/docs/components/icons.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4136,11 +4136,14 @@ export function LumaIcon(props: SVGProps<SVGSVGElement>) {
41364136
}
41374137

41384138
export function MetaAdsIcon(props: SVGProps<SVGSVGElement>) {
4139+
const id = useId()
4140+
const lg1 = `${id}-meta-lg1`
4141+
const lg2 = `${id}-meta-lg2`
41394142
return (
41404143
<svg {...props} xmlns='http://www.w3.org/2000/svg' viewBox='0 0 287.56 191'>
41414144
<defs>
41424145
<linearGradient
4143-
id='meta-lg1'
4146+
id={lg1}
41444147
x1='62.34'
41454148
y1='101.45'
41464149
x2='260.34'
@@ -4154,7 +4157,7 @@ export function MetaAdsIcon(props: SVGProps<SVGSVGElement>) {
41544157
<stop offset='1' stopColor='#0082fb' />
41554158
</linearGradient>
41564159
<linearGradient
4157-
id='meta-lg2'
4160+
id={lg2}
41584161
x1='41.42'
41594162
y1='53'
41604163
x2='41.42'
@@ -4171,11 +4174,11 @@ export function MetaAdsIcon(props: SVGProps<SVGSVGElement>) {
41714174
d='M31.06,126c0,11,2.41,19.41,5.56,24.51A19,19,0,0,0,53.19,160c8.1,0,15.51-2,29.79-21.76,11.44-15.83,24.92-38,34-52l15.36-23.6c10.67-16.39,23-34.61,37.18-47C181.07,5.6,193.54,0,206.09,0c21.07,0,41.14,12.21,56.5,35.11,16.81,25.08,25,56.67,25,89.27,0,19.38-3.82,33.62-10.32,44.87C271,180.13,258.72,191,238.13,191V160c17.63,0,22-16.2,22-34.74,0-26.42-6.16-55.74-19.73-76.69-9.63-14.86-22.11-23.94-35.84-23.94-14.85,0-26.8,11.2-40.23,31.17-7.14,10.61-14.47,23.54-22.7,38.13l-9.06,16c-18.2,32.27-22.81,39.62-31.91,51.75C84.74,183,71.12,191,53.19,191c-21.27,0-34.72-9.21-43-23.09C3.34,156.6,0,141.76,0,124.85Z'
41724175
/>
41734176
<path
4174-
fill='url(#meta-lg1)'
4177+
fill={`url(#${lg1})`}
41754178
d='M24.49,37.3C38.73,15.35,59.28,0,82.85,0c13.65,0,27.22,4,41.39,15.61,15.5,12.65,32,33.48,52.63,67.81l7.39,12.32c17.84,29.72,28,45,33.93,52.22,7.64,9.26,13,12,19.94,12,17.63,0,22-16.2,22-34.74l27.4-.86c0,19.38-3.82,33.62-10.32,44.87C271,180.13,258.72,191,238.13,191c-12.8,0-24.14-2.78-36.68-14.61-9.64-9.08-20.91-25.21-29.58-39.71L146.08,93.6c-12.94-21.62-24.81-37.74-31.68-45C107,40.71,97.51,31.23,82.35,31.23c-12.27,0-22.69,8.61-31.41,21.78Z'
41764179
/>
41774180
<path
4178-
fill='url(#meta-lg2)'
4181+
fill={`url(#${lg2})`}
41794182
d='M82.35,31.23c-12.27,0-22.69,8.61-31.41,21.78C38.61,71.62,31.06,99.34,31.06,126c0,11,2.41,19.41,5.56,24.51L10.14,167.91C3.34,156.6,0,141.76,0,124.85,0,94.1,8.44,62.05,24.49,37.3,38.73,15.35,59.28,0,82.85,0Z'
41804183
/>
41814184
</svg>

apps/sim/components/icons.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4136,11 +4136,14 @@ export function LumaIcon(props: SVGProps<SVGSVGElement>) {
41364136
}
41374137

41384138
export function MetaAdsIcon(props: SVGProps<SVGSVGElement>) {
4139+
const id = useId()
4140+
const lg1 = `${id}-meta-lg1`
4141+
const lg2 = `${id}-meta-lg2`
41394142
return (
41404143
<svg {...props} xmlns='http://www.w3.org/2000/svg' viewBox='0 0 287.56 191'>
41414144
<defs>
41424145
<linearGradient
4143-
id='meta-lg1'
4146+
id={lg1}
41444147
x1='62.34'
41454148
y1='101.45'
41464149
x2='260.34'
@@ -4154,7 +4157,7 @@ export function MetaAdsIcon(props: SVGProps<SVGSVGElement>) {
41544157
<stop offset='1' stopColor='#0082fb' />
41554158
</linearGradient>
41564159
<linearGradient
4157-
id='meta-lg2'
4160+
id={lg2}
41584161
x1='41.42'
41594162
y1='53'
41604163
x2='41.42'
@@ -4171,11 +4174,11 @@ export function MetaAdsIcon(props: SVGProps<SVGSVGElement>) {
41714174
d='M31.06,126c0,11,2.41,19.41,5.56,24.51A19,19,0,0,0,53.19,160c8.1,0,15.51-2,29.79-21.76,11.44-15.83,24.92-38,34-52l15.36-23.6c10.67-16.39,23-34.61,37.18-47C181.07,5.6,193.54,0,206.09,0c21.07,0,41.14,12.21,56.5,35.11,16.81,25.08,25,56.67,25,89.27,0,19.38-3.82,33.62-10.32,44.87C271,180.13,258.72,191,238.13,191V160c17.63,0,22-16.2,22-34.74,0-26.42-6.16-55.74-19.73-76.69-9.63-14.86-22.11-23.94-35.84-23.94-14.85,0-26.8,11.2-40.23,31.17-7.14,10.61-14.47,23.54-22.7,38.13l-9.06,16c-18.2,32.27-22.81,39.62-31.91,51.75C84.74,183,71.12,191,53.19,191c-21.27,0-34.72-9.21-43-23.09C3.34,156.6,0,141.76,0,124.85Z'
41724175
/>
41734176
<path
4174-
fill='url(#meta-lg1)'
4177+
fill={`url(#${lg1})`}
41754178
d='M24.49,37.3C38.73,15.35,59.28,0,82.85,0c13.65,0,27.22,4,41.39,15.61,15.5,12.65,32,33.48,52.63,67.81l7.39,12.32c17.84,29.72,28,45,33.93,52.22,7.64,9.26,13,12,19.94,12,17.63,0,22-16.2,22-34.74l27.4-.86c0,19.38-3.82,33.62-10.32,44.87C271,180.13,258.72,191,238.13,191c-12.8,0-24.14-2.78-36.68-14.61-9.64-9.08-20.91-25.21-29.58-39.71L146.08,93.6c-12.94-21.62-24.81-37.74-31.68-45C107,40.71,97.51,31.23,82.35,31.23c-12.27,0-22.69,8.61-31.41,21.78Z'
41764179
/>
41774180
<path
4178-
fill='url(#meta-lg2)'
4181+
fill={`url(#${lg2})`}
41794182
d='M82.35,31.23c-12.27,0-22.69,8.61-31.41,21.78C38.61,71.62,31.06,99.34,31.06,126c0,11,2.41,19.41,5.56,24.51L10.14,167.91C3.34,156.6,0,141.76,0,124.85,0,94.1,8.44,62.05,24.49,37.3,38.73,15.35,59.28,0,82.85,0Z'
41804183
/>
41814184
</svg>

apps/sim/tools/meta_ads/get_insights.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,17 @@ export const metaAdsGetInsightsTool: ToolConfig<
127127
const items = data.data ?? []
128128
const insights = items.map((i: Record<string, unknown>) => {
129129
const actions = (i.actions as Array<Record<string, unknown>>) ?? []
130-
const conversions = actions.reduce((sum, a) => sum + Number(a.value ?? 0), 0)
130+
const conversionTypes = new Set([
131+
'offsite_conversion',
132+
'onsite_conversion',
133+
'app_custom_event',
134+
])
135+
const conversions = actions
136+
.filter((a) => {
137+
const actionType = a.action_type as string
138+
return conversionTypes.has(actionType) || actionType?.startsWith('offsite_conversion.')
139+
})
140+
.reduce((sum, a) => sum + Number(a.value ?? 0), 0)
131141

132142
return {
133143
accountId: (i.account_id as string) ?? null,

0 commit comments

Comments
 (0)