How to track clicks in an iframe with google analytics?
@alvera_smith
To track clicks on elements within an iframe using Google Analytics, you need to implement event tracking. Follow these steps:
1 2 3 4 5 |
<script> document.getElementById('YOUR_IFRAME_ID').contentWindow.document.addEventListener('click', function(event) { ga('send', 'event', 'iframe', 'click', event.target.href); }); </script> |
Replace 'YOUR_IFRAME_ID'
with the ID of your iframe element.
Now, whenever a click occurs within the iframe, Google Analytics will track it as an event with the category "iframe" and the action "click". The event label will contain the href of the clicked element.
Remember that it may take some time for the data to appear in your Google Analytics account. You can view the results by going to "Behavior" -> "Events" -> "Top Events" in your Google Analytics dashboard and filtering by the "iframe" category.