How To Bind Twitter Basic Pixel in Customer events

I have added Twitter’s basic code in Customer events. But when I use Chrome’s Twitter plug-in tool to detect the pixel, I always get this error. How to fix it?

Btw, there is no problem adding the code directly to [theme.liquid]. I want to know why?

P.S. error message:

  1. Warning. No Referrer found. This is expected if you are loading this page directly. If this occurs after redirecting from a Twitter Ad or other page, this may indicate an error.

  2. An iFrame was detected. Remove the tag from the iFrame to properly track URLs.

The tracking snippet needs to run before the event fires. When you add it through a property in the cms the load order is defined by the app or platform, in code the conversion metric will follow after the library is loaded.

Thanks for your answer. Can you please tell me how to adjust my Twitter code?

window.addEventListener(‘load’, (e) => {
if(window.twitter == null) {
window.twitter = ;
}

window.twitter();
})