Closed (fixed)
Project:
Drupal.org site moderators
Component:
Other
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
10 Nov 2008 at 16:23 UTC
Updated:
28 Nov 2008 at 07:52 UTC
Hello,
We are working on the "pivots module recommendation system" for D.O. It is a customized block deployed on D.O. already, e.g. http://drupal.org/project/archiver
We inserted a few lines of Google Analytics code into the block in order to collect usage data to improve the recommendation algorithm. The GA code looks like below, where $output is the block content.
if (!empty($output)) {
// GA code for pageviews
$output .= '
<script type="text/javascript">var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");document.write(unescape("%3Cscript src=\'" + gaJsHost + "google-analytics.com/ga.js\' type=\'text/javascript\'%3E%3C/script%3E"));</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-2360451-1");
pageTracker._trackPageview("/pivotslog/pageview/'.$_pivots_block_pid_double.'/'.$node_id.'");
</script>';
}
However, when it's rendered in D.O., the HTML looks like:
<script type="text/javascript">var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");document.write(unesca<wbr />pe("%3Cscrip<wbr />t src='" + gaJsHost + "google-anal<wbr />ytics.com/ga.js' type='text/javascript'%<wbr />3E%3C/script%3E"))<wbr />;</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker(<wbr />"UA-2360451-<wbr />1");
pageTracker._trackPagevi<wbr />ew("/pivotslog/pageview/4153/132961");
</script>
Note that several tags were inserted into the
block. For example, "pageTracker._trackPageview()". It distorted the entire Javascript. I searched D.O. and learned that was a design decision for the D.O. Bluebeach theme. I'm fine with it. I'm just wondering if there's some way to control it so that it's not applied to the tag? Thanks.
Comments
Comment #1
killes@www.drop.org commentedthe wbr is created by a function which is run over the output of all blocks of one region before outputting the content in page.tpl.php. I am not sure how to exempt your block from this...
Comment #2
kbahey commentedHow about modifying hook_block() in the pivots module here to add the code that you are after, instead of pasting it in a block?
Comment #3
killes@www.drop.org commentedWon't help:
print(word_split($sidebar_left));Comment #4
drummWhy is the full GA code, with the same UA-... ID being output in a block? This is already in the footer.
Can this just be added to the Custom JavaScript code field of the Google Analytics module configuration?
Comment #5
danithaca commentedWe'd like to track the pageview when the pivots block was loaded. That's before the GA code in the footer. That's why we included it in the block. In terms of performance concern, the same GA javascript will not load again because of caching.
I'm trying to study the problem and the Custom Javascript field of the GA module configuration. I'll submit a patch asap when it's fixed. Thanks for all the help I received!!
Comment #6
drummHave pivots do a
drupal_add_js(array('pivotsMeta' => array($_pivots_block_pid_double, ...), 'setting');and all the info you need should be available at the bottom of the page in Drupal.settings.pivotsMeta.Google runs some good servers, but I still don't trust them to not slow down our page load.