Skip to:
Content
Pages
Categories
Search
Top
Bottom

Analytics kills Dashboard with Blank page


  • Mark
    Participant

    @markschafer

    I’ve added the following code to bp-custom.php to use Google Analytics. All attempts to access the dashboard (/wp-admin and /wp-admin/index.php) result in a blank page (the dashboard will appear for a second and then go blank). No PHP Error messages are generated. ALL other Admin and Public pages work fine.

    <div align="center">

    <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">
    try {
    var pageTracker = _gat._getTracker("UA-5834099-9");
    pageTracker._trackPageview();
    } catch(err) {}</script>

    </div>

    Source:

    http://www.pingsense.com/2009/11/buddypress-analytics-plugin/

    wpmu: 2.8.6, bp: 1.1.3

Viewing 16 replies - 1 through 16 (of 16 total)

  • Andrea Rennick
    Participant

    @andrea_r

    Why not just do this:

    http://wpmututorials.com/plugins/how-to-hook-into-the-footer/

    You really don’t need to be BP-specific or this.


    r-a-y
    Keymaster

    @r-a-y

    On the author’s plugin page, he says the plugin requires the BP bar, but it really doesn’t; it doesn’t hook into anything.

    Here’s the proper way to have written the plugin:

    function bp_ga_analytics() {
    echo '<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">
    try {
    var pageTracker = _gat._getTracker("UA-5834099-9");
    pageTracker._trackPageview();
    } catch(err) {}</script>';
    }
    add_action('bp_after_footer', 'bp_ga_analytics');

    You can also use Andrea’s tutorial as well, the difference between Andrea’s and mine is I’m using the bp_after_footer action, and not the wp_footer action.

    bp_after_footer shouldn’t hook into the admin dashboard as well, so this should be safe.


    netstay
    Participant

    @netstay

    That’s right r-a-y. I tried your solution and it’s works but it’s necesary to escape all apostrophe inside the echo command. I mean:

    function bp_ga_analytics() {

    echo ‘<script type=”text/javascript”>

    var gaJsHost = ((“https:” == document.location.protocol) ? “https://ssl.&#8221; : “http://www.&#8221;);

    document.write(unescape(“%3Cscript src=\'” + gaJsHost + “google-analytics.com/ga.js\’ type=\’text/javascript\’%3E%3C/script%3E”));

    </script>

    <script type=”text/javascript”>

    try {

    var pageTracker = _gat._getTracker(“UA-XXX”);

    pageTracker._trackPageview();

    } catch(err) {}</script>’;

    }

    add_action(‘bp_after_footer’, ‘bp_ga_analytics’);


    r-a-y
    Keymaster

    @r-a-y

    Yes you’re right, netstay… I typed it on the fly and didn’t check for apostrophes!

    Thanks!


    Sandeep Hegde
    Participant

    @sandeephegde

    Thanks for your support r-a-y, Andrea_r and netstay

    I have updated the plugin code at

    https://wordpress.org/extend/plugins/buddypress-analytics/

    http://www.pingsense.com/2009/11/buddypress-analytics-plugin/


    midwestbonsai
    Participant

    @midwestbonsai

    I get the following code showing on all pages even the admin area:

    function bp_ga_analytics() { echo ' '; } add_action('bp_after_footer', 'bp_ga_analytics');


    r-a-y
    Keymaster

    @r-a-y

    Sandeep didn’t wrap the open and close php tags properly…

    Replace whatever is in his PHP file with this:

    <?php
    /*
    Plugin Name: BP Analytics
    Description: Do you even need this plugin?
    Author: Whatever
    Version: 1.0
    */

    function bp_ga_analytics() {
    ?>

    <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">
    try {
    var pageTracker = _gat._getTracker("UA-XXX");
    pageTracker._trackPageview();
    } catch(err) {}</script>

    <?php
    }

    add_action('bp_after_footer', 'bp_ga_analytics');
    ?>


    midwestbonsai
    Participant

    @midwestbonsai

    That worked! Thanks!


    pcwriter
    Participant

    @pcwriter

    @r-a-y… or anyone else :-)

    I modified sandeep’s code as per your instructions and it worked fine BUT… Google Analytics hijacks my pages with their Content Overlay view, even if I’m signed out of Analytics, and covers up the admin bar so I can’t even access the dashboard. (I know, weird). I’ve deleted the file for now.

    Any ideas on this one?

    Plus, the code only showed in the source of my main site, but not in any member blogs. Know if this or any other similar plugin can be installed site-wide?


    r-a-y
    Keymaster

    @r-a-y

    I’ve never used GA’s content overlay, so I can’t tell you the specifics.

    Try clearing your internet cache / cookies to remove the site overlay setting.

    Member blogs are a different matter, since the member blogs do not use the BP theme.

    You can try modifying this line:

    add_action('bp_after_footer', 'bp_ga_analytics');

    with:

    add_action('wp_footer', 'bp_ga_analytics');

    Then put the plugin in /wp-content/mu-plugins/THEGAPLUGINFILE.php to activate Google Analytics on all your WPMU blogs.


    pcwriter
    Participant

    @pcwriter

    Thanks r-a-y! That worked on both accounts (cookies, huh).

    I kinda figured the file would have to go in mu-plugins, but hesitated trying anything for fear of really mucking things up ;-)

    Thanks again! I’m learning… slowly.


    jwack
    Participant

    @jwack

    I am looking to install GA on the main blog as well as all other sub blogs. Is the above method still the best way to do this? This was posted a few months ago so I wanted to double check. Thanks.


    r-a-y
    Keymaster

    @r-a-y

    It still applies, @jwack .


    jwack
    Participant

    @jwack

    Yup, works great across all blogs. Also, when I signed up for GA account it had an option specifically for sub-domains, which generated a slightly different script than the one in the example.


    r-a-y
    Keymaster

    @r-a-y

    @jwack – That’s why it’s called example code ;)


    jwack
    Participant

    @jwack

    When viewing on google analytics it give me the stats across all blogs, but it just says /pagename for all the page views etc. Can’t really tell what blog its coming from.

    Is there a better way to view stats (doesnt have to be GA)? GA’s documentation says I can use an “advanced filter” to view the full path, but it seems really confusing.

Viewing 16 replies - 1 through 16 (of 16 total)
  • The topic ‘Analytics kills Dashboard with Blank page’ is closed to new replies.
Skip to toolbar