tpcolson
tpcolson

Reputation: 681

How to use Google Analytics to track cross-domain image loads?

I have a simple-cheezy web site set up on Neocities for the single and sole purpose of hosting a single image. There is no other content, and this free web-hosting service exists only to host the single image. The reason why I am hosting the image here, is that I have another web hosting service provider where I wish to display the image, but the second provider does not support Google Analytics; Neocities does.

I'd like to embed the image (which is my organization's logo, so it's use is legal and users aren't getting stuffed with the typical, rogue blank gif). Sounds like Google Analytics could simply track image loads, where the image is hosted on Neocities and loaded via page views to the other web page.

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>The web site of abcdz</title>
    <!-- The style.css file allows you to change the look of your web pages.
         If you include the next line in all your web pages, they will all share the same look.
         This makes it easier to make new pages for your site. -->
    <link href="/style.css" rel="stylesheet" type="text/css" media="all">
<script>
  (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-xxxxxxxxx-2', 'auto');
  ga('send', 'pageview');

</script>
  </head>
  <body>
  <a target="_blank" href="http://www.abz.com/abcd/index.htm" id="anch_90" style="display: block; width: 80px; margin: auto"><img class="" 
  src="  http://abcdz.neocities.org/logo.png" width="200" height="260"
  alt="Organization Name." 
  title="Organization Name."></a>


  </body>
</html>

So back to my second web site, I embed the following, so users see my organization logo, and when they click on it, a new page opens to my organization home page. Just to reiterate, the second web host does not support Google Analytics, only simple HTML customization (I can't access head content), it is something like a CMS-style application.

  <a target="_blank" href="http://www.abz.com/abcd/index.htm" id="anch_90" style="display: block; width: 80px; margin: auto"><img class="" 
  src="  http://abcdz.neocities.org/logo.png" width="200" height="260"
  alt="organization Name." 
  title="Organization Name."></a>

Set up GA, seems to be working, when I visit http://abcdz.neocities.org/, GA statistics register the hit.

When I visit the other web page, which is loading only http://abcdz.neocities.org/logo.png, no GA "hits". Obviously, GA is tracking page views, but no tracking access to the logo.png that is embedded in the page but accessed cross-domain.

Certainly other people are doing this successfully, but how?

Upvotes: 0

Views: 1368

Answers (2)

Eike Pierstorff
Eike Pierstorff

Reputation: 32780

Google Analytics does not track images since images do not contain tracking code, so this is not caused by cross domain issue (it is in fact expected behavior, unless I really misunderstand your post).

GA tracks pages which are composed of multiple assets like HTML, images, scripts etc. Most people would not event want their assets tracked individually and are quite happy with page tracking, so there has been no need ever for Google to invent a workaround.

You can track when the image is successfully loaded into your html page (by using the onLoad-event of the image) but that does not seem to be what you are after.

You cannot track images that are called directly (unless they are really scripts that output an image after sending a server-side request to Analytics which does not seem feasible in your case).

Upvotes: 0

ABrowBoyGenius
ABrowBoyGenius

Reputation: 73

You can use Google URL builder to be able to track the image itself. Here is the directions for that: https://support.google.com/analytics/answer/1033867?hl=en

I am referencing this answer post on the Google Product Forum.

Upvotes: 1

Related Questions