0

I've got a third party app on my website, that allows me to receive bookings for my hostel. The idea is to get some funnel tracking going into google analytics. My access to the code of the app is limited, I'm guessing it will not allow me to insert javascript, because this code will not work even though it shows up in the source code of the iframe on my website:

<a href="mailto:x@xxxx.com.br" onClick="_gaq.push(['_trackEvent', 'BookNowApp', 'BankEmailClicked'])">email</a> 

The app will allow me to enter some html code into it's iframe on my website. For example, the link in the above example ended up in the iframe on my website and it works.

So I figure to write some javascript that will trigger when somebody clicks that link in the iframe of the third party app. I plan to load this into the page header:

<script type="text/javascript">
<!--
$('#mailto:x@xxxx.com.br').click(function(){
_gaq.push(['_trackEvent', 'BookNowApp', 'BankEmailClicked']); return false; });

// -->
</script>

The website is http://www.3dogshostelsaopaulo.com (click "BookReserva" for the app)

I'm hoping that with the above script, the only thing I need to incorporate in the HTML of the third party app is that clickable link. Any ideas why this wouldn't work are greatly appreciated!

1 Answers1

0

How are you defining _gaq in the iframe?

I assume the google tracking code is part of your website and is not available in iframe.
If that is the case, the JS in iframe doesnt know what _gaq means and the tracking will fail.

EDIT:

Since the iframe and the parent window are form different domains, the browsers wont allow communication between them for security reasons. There are some solution available to make such communication possible, but they somewhat complex. Here are a few references:

How to communicate between frames?
http://stevehanov.ca/blog/index.php?id=109

Community
  • 1
  • 1
Praveen B
  • 207
  • 1
  • 6
  • Hi thank you for looking into this! I've edited my post in the hope it clarifies. You're saying that I should enter a javascript into the iframe, for it to recognize the onClick event, right? Not sure if the app will allow me to enter anything but basic HTML. I didn't know that JS in my website's body doesn't propagate into my iframe. I do hope I can teach the JS in the body of my website to trigger on stuff that happens in the iframe somehow? – frodo eggens Oct 20 '13 at 11:49
  • Unfortunately the iframe won't accept my whole analytics tracking code. It would conveniently solve all problems, but alas. Thanks for your pointer, I'm gonna read all that :) I consider this topic closed. – frodo eggens Oct 20 '13 at 12:18
  • Ok, I think I found a workaround. Each different step in the third party app now loads a different image from the container website, my own website. I'm hoping I can get analytics to track the image loads. But the image load doesn't count as a pageload for analytics, and I cannot add onLoad event script to the image. So I need to work out how analytics.js tracks each image load. – frodo eggens Oct 20 '13 at 22:10