[resolved] Post previews affecting stats (9 posts)

  1. blogjunkie
    Posted 10 years ago #

    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">
    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 id="stats_script" type="text/javascript" src="http://metrics.performancing.com/wp.js"></script>

    Appreciate all your advice, thanks!

  2. spencerp
    Posted 10 years ago #

    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


    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..


    However, I'd hate to do that though, because it helps me see what it looks like before actually hitting "publish"... =/

  3. blogjunkie
    Posted 10 years ago #

    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.

  4. alrescha
    Posted 10 years ago #

    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.

  5. blogjunkie
    Posted 10 years ago #

    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!

  6. alrescha
    Posted 10 years ago #

    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. :P

  7. blogjunkie
    Posted 10 years ago #

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

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

  8. davereid20
    Posted 10 years ago #

    Hey blogjunkie, I'm the author of the Performancing Metrics plugin (http://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!

  9. blogjunkie
    Posted 10 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic