Google analytics - Track events in iframe but not the pageview
NickName:Abdul Rafay Shaikh Ask DateTime:2016-05-19T23:48:20

Google analytics - Track events in iframe but not the pageview

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.

var tracking = {
 event_tracker : function(event,ad_id) {
    var eventName = "";
    switch (event){
        case "1":
            eventName = "Click";
            break;
        case "2":
            eventName = "Impression";
            break;
    }
    console.log(ad_id);
    ga('send', 'event', ad_id, eventName);
}

and this is the simple event I want to fetch

<a href="#" onclick="tracking.event_tracker('1','event1')">
   <img onload="tracking.event_tracker('2','event2');" src="dummyimage.jpg" alt="ads">
 </a>

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 documentation

(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');

as you can see I havent added

ga('send', 'pageview');

that sends the pageview event but Google analytics is still showing pageviews.

Question: Is there a way to track only events and not pageviews in google analytics.

Copyright Notice:Content Author:「Abdul Rafay Shaikh」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/37328250/google-analytics-track-events-in-iframe-but-not-the-pageview

More about “Google analytics - Track events in iframe but not the pageview” related questions

Google analytics - Track events in iframe but not the pageview

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 analy...

Show Detail

How to track iFrame pageviews with Google Analytics?

I have a Chrome Extension that re-designs the new tab. Each new tab loads content as an iFrame from tab.mywebsite.com. When visiting tab.mywebsite.com, Google Analytics will track the pageview. How...

Show Detail

Vimeo tracking in Google Analytics not sending events

I have followed the documentation from Vimeo to track play-events in Google Analytics but no events are being sent. &lt;script&gt; (function (i, s, o, g, r, a, m) { i['GoogleAnalyticsOb...

Show Detail

Google Analytics: Track third-party form submission embedded in iframe (with another iframe)

I have a form hosted by a third party embedded on my site via an iframe (I'll call this the "Parent iFrame"). I would like to track those form submissions in Google Analytics. If I embed another ...

Show Detail

Google Analytics - Track Fake Pageview

I have been trying for a while and I cant seem to get it to work. I am just wondering how to track a fake pageview in google analytics, I have a link that leads to an external site, and I want to t...

Show Detail

Submit virtual pageview to google analytics server-side

I'm trying to submit a virtual pageview to track events within application, that may not be associated with user visiting a page, and therefore will not allow for execution of javascript. The proje...

Show Detail

Suppress Google Pageview Event in an AMP-IFRAME

I have been recently asked to disable the additional Pageview event on Page nestet within an AMP-IFRAME. The problem is, that both pages use the Google Analytics functions which is required so far,...

Show Detail

Universal Analytics Track Events

I need help with tracking events with Google Analytics. &lt;script&gt; (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=...

Show Detail

How to detect if Google Analytics is loaded and able to track custom Events

We're having some issues when we're loading an iframe with a video player that sends playback Events to Google Universal Analytics (analytics.js) loaded inside that iframe (on another domain). The GA

Show Detail

Track custom impressions in google analytics

Google Analytic's Enhanced Ecommerce Plugin has product impressions that track views of shown products. I have products AND multiple businesses in my search result, therefore, I want to track busin...

Show Detail