0

Because of Google Analytics I would need to use JavaScipt to load iFrame to my Drupal template. I use this only just on one custom content type template.

Can I put the JavaScript straight to the template?

At the moment the JavaScript in my node template is like this:

<script type="text/javascript">
var iframe = document.getElementById('myIFrame');
iframe.src = pageTracker._getLinkerUrl('http://mydomain.com/iframepage/');

</script>

<iframe id="myIFrame" height="500px" width="350"></iframe>

But it doesn't load anything to the iFrame. I followed this http://code.google.com/intl/fi/apis/analytics/docs/tracking/gaTrackingSite.html#trackingIFrames

Any idea where the problem is?

EDIT: noticed that I get error: "Uncaught ReferenceError: pageTracker is not defined"

3
1

Your code is missing some important stuff. The original code from the Google page you linked yourself:

_gaq.push(function() {
  var pageTracker = _gat._getTrackerByName();
  var iframe = document.getElementById('myIFrame');
  iframe.src = pageTracker._getLinkerUrl('http://www.my-example-iframecontent.com/');
});

So you would end up with something like the following.

<script type="text/javascript">_gaq.push(function () {
  document.getElementById('myIFrame').src = _gat._getTrackerByName()._getLinkerUrl('http://www.my-example-iframecontent.com/');
});</script>
<iframe id="myIFrame" height="500px" width="350"></iframe>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.