Google Analytics from a third party script

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 ?

  1. 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
  2. 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:

  1. My customer has added my widget code into their website so I can do dom manipulation on their site.
  2. My widget iframe is running on my domain which is different from my customer’s parent window domain
  3. My customer might or might not have GA4 tag in their parent window.

4

Ok, how you should handle it:

  1. You don’t add the GA to the widget code. Your widget code deploys the iframe.

  2. No, you don’t send the post messages unless your stakeholders explicitly asked you to do so. Well, you may. Some iframe widgets would be nice enough to provide JS events to the parent. That’s handy.

What usually happens in these cases is the customer would give you their GTM snippet and you would deploy it in the iframe. Not in your widget.

Then they will be able to track whatever they want through that GTM snippet. That’s very simple on your part.

Another thing they could ask for is to give them dataLayer events, but in this case you don’t need their GA id either. You just do the post messages exactly as you described from the iframe to the parent, where your widget would deploy listeners and translate those messages into the datalayer events. If you do this, you’re a very nice and considerate widget. I wish all widgets were this good.

Finally, your client may not have the capability to do any kind of tracking on their side. In other words, they saved money on technical analyst expertise. In that case, they would ask you to send actual events into their analytics, at which point you become that technical analyst. And that’s… I wouldn’t expect any widget vendor to do this. That’s a bit too much to ask for many reasons. One of which, the vendor doesn’t and shouldn’t know about every client’s data structure and logic. Doing separate tracking implementation for every client is nonsense. Hence the dataLayer is the middleground where they can get the events and remap them into their analytics as they see fit.

2

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật