Datapack check when food with nbt tag get eaten

Hello when i want to check when a cookie with a custom tag is eaten, so i can replace it with a new one

i do this on load.mcfunction

scoreboard objectives add cookie minecraft.used:minecraft.cookie
scoreboard players set @a cookie 0

and i want to check if its the custom in the tick thing give @s minecraft:cookie{customtag:1b,display:{Name:'{"text":"Custom Cookie"}'},CustomCookie:1b} 1

Continue to help post