PDA

View Full Version : Hit Counter For Craigslist Postings


rusty.nells
04-15-2009, 04:00 AM
Anybody sell or advertise on craigslist?

Here's a little php script I put together to see how many page views my posts get. Whenever someone views my post, I get an email. The email is filtered and sent to it's own folder where I can easily get a count. You could also mod this to save data in a database or display an actual counter in the post.

This requires a web server with php and sendmail() enabled.

First, copy the following code and save as "view.php"

<?
if(isset($_GET['item']))
{
$ua = $_SERVER['HTTP_USER_AGENT'];

$ref = $_SERVER['HTTP_REFERER'];

$viewer = $_SERVER['REMOTE_ADDR'];

$item = $_GET['item'];

$Name = "Viewer";

$email = "myaddress@mydomain.com";

$recipient = "myaddress@mydomain.com"; //enter your own email address

$mail_body = "IP address is $viewer\n
Referrer is $ref\n\n
User Agent is $ua\n\n
More IP info - http://www.ip-adress.com/ip_tracer/?QRY=$viewer";

$subject = "$item Viewed by $viewer";

$header = "From: ". $Name . " <" . $email . ">\r\n";

mail($recipient, $subject, $mail_body, $header);

header("Location: index.php");
}

else

header("Location: index.php");
?>

You might want to change the $email variable. You'll definitely need to change the $recipient variable, enter your own email address. Save and upload to your web server.

Then (assuming you uploaded to the root directory) insert the following code in to your craigslist post. Edit MYWEBSITE.COM and YOUR_ITEM_NAME
<img src=http://MYWEBSITE.COM/view.php?item=YOUR_ITEM_NAME width=0 height=0>

This should work on other sites that allow the IMG tag.

TimeCode
04-15-2009, 06:32 AM
Good info. I bookmarked this page for my next CL post.

Thanks!!!

jaydude23
04-15-2009, 01:24 PM
Nice. I'll use this. Thanks!

LunchBox
04-16-2009, 01:17 AM
Anybody sell or advertise on craigslist?

Here's a little php script I put together to see how many page views my posts get. Whenever someone views my post, I get an email. The email is filtered and sent to it's own folder where I can easily get a count. You could also mod this to save data in a database or display an actual counter in the post.

This requires a web server with php and sendmail() enabled.

First, copy the following code and save as "view.php"

<?
if(isset($_GET['item']))
{
$ua = $_SERVER['HTTP_USER_AGENT'];

$ref = $_SERVER['HTTP_REFERER'];

$viewer = $_SERVER['REMOTE_ADDR'];

$item = $_GET['item'];

$Name = "Viewer";

$email = "myaddress@mydomain.com";

$recipient = "myaddress@mydomain.com"; //enter your own email address

$mail_body = "IP address is $viewer\n
Referrer is $ref\n\n
User Agent is $ua\n\n
More IP info - http://www.ip-adress.com/ip_tracer/?QRY=$viewer";

$subject = "$item Viewed by $viewer";

$header = "From: ". $Name . " <" . $email . ">\r\n";

mail($recipient, $subject, $mail_body, $header);

header("Location: index.php");
}

else

header("Location: index.php");
?>

You might want to change the $email variable. You'll definitely need to change the $recipient variable, enter your own email address. Save and upload to your web server.

Then (assuming you uploaded to the root directory) insert the following code in to your craigslist post. Edit MYWEBSITE.COM and YOUR_ITEM_NAME
<img src=http://MYWEBSITE.COM/view.php?item=YOUR_ITEM_NAME width=0 height=0>

This should work on other sites that allow the IMG tag.


This is fantastic. I dont want it to e-mail but I would like for it to keep a count on the page. What do I modify? I am not good at scripting.

From what I can tell this is set to e-mail (after we add our own e-mail address)

rusty.nells
04-16-2009, 03:13 AM
This is fantastic. I dont want it to e-mail but I would like for it to keep a count on the page. What do I modify? I am not good at scripting.

From what I can tell this is set to e-mail (after we add our own e-mail address)

It shouldn't be too hard to create. You'd need a database or text file to store the count. Also need to create a blank image and print the count on the image.

You'd also have to filter the input because anybody could manipulate the query string.

If I can find the time (and motivation) I'll see what I can put together. Might be a few months:D

LunchBox
04-16-2009, 04:49 AM
It shouldn't be too hard to create. You'd need a database or text file to store the count. Also need to create a blank image and print the count on the image.

You'd also have to filter the input because anybody could manipulate the query string.

If I can find the time (and motivation) I'll see what I can put together. Might be a few months:D

Dang I knew that I should have taken scripting and HTML.

LunchBox
04-16-2009, 05:20 AM
I just found a craigslist posting with a counter but I dont see when I go to view source I dont see when the counter is. The image does not go else where like photobucket etc.

That could be cool to have. That way I can check how many people seen the add.

Methical
04-16-2009, 05:27 AM
Couldn't you just use a simple javascript code to do that?

LunchBox
04-16-2009, 05:39 AM
Couldn't you just use a simple javascript code to do that?


I have been searching google and all counters that supposedly work are not really working. I am talking about the copy and paste one where everything is ready to go.

Can you do a simple script? buddy, pal :D

Methical
04-16-2009, 05:50 AM
Lol
well if all the usual javascripts page counters from the normal cut and paste sites found via google don't work, would any javascript work at all

I am not familiar with Craiglist, doesn't apply to me in my country (to my knowledge) I can actually say I've NEVER visited the site. Is there a page that lists which scripts are applicable in an ad? Or anything similar?

*** EDIT ***

@LunchBox

suck up ;)

rusty.nells
04-16-2009, 05:55 AM
Couldn't you just use a simple javascript code to do that?

Craigslist doesn't allow javascript. Also a hit counter requires a server-side script to process and store the data. However, there are some services that use javascript to access a server-side script to display a hit counter.

rusty.nells
04-16-2009, 05:59 AM
...I am not familiar with Craiglist, doesn't apply to me in my country...

Try this http://christchurch.craigslist.org/
(http://christchurch.craigslist.org/)

Not much there though.

Methical
04-16-2009, 06:00 AM
Yeah i know it required server-side scripting, somethin' needs to calculate and store the data .

As previous, I have never visited CL so I don't know what it allows.
Well now that I know that you can't use JS, click here (http://www.ecommerce-blog.org/archives/how-to-track-craigslist-ads/)

Methical
04-16-2009, 06:05 AM
Try this http://christchurch.craigslist.org/
(http://christchurch.craigslist.org/)

Not much there though.

Well I went there, and left 5 seconds later..

Whats the deal with Craigslist anyway? It looks like a cheap rip-off of yellow pages lol

LunchBox
04-16-2009, 06:30 AM
Well I went there, and left 5 seconds later..

Whats the deal with Craigslist anyway? It looks like a cheap rip-off of yellow pages lol

LOL . Yeah it a classified ad online. Very popular. I worked once at a place one that posted "free office furniture" within 30 minutes it was gone.

I tried that link you posted (that was the first one I come across) but it didnt work. Maybe I just suck at copying and pasting.

When you see pizza techs, they a lot of time mean the techs that post at craigslist for $20 jobs.

Methical
04-16-2009, 06:53 AM
I'm sure if people use there common sense then they would figure that $20 isn't really ideal for gettin' your PC fixed. Thats just a little too cheap; ecspecially when everyone has a "friend who knows computers", which is what im assuming all the 'pizza techs' that post $20 job ads on CL.

Lol I didn't wanna pay out CL to much incase I got flamed about it before, cos i know a few people on here use CL. But anyway, it looks like a 12-year old script kiddie who just learnt how to use <table> <tr> and <td> tags in HTML lol

Copy and paste this;

http://www.ecommerce-blog.org/archives/how-to-track-craigslist-ads/


It mentions HTML only counters, which directs you to hitslog.com (http://www.hitslog.com) and statcounter.com (http://www.statcounter.com)

If you can't get that one right, donate some money into my PayPal and I'll write you a tutorial on how to copy some text, and paste it into a address bar of a browser, it is quite complex, and I'm sure I could stretch it out to 20 step tutorial lol buddy, pal :D

daquigle
04-16-2009, 07:38 AM
This works great. I'll be using it to see how different ad titles perform. Thanks for sharing.

Methical
04-16-2009, 10:07 AM
Glad I can help you with somethin' i've never used before :)

rusty.nells
04-18-2009, 07:36 AM
This is fantastic. I dont want it to e-mail but I would like for it to keep a count on the page. What do I modify? I am not good at scripting.

I just put together a script for you. It's late (yawn) so I will post it later this weekend. You owe me :D

It requires PHP with GD and MySQL

LunchBox
04-18-2009, 08:53 PM
I just put together a script for you. It's late (yawn) so I will post it later this weekend. You owe me :D

It requires PHP with GD and MySQL

I finally discovered what I was doing wrong with the code I found on the internet. I was just pasting straight into craigslist. I did not know I had to create at account (which is free). The counter has no advertisement around it unless you click in the counter which takes you to the hit counter web page. Now I know how many people see my ads. I created two counters one for each ad to see which one gets more hits.

I dont have a website yet. But once I do having a counter not tied to some other site is much better.

rusty.nells
04-19-2009, 06:41 AM
Here it is, the actual hit counter -> http://technibblerocks.atbhost.net/viewer.php?item=technibble

First of all, I should warn you:

I am not an expert PHP coder. I can't guarantee the worthiness of this script. If you get a twitter worm or attract the attention of any government agencies, it's not my fault :D

Anyone can do whatever you like with this script. Post it on a blog, post it on sourceforge, sell it on ebay etc. You are not bound by any license, this is absolutely free for personal or commercial use. You don't even have to credit me. However, if you're feeling generous, you can credit "copyright1968" (my usual online nickname).

It's just a simple script, nothing fancy, no cool features. It counts all page views, not unique page views. If you were to view a page with this counter and refresh the page 10 times, the count will be incremented by 10.

There's no need to enter items into the database, they are automatically added via the query string (eg. ?item=WHATEVER). Once you create the database, you never have to bother with it again. Unless you want to remove items, and you likely will.

This requires PHP with GD and MySQL. For MySQL you'll need a database, database host, user name and password, all are usually provided by your host. If you run your own server, you'll already know these.

Just copy and save the following code as viewer.php (or any name). Edit the $db, $dbhost, $dbuser and $dbpassword fields with your info.

<?php

$db = "";
$dbhost = "";
$dbuser = "";
$dbpassword = "";

if(isset($_GET['item']))
{

if ($_GET['item'] == "showall"){
mysql_connect($dbhost, $dbuser, $dbpassword) or die(mysql_error()) ;
mysql_select_db($db) or die(mysql_error()) ;
$result = mysql_query("SELECT * FROM clcounter") ;
echo "<table border=1 width=400><tr><td width=200><b>Item</b></td><td width=200><b>Count</b></td></tr>";
while($row=mysql_fetch_array($result)){
echo "<tr><td>$row[item]</td><td>$row[viewcount]</td></tr>";

}
echo "</table>";
exit();
}

$item = addslashes($_GET['item']);

mysql_connect($dbhost, $dbuser, $dbpassword) or die(mysql_error()) ;
mysql_select_db($db) or die(mysql_error()) ;
$result = mysql_query("SELECT viewcount FROM clcounter WHERE item = '$item'") ;

$check = mysql_num_rows($result);

if ($check == 0) {
mysql_query("INSERT INTO clcounter (item, viewcount) VALUES ('$item', '0')") ;
}
$result = mysql_query("SELECT viewcount FROM clcounter WHERE item = '$item'") ;
while($row = mysql_fetch_array($result)){
$viewcount = $row['viewcount'];
$viewcount++;
mysql_query("UPDATE clcounter SET viewcount='$viewcount' WHERE item = '$item'") ;

}

$pagecounter = imagecreate(60, 20);
$background = imagecolorallocate($pagecounter, 255, 153, 0);
$textcolor = imagecolorallocate($pagecounter, 0, 0, 0);
imagestring($pagecounter, 5, 4, 4, $viewcount, $textcolor);

header("Content-type: image/png");
imagepng($pagecounter);
imagecolordeallocate($textcolor);
imagecolordeallocate($background);
imagedestroy($pagecounter);

}else{
header("Location: index.php");
}
?>



Next, create the table clcounter in your database. You'll need two fields for item and viewcount. You can create it manually or use the following SQL code


CREATE TABLE `clcounter` (
`item` tinytext collate latin1_general_cs NOT NULL,
`viewcount` smallint(7) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_cs;


Now (assuming you uploaded to the root directory) insert the following code in to your craigslist post. Edit MYWEBSITE.COM and YOUR_ITEM_NAME. If item=showall, it will list all items and their page views.
<img src=http://MYWEBSITE.COM/viewer.php?item=YOUR_ITEM_NAME width=60 height=20 border=1>

I uploaded this to http://technibblerocks.atbhost.net/viewer.php?item=showall (a free host). If you don't have a web site, you can use this one:
<img src=http://technibblerocks.atbhost.net/viewer.php?item=YOUR_ITEM_NAME width=60 height=20 border=1>

each item name should be unique to display the page views for that specific item. If not, multiple counters will display the same number for multiple posts with the same item name.