Can a page be tagged via an HTML iframe?
Yes. An iframe can contain Piano Analytics tags, as well as any JavaScript you need to measure the iframe’s own content (for example, clicks and other interactions).
Where to implement tagging
Tagging should be implemented on the child page (the page loaded inside the iframe), not on the parent page. All code included in the iframe content is executed in the iframe’s context and can send events normally.
When an iframe is loaded on a partner page, all tagging contained within the iframe will still execute, because it runs as part of the iframe’s document.
Recommended approach: use the latest Piano Analytics library (SDK)
We recommend using the latest version of the Piano Analytics JavaScript library to tag an iframe.
Load the library on the iframe page:
CODE<script type="text/javascript" src="https://tag.aticdn.net/piano-analytics.js"></script>Configure the SDK (example):
CODEpa.setConfigurations({ site: 123456, collectDomain: "https://your-collect-domain.com" });Send events as usual (example):
CODEpa.sendEvent('page.display', { page: 'Page_Name' });
All methods available in the Piano Analytics SDK can be used in an iframe. The iframe can be treated like a normal page loaded within a parent document.
Namespaces and avoiding conflicts (important)
Our SDKs use global variables, which can create conflicts if analytics code is present both on: - the parent page where the iframe is embedded, and - the iframe content itself
To avoid conflicts, use unique namespaces so that global objects and configuration do not collide between the parent page and the iframe.
Cross-domain considerations (visitor identification)
If the parent page and the iframe are on different domains, visitor identification may not automatically align between the two contexts. In that case, you may need to synchronize the client ID between the parent page and the iframe to preserve consistent visitor tracking across both environments.