• Resolved David Wang

    (@blogjunkie)


    Hi guys,

    I’m a WordPress newbie and loving it.

    I’ve got a question though. I notice post previews are affecting my web stats (Performancing). Today I saved a draft entry and as usual the write page shows me a preview although the post has not been published yet. Later when I checked my stats I noticed that my draft entry registered a page view.

    Is there some way I can hide the stats code so that it does not show up in the previews? A conditional tag or something? Like I said, I’m new.

    Here’s the code I stuck into my template. It’s placed right before the </body> tag.


    <script type="text/javascript">
    <?php
    global $userdata;
    if ($userdata) {
    echo "z_user_name=\"" . $userdata->display_name . "\";\n";
    echo "z_user_email=\"" . $userdata->user_email . "\";\n";
    }
    ?>
    z_post_title="<?php the_title();?>";
    z_post_category="<?php $c=get_the_category();echo $c[0]->cat_name;?>";
    </script>
    <script id="stats_script" type="text/javascript" src="https://metrics.performancing.com/wp.js"></script>

    Appreciate all your advice, thanks!

Viewing 8 replies - 1 through 8 (of 8 total)
  • blogjunkie, I’m right there with ya. I hate that, but the only thing to do really, is maybe remove the “preview window”. I’m not sure where the thread is now, but I’m sure someone will give it here soon.

    I have it removed on the localhost version though, maybe I can upload it to the FTP and give link for it here then.. The file with it removed I mean.. =P

    https://www.vindictivebastard.net/downloads/post.php.txt

    That *should* be it, just replace whatever is inside the wp-admin/post.php file, with that code.. And reupload it to the right place: wp-admin/ directory.

    Unless I’m wrong…someone will show ya the right way lol..

    spencerp

    However, I’d hate to do that though, because it helps me see what it looks like before actually hitting “publish”… =/

    Thread Starter David Wang

    (@blogjunkie)

    thanks spencerp for the modified file! ..but i’m still gonna wait a while longer to see if anyone else has another solution. let’s keep our fingers crossed.

    If you have a look at the Write Post page, you’ll see that the post preview iframe uses this kind of url to show the preview page: blog_url?p=post_id&preview=true

    In other words, enclose your entire stat script in an PHP if statement, check if the POST variable contains the preview variable and is set to true. If so, then don’t print the stats code.

    Thread Starter David Wang

    (@blogjunkie)

    hey alrescha – great idea! did i mention i’m a PHP noob too? appreciate it if you could give me a sample block of code.. thanks!

    Hmmm…I’m only a PHP beginner, but I would say something like this:

    <?php if (!($_POST['preview']==true)) { ?>
    (then here goes all your stat code)
    <?php } ?>

    I’m actually not sure which is $_POST or which is $_GET, just try $_GET if it doesn’t work.

    No guarantee that this will work, though. Maybe a PHP guru wondering by will help out. ??

    Thread Starter David Wang

    (@blogjunkie)

    This is what I did, and it looks like its working:


    <?php
    if($_GET['preview'] != 'true') {
    include (TEMPLATEPATH . '/stats.php');
    }

    Hey blogjunkie, I’m the author of the Performancing Metrics plugin (https://davereid.net/projects/wordpress/pmetrics) – and there’s an option to disable the tracking script when you’re logged in as an administrator, which also covers post previews (since you have to be logged in to use the dashboard). Maybe it might be another solution for you to consider – let me know!

    Thread Starter David Wang

    (@blogjunkie)

    Hey that sounds great! I’ll be sure to give a look. Thanks!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Post previews affecting stats’ is closed to new replies.