Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 03-15-2008, 03:31 AM
neverstop neverstop is offline
 
Join Date: Jan 2007
Posts: 170
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Ajax - Trying to count thread views on outgoing links.

Hi,

I will preface by saying I am a total noob and I really know nothing.

I am trying to use one of my forums as a link dump/directory. I am trying to count the thread views on an outbound link (ie clicking the link increases thread views by 1). I found a snippet of code on another forum and I am trying to get it to fill my needs:

Code:
<script type="text/javascript">
function trackClick( id ){
    var url = "http://www.amateurpornster.com/showthread.php?t=" + id;
    xmlRequestObj = window.XMLHttpRequest?new XMLHttpRequest():new ActiveXObject("Microsoft.XMLHTTP")
    xmlRequestObj.open("GET", url, true);
    xmlRequestObj.send(null);
    return false;
}
</script>
So I am using a link like this in the threadbit template (in this forum (3) I will just put the URL in as the post body so $thread[preview] becomes the URL):

Code:
<a href=<if condition="in_array($forumid, array(3))">"$thread[preview]" onClick="trackClick( '$thread[threadid]' );" target="_blank"<else />"showthread.php?$session[sessionurl]t=$thread[threadid]"</if> id="thread_title_$thread[realthreadid]"<if condition="$show['gotonewpost']"> style="font-weight:bold"</if>>$thread[threadtitle]</a>
Now I may be completely off, but should that work for counting the views when the trackClick function is triggered by clicking on the link?

Any help would be appreciated, or just tell me it wont work and I will look for another solution!

Cheers,
Ian
Reply With Quote
  #2  
Old 03-15-2008, 06:06 AM
SEOvB's Avatar
SEOvB SEOvB is offline
 
Join Date: May 2007
Location: Indianapolis
Posts: 2,451
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

No clue, but Google Analyitcs provides this information and its free and a lot easier to implement
Reply With Quote
  #3  
Old 03-15-2008, 06:06 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

But then you'll get an increase on the thread view by 2 (one for entering thread, one for clicking link), and this isn't what you want, right?
Reply With Quote
  #4  
Old 03-15-2008, 06:42 AM
neverstop neverstop is offline
 
Join Date: Jan 2007
Posts: 170
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by FRDS View Post
No clue, but Google Analyitcs provides this information and its free and a lot easier to implement
Oh yeah? Can you elaborate please?

Quote:
Originally Posted by Dismounted View Post
But then you'll get an increase on the thread view by 2 (one for entering thread, one for clicking link), and this isn't what you want, right?
Not exactly...

When they click the thread title link they wont be taken to the thread:

Code:
<a href=<if condition="in_array($forumid, array(3))">"$thread[preview]" onClick="trackClick( '$thread[threadid]' );" target="_blank"<else /> ...
$thread[preview] = the URL i want to go to. It all works but except the function isn't working afaik (ie: the views arent going up).

--------------- Added [DATE]1205605006[/DATE] at [TIME]1205605006[/TIME] ---------------

Ok my mistake, this seems to be working. Since my board is not live yet I am the only one on the site so the cron to count thread views wasnt getting triggered.

Now that I know the function is working, I don't think showthread.php is appropriate for this when I can have a much smaller file accomplish the same.

Can anyone show me how to write a file that would basically:

UPDATE " . TABLE_PREFIX . "thread
SET views = views + 1
WHERE threadid = the thread id that was clicked

Cheers,
Ian
Reply With Quote
  #5  
Old 03-17-2008, 07:27 PM
neverstop neverstop is offline
 
Join Date: Jan 2007
Posts: 170
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by neverstop

Can anyone show me how to write a file that would basically:

UPDATE " . TABLE_PREFIX . "thread
SET views = views + 1
WHERE threadid = the thread id that was clicked

Cheers,
Ian
Bump...

Basically I want to make a file (track.php) that when clicked adds a view to the thread table. So clicking on track.php?id=15 would update thread 15 with one more view. Not sure if its possible to have it update hourly like regular thread views?

Can someone help me out on this one pls.

Thanks in advance,
Ian
Reply With Quote
  #6  
Old 03-17-2008, 08:57 PM
MoT3rror MoT3rror is offline
 
Join Date: Mar 2007
Posts: 423
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Here is the php code for it
PHP Code:
// update views counter
if ($vbulletin->options['threadviewslive'])
{
    
// doing it as they happen; for optimization purposes, this cannot use a DM!
    
$db->shutdown_query("
        UPDATE " 
TABLE_PREFIX "thread
        SET views = views + 1
        WHERE threadid = " 
intval($threadinfo['threadid'])
    );
}
else
{
    
// or doing it once an hour
    
$db->shutdown_query("
        INSERT INTO " 
TABLE_PREFIX "threadviews (threadid)
        VALUES (" 
intval($threadinfo['threadid']) . ')'
    
);

You can find that in showthread.php
Reply With Quote
  #7  
Old 03-18-2008, 04:10 AM
neverstop neverstop is offline
 
Join Date: Jan 2007
Posts: 170
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by MoT3rror View Post
Here is the php code for it
PHP Code:
// update views counter
if ($vbulletin->options['threadviewslive'])
{
    
// doing it as they happen; for optimization purposes, this cannot use a DM!
    
$db->shutdown_query("
        UPDATE " 
TABLE_PREFIX "thread
        SET views = views + 1
        WHERE threadid = " 
intval($threadinfo['threadid'])
    );
}
else
{
    
// or doing it once an hour
    
$db->shutdown_query("
        INSERT INTO " 
TABLE_PREFIX "threadviews (threadid)
        VALUES (" 
intval($threadinfo['threadid']) . ')'
    
);

You can find that in showthread.php
OK cool. Now I am a beginner so please bear with me here. How do I make a new file with that? Where it would take the id (track.php?id=x)from the url and update the table?

Cheers,
Ian
Reply With Quote
  #8  
Old 03-18-2008, 04:49 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

PHP Code:
<?php

// setup vbulletin backend
require_once('./global.php');

// clean id
$threadid intval($_GET['id']);

// exit if empty id
if (!$threadid)
{
    exit;
}

// update views counter
if ($vbulletin->options['threadviewslive'])
{
    
// doing it as they happen; for optimization purposes, this cannot use a DM!
    
$db->shutdown_query("
        UPDATE " 
TABLE_PREFIX "thread
        SET views = views + 1
        WHERE threadid = 
$threadid
    "
);
}
else
{
    
// or doing it once an hour
    
$db->shutdown_query("
        INSERT INTO " 
TABLE_PREFIX "threadviews
        (threadid)
        VALUES
        (
$threadid)
    "
);
}

?>
Put it in a file called track.php and upload it.
Reply With Quote
  #9  
Old 03-18-2008, 02:22 PM
neverstop neverstop is offline
 
Join Date: Jan 2007
Posts: 170
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hmmm, the above code does not seem to be working, the views are not being added. If I go to the file in my browser (ie:www.mydomain.com/track.php?id=15) I get a white screen (that is expected I guess) and there is no error or anything, views not being added. Tried changing the admincp option to both hourly and instant but no changes.

Cheers
Reply With Quote
  #10  
Old 03-19-2008, 05:12 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Please try this and report the output.
PHP Code:
<?php

// setup vbulletin backend
require_once('./global.php');

// clean id
$threadid intval($_GET['id']);

// exit if empty id
if (!$threadid)
{
    die(
'Invalid Thread ID');
}

// update views counter
if ($vbulletin->options['threadviewslive'])
{
    
// doing it as they happen; for optimization purposes, this cannot use a DM!
    
$db->shutdown_query("
        UPDATE " 
TABLE_PREFIX "thread
        SET views = views + 1
        WHERE threadid = 
$threadid
    "
);
}
else
{
    
// or doing it once an hour
    
$db->shutdown_query("
        INSERT INTO " 
TABLE_PREFIX "threadviews
        (threadid)
        VALUES
        (
$threadid)
    "
);
}

die(
'Thread View Added');
?>
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 01:38 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04492 seconds
  • Memory Usage 2,285KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (3)bbcode_code
  • (4)bbcode_php
  • (4)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete