Track events on iFrame

Hey guys! I’m having trouble tracking events on an iframe in our webflow page. Creating a custom attribute (like I did for e.g. buttons) doesn’t seem to work for the iframe.

ChatGPT gave me this example but it didn’t work:

<div id="iframe-container">
    <iframe src="https://example.com" width="600" height="400"></iframe>
</div>

<script>
    document.addEventListener("DOMContentLoaded", () => {
        document.getElementById("iframe-container").addEventListener("click", () => {
            pirsch("iFrame Clicked", { duration: 1, meta: { Key: "Meta Value" } });
        });
    });
</script>

Here’s how my custom code block looks in Webflow

I’d appreciate some help! :slight_smile: Thanks

Hi,

Tracking inside an iframe requires the script to be installed inside the embedded page. JavaScript from outside the iframe won’t have access to it, they are completely separated websites.

Do you have access to “example.com”? In that case, add the tracking script and custom button tracking to it directly.

Or would you actually like to track clicks onto the iframe? I don’t know if it is possible to track click events on the

Hey Marvin,

We’re using a Tally.so form, and we’d like to track klicks on a button in there. In that case we somehow would need to place the script within Tally and not in the iframe brackets?

Exactly. You would need to add it to Tally and probably also create a roll-up view.

What exactly are you trying to achieve? If it’s about tracking the successful form submission, I would recommend setting up a “thank you” page and adding the event there, making implementing this a lot easier.

Hey Marvin!

We manged to implement it. Tally Pro allows for code injection. So we added our Tally sub-domain to Pirsch as an additional domain, added the general Pirsch snippet in Tally (on a domain level code injection) and then added the JavaScript Snippet into the code injection of that specific form.

Now when the button with the class “sc-bb5db573-1” gets klicked, an event is logged in Pirsch :slight_smile:

Awesome! I didn’t know this was possible with Tally, but that’s a really nice feature :+1:

1 Like