I am developing a widget that can be added to a host website via snippet of js code that once rendered will add an iframe to the host website.
Now my customers want to give me their GA tracking id so that I can send events from my widget to their GA4 account.
How should I handle this ?
- Add GA4 tag to the widget code and send the events from within the iframe, regardless of any GA4 tag that the host / parent page has
- Post messages from within the iframe page to the parent window and then intercept them on parent window and send them to GA4 from there. I will have to check if the parent window already has GA4 tag and if so, use it. If not, I will have to add the tag to the parent window.
Couple of things to note:
- My customer has added my widget code into their website so I can do dom manipulation on their site.
- My widget iframe is running on my domain which is different from my customer’s parent window domain