How to Track Iframe Pageviews With Google Analytics?

3 minutes read

To track iframe pageviews with Google Analytics, you can use Google Tag Manager to insert the Google Analytics tracking code on the iframe page. This will allow you to track the pageviews of the iframe content as if it were part of your main website.


First, set up Google Analytics on your website using the tracking code provided by Google. Then, create a new tag in Google Tag Manager and select "Custom HTML" as the tag type. Paste the Google Analytics tracking code into the custom HTML box.


Next, you will need to set up a trigger to fire the tag on the iframe page. Create a new trigger in Google Tag Manager and choose "Page View" as the trigger type. In the trigger conditions, specify the URL of the iframe page.


Finally, link the tag and trigger together in a new tag firing rule. This will ensure that the Google Analytics tracking code is only inserted on the iframe page.


Once you have set up the tag, trigger, and firing rule in Google Tag Manager, test the setup to ensure that Google Analytics is tracking pageviews on the iframe content. You should see the pageviews for the iframe page in your Google Analytics reports alongside the pageviews for your main website.


How to track pageviews in Google Analytics?

To track pageviews in Google Analytics, you can follow these steps:

  1. Sign in to your Google Analytics account.
  2. Select the website or app you want to track the pageviews for.
  3. Click on the "Reporting" tab in the top navigation menu.
  4. In the left-hand sidebar, click on "Behavior" to expand the menu.
  5. From the expanded menu, select "Site Content" and then click on "All Pages".
  6. This will display a list of all the pages on your website or app along with the number of pageviews for each page.


Alternatively, you can also set up custom reports in Google Analytics to track pageviews for specific pages or sections of your website. To do this, click on the "Customization" tab in the top navigation menu and then click on "Custom Reports". From there, you can create a new custom report and set up the dimensions and metrics you want to track, including pageviews.


What is Google Analytics?

Google Analytics is a web analytics service offered by Google that tracks and reports website traffic. It provides valuable insights into the behavior of visitors on a website, such as the number of visitors, their demographics, the pages they visit, the time they spend on the site, and more. This data helps website owners understand user behavior, improve their website's performance, and make data-driven decisions to optimize their online presence.


How to track iframe pageviews with Google Analytics?

To track iframe pageviews with Google Analytics, you can follow these steps:

  1. Ensure that the parent page containing the iframe code has the Google Analytics tracking code installed.
  2. Add the following JavaScript code to the iframe page that you want to track:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<script>
  window.onload = function() {
    var iframeDocument = document;
    // Replace 'YOUR_GA_TRACKING_ID' with your actual Google Analytics tracking ID
    var ga_code = "YOUR_GA_TRACKING_ID";
    
    iframeDocument.querySelector("body").insertAdjacentHTML("beforeend", "<iframe src='https://www.google-analytics.com/analytics.js'></iframe>");
    
    function loadGaIframe() {
      console.log('ga loaded');
      var script = document.createElement('script');
      script.async = true;
      script.src = 'https://www.googletagmanager.com/gtag/js?id=' + ga_code;
      document.head.appendChild(script);
      
      window.dataLayer = window.dataLayer || [];
      function gtag() {
        window.dataLayer.push(arguments);
      }
      gtag('js', new Date());
      gtag('config', ga_code);
    }
    
    if(document.readyState == 'complete') {
        loadGaIframe();
    } else {
        window.addEventListener('load', function() {
            loadGaIframe();
        });
    }
  }
</script>


  1. Replace 'YOUR_GA_TRACKING_ID' with your actual Google Analytics tracking ID.
  2. Save the changes to the iframe page and ensure that the parent page containing the iframe is also updated.
  3. Test the implementation by visiting the page containing the iframe and checking the Google Analytics reports to see if the pageviews are being tracked properly.


Please note that tracking iframe pageviews with Google Analytics may have some limitations and restrictions due to browser security policies. It is recommended to thoroughly test the implementation and consider alternative tracking options if needed.

Facebook Twitter LinkedIn Telegram

Related Posts:

To create a custom alert in Google Analytics 4, you will need to first sign in to your Google Analytics account and navigate to the Admin section. From there, click on the Custom Alerts tab under the View column. Then, click on the New Alert button to create a...
To search for a specific phrase in a text field in Solr, you can use double quotation marks around the phrase you are looking for. This will tell Solr to search for the exact phrase within the text field. For example, if you want to search for the phrase &#34;...
To track your performance in intraday trading, it is important to keep detailed records of each trade you make. This includes noting the entry and exit points of each trade, the size of the position, the profit or loss made on each trade, as well as any fees o...
Migrating from Teradata to Hadoop can provide several benefits for organizations looking to improve their data analytics capabilities. Hadoop is a distributed computing platform that allows for processing large volumes of data in a more cost-effective manner c...
In React.js, keys are used to uniquely identify elements in a list. When rendering a list of elements, React needs a way to distinguish between them to efficiently update the DOM when the list changes. Keys are used as a way to track the identity of each eleme...