title: Google analytics - Track events in iframe but not the pageview
body: <p>I am trying to track events in iframe through google analytics its not cross domain but I need to call the content in an iframe and track events. I used this object to send an event to google analytics.</p>
  <pre><code>var tracking = {
   event_tracker : function(event,ad_id) {
      var eventName = &quot;&quot;;
      switch (event){
          case &quot;1&quot;:
              eventName = &quot;Click&quot;;
              break;
          case &quot;2&quot;:
              eventName = &quot;Impression&quot;;
              break;
      }
      console.log(ad_id);
      ga('send', 'event', ad_id, eventName);
  }
  </code></pre>
  <p>and this is the simple event I want to fetch</p>
  <pre><code>&lt;a href=&quot;#&quot; onclick=&quot;tracking.event_tracker('1','event1')&quot;&gt;
     &lt;img onload=&quot;tracking.event_tracker('2','event2');&quot; src=&quot;dummyimage.jpg&quot; alt=&quot;ads&quot;&gt;
   &lt;/a&gt;
  </code></pre>
  <p>one onClick  and one of the image Impression I am putting this code in my iframe just to track event not the Page view as in the <a href="https://developers.google.com/analytics/devguides/collection/analyticsjs/#the_javascript_tracking_snippet" rel="nofollow noreferrer">documentation</a></p>
  <pre><code>(function(i,s,o,g,r,a,m){
      i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
      (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
      m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
  
  ga('create', 'UA-xxx-1', 'dummy.com');
  </code></pre>
  <p>as you can see I havent added</p>
  <pre><code>ga('send', 'pageview');
  </code></pre>
  <p>that sends the pageview <strong>event</strong> but Google analytics is still <strong>showing pageviews</strong>.</p>
  <p><strong>Question: Is there a way to track only events and not pageviews in google analytics.</strong></p>