Monitor clicks/goals Google Analytics with iframes? - javascript

We've got a site that shows some content in iframes loaded from another domains. What I'd like to do is setup some Goals to track if this stuff is clicked, is this possible to track these clicks?
I know that this content us outside our domain but is it still in the dom?

It is possible. Since Goal Tracking is Profile based, the key is to have a tracking of all domains into one Profile. See the How do I install the tracking code if my site spans multiple domains? entry in the Google Analytics Help for further instructions. After that your iframe contents will appear as usual PageViews in the reports. (For instance, if you used <iframe src="http://otherdomain.com/stuff"></iframe>, you will find PageViews for ’/stuff’.)
Otherwise, I don't really know what you mean under ’stuff is clicked’. If it's an object in the iframe you want to track, you may generate a virtual PageView when visitor clicks on it:
pageTracker._trackPageview("/Stuff_clicked");

If you are not able to install GATC (Google Analytics Tracking Code) on so called another domains which you are loading inside your iFrame, unfortunately, you won't be able to track any clicks or virtual page-views for those domains. Any clicks or event occurring on any domain can be tracked back to your account as far as your GATC which includes your Google Analytics ProfileID e.g. UA-XXXX-X is installed on that page.

Related

Can I freeze/unfreeze Google Analytics on a page via JavaScript?

I have a Swift app with a section that contains a feed of articles. Each article is presented as a web view baked into the app.
The web views are each loaded as the links in the feed are shown, i.e. before the actual view of the article is presented.
I have noticed that Google Analytics considers these preloads to be page views. How can I avoid this? I am able to run JavaScript at the time of the preload as well as when the user navigates to the article. Is it possible to use custom JavaScript to stop GA when the page first loads, then re-enable it when the page is actually displayed?
This is not guaranteed to work but one thing you could explore, providing that you own the GA implementation and the actual articles is to filter out traffic in GA based on a query string param or a campaign param, OR to use some javascript in the articles pages to prevent the GA script from executing.
In your app, upon fetching the list of articles you would append all the URLs in the webviews with a param=value that you would use to build an exclusion rule in the property/view settings in the admin, or instruct your JS in the articles to not execute GA.
On the click on an article you would however remove the param from the URL which would cause GA to behave "normally".
From the GA console:

How to capture visitor source with GTM, if they have agreed to privacy policy (GDPR)

I have a website in the UK that needs to comply with GDPR, so we ask for consent (via a standard banner with an 'accept' button) before we run scripts like GTM.
Many of our visitors do click that 'accept' button when they arrive on the site (before they move onto another page); upon that event, we lazyload GTM, and within it, Google Analytics (see Is it a good idea to lazy load GTM) however that doesn't seem to capture their referral source/medium (whilst as an example, if we were to load it immediately in it does capture it, but that's not GDPR compliant as I understand).
What then happens is that we have a lot of traffic with no known source, which makes business management / marketing decisions very difficult.
Is there a better way of loading GTM to ensure we do capture the medium/source in Google Analytics for visitors who consent on their landing page?
Google Analytics reads the source based on the referrer, if this is lost it cannot know where the user came from. It is not a good practice to block the tracking, it can probably be enough to anonymize the IP with anonimyzeIp.
Even if you were able to do as you said, it makes no sense that Analytics start tracking from the second page and that the source is attributed to this page, because it is not the reality, this is not really the langing, you would base the analysis on untrue data...

Event Tracking with Google Analytics in a Standalone HTML App

I work with internet connected touchscreens that can run HTML projects. The HTML projects must be self contained in that all assets like scripts, css, images, videos, etc... must be in the local file structure on the hardware in case the unit loses internet connectivity. The units have a built-in web server for this basic use with a chromium browser.
I'm wanting to track events on specified DOM elements using Google Analytics so those events can be recorded when the unit has an active internet connection.
For example... If a button is clicked to perform some sort of action on the page and in that action I want to include an audit call to send that event to my GA account. Pretty standard use of this: https://developers.google.com/analytics/devguides/collection/analyticsjs/events
However, I can't seem to figure out how to make this work on a page that isn't hosted on a typical website. Everything I'm finding doesn't deal with this specific scenario and always relies on a page hosted on a typical site.
How can I track events using Google Analytics on a standalone HTML page?
Thanks,
~Mike
Can you try with sending your events by using Google Tag Manager to Google Analytics.It is quite easy to implement.
Try with adding the Google Tag Manager code, you get once you create the account in tag manager.And add your analytics property id to a custom variable in tag manager.Then create a page view type tag with analytics property id.
sample link for your reference https://support.google.com/tagmanager/answer/6102821?hl=en
Once you are able to link tag manager to your HTML page you can start tracking the page view event.Similarly, you can track other types of events.

changing web content but still google analytics tracks the page

Here is a website a let say a.com with a.com/xxx or /yyy
I am now the webmaster and i don't know the initial setup of the web.
It used google analytics to track webpage info. And it is assumed the web is attached with javascript tracking code.
The webpage reforms and it is now with no tracking code.
However, there is still tracking info until today.
Some of the hierarchy of the website remains.
Q1. Why google can still track the website? I guess that's because of the unchanged hierarchy.
Q2. Can i see individual user pathway / history? Now i can see the summary of each day / hour with total. What I want is user a /xxx -> /yyy / a.com -> /yyy
Q3. I still want to use google analytics service. How can I make sure it works fine? Status now: receiving data, which I barely trust. Answer of Q2 leads to Q3.
If I can see there are some users viewing the new page e.g. a.com/zzz, then i know new webpage is being tracked.
Newbie to web.
Comment appreciated.
Most possibly your tracking code is in your header or footer, so every new page will have it. Just look for the code in the source code.
It doesn't matter if you change a content, structure, make new page or whatsoever. Google Analytics tracks every page where the code is present, and don't track pages where there is no code.
If there is no tracking code (and you are sure there isn't) - then GA can't track it. However there are spam referrals, that could hit your GA account and show you traffic on pages where the code is missing (just check if the traffic is referral). To fight with this spam you need a filters but this is whole new question.

How do you track how many sites have an actively embedded iframe widget?

I have an iframe widget that is being embedded in over 3000 third party sites, but I want to know exactly how many sites it is embedded in.
Our current method is to use google analytics to generate a list of referers, and have a script manually curl each url in the list to look for our widget.
Another method we were thinking of is to use php to print a $_SERVER['HTTP_REFERER'], and use javascript to fire an analytics event if it determines the page is in an iframe, but as the referer can be manipulated, I don't know how effective it would be.
Thanks!

Categories

Resources