'; $mid = (int) $_GET['qx']; $rv = ''; $hitTot = 0; if ($mid > 0) { $sql = 'SELECT s.subject_id, s.hit_cnt, s.subject_nm, a.ad_id, s.title FROM Subject s, Google_Ad a WHERE a.merchant_id = '.$mid.' and s.subject_nm <> \'\' and a.ad_id = s.ad_id'; if ($r=mysql_query($sql)) { while (list($subject_id, $hit_cnt, $subject_nm, $ad_id, $title) = mysql_fetch_row($r)) { $subURL = ($subject_id > 741)? 'http://protophoto.com/g/'.$subject_nm : 'http://protophoto.com/subject.html?subject_id='.$subject_id; $rv .= sprintf('% 11d',$hit_cnt).' '.$subject_nm.'
'; $hitTot += $hit_cnt; } } if ($hitTot > 0) { echo '

Photo Galleries

The merchant has a a box ads placed on the following photo galleries:

'.$rv.'
'.sprintf('% 11d',$hitTot).' Total Page Views'; } else { echo ' '; // just send a file with one blank space. } $frv = ''; $fsql = 'SELECT f.fob_id, f.category_id, f.start_dt, f.end_dt, c.category_nm, c.file_nm FROM FOB_Listing f, FOB_Category c WHERE f.category_id = c.category_id and f.merchant_id = '.$mid; if ($r=mysql_query($fsql)) { while (list($fob_id, $cat_id, $startDt, $endDt, $catName, $catFile) = mysql_fetch_row($r)) { $frv .= $startDt.' '.$endDt.' '.$catName.'
'; $hitTot += $hit_cnt; } } if ($frv == '') { echo ''; } else { echo '

A Fountain of Bargains

aFountainOfBargains was an attempt to create a pure affiliate/coupon site. Your merchant site is listed on the following pages. The start start shows the date the ad appears. The end date shows the removal date: '.$frv; } } echo '

Reported Earnings

This final table shows reported earnings for the affiliate arrangement drawn on a quarterly basis from the affiliate network or whatever reporting tools were provided by the merchant. The "imprs" comlumn shows reported impressions. I do not display the null bit with each ad displa; so this figure is inaccurate.

'; sqlTable("Earnings History",'',"SELECT concat(i.year,'-',floor((i.month + 2)/3)) 'Quarter', sum(impressions) '+Imprs', sum(h.hits) '+Hits', sum(h.actions) '+Actions', sum(h.sales_amt) '+Sales', sum(h.revenue_amt) '+Commission' FROM Rev_Import i, Rev_Hist h WHERE h.merchant_id = $mid and h.import_id = i.import_id GROUP BY i.year, floor((i.month + 2)/3) ORDER BY i.year DESC, i.month DESC"); } function getMNotes($m) { $rv=""; if ($result=mysql_query("SELECT note_id, note_dt, short_desc FROM Merchant_Note WHERE merchant_id=$m ORDER BY note_dt")) { while (list($note_id,$note_dt,$short_desc) = mysql_fetch_row($result)) { $rv .= $note_dt.": ".$short_desc."
\n"; } } return ($rv == "")? "" : "
".$rv."
"; } function catSum() { displayHead("Merchant Detail - $merchant_nm"); echo '

All of the ambitious plans I had for the Community Color sites got hung up on the inability to generate income. Hiring a minimum clerk in the US requires some $40k in income. Hiring a programmer would requires $100k. The site is lucky to break $1k a month. In an attempt to solve the income problem, I decided to categorize the advertisers on the site to determine where I should concentrate to make an income.

'; $hCnt = 0; $sql = 'SELECT m.category_id, m.active_cd, g.group_nm, c.category_nm, c.la_cat, c.fob_pg, count(*) Count, sum(tot_hits) Hits, sum(tot_commissions) Earnings FROM Merchant m, Merchant_Category c, Merchant_Cat_Group g WHERE m.category_id = c.category_id and c.group_id = g.group_id GROUP BY m.category_id, active_cd ORDER BY m.category_id, m.active_cd'; $holdCat = -1; $holdStr = ''; $cnt = 0; if ($r = mysql_query($sql)) { while (list($category_id, $active_cd, $group_nm, $category_nm, $la_cat, $fob_pg, $cnt, $tot_hits, $tot_commissions) = mysql_fetch_row($r)) { $cnt++; if ($holdCat != $category_id) { if ($holdCat > 0) { // holdStr contains start of row. echo ' '.$holdStr; echo $activeCnt.''; } $cNm = ($la_cat > 0) ? ''.$category_nm.'' : $category_nm; if ($fob_pg != '') $cNm .= ' (more) '; // set the variabls for the next category. $rColor = (($hCnt++ %2) == 0)? 'EEE' : 'CCC'; $holdStr = ''; echo '
Category Active
Count
Active
Hits
Active
Revenue
Inactive
Count
Inactive
Hits
Inactive
Revenue
Total
Count
Total
Hits
Total
Revenu
'.$activeHits.''.number_format($activeComm,2); echo ''.$termCnt.''.$termHits.''.number_format($termComm,2); echo ''.($activeCnt + $termCnt).''.($termHits + $activeHits).''.number_format($termComm + $activeComm,2).'
'.$cNm.''; $holdCat = $category_id; $activeCnt = 0; $activeHits = 0; $activeComm = 0; $termCnt = 0; $termHits = 0; $termComm = 0; } if ($active_cd == 'N') { $activeCnt = $cnt; $activeHits = $tot_hits; $activeComm = $tot_commissions; } else { $termCnt = $cnt; $termHits = $tot_hits; $termComm = $tot_commissions; } } } echo ' '.$holdStr; echo $activeCnt.''.$activeHits.''.number_format($activeComm,2); echo ''.$termCnt.''.$termHits.''.number_format($termComm,2); echo ''.($activeCnt + $termCnt).''.($termHits + $activeHits).''.number_format($termComm + $activeComm,2).'
'; displayFoot(); } function networkMonth($prog_cd) { $prog_nm = sqlValue("SELECT prog_nm FROM Merchant_Network WHERE prog_cd like '$prog_cd'"); displayHead('Network Data - '.$prog_nm); sqlTable("Network Earnings By Quarter - ".$prog_nm,'',"SELECT concat(i.year,' Q',ceil(i.month/3)) Quarter, count( DISTINCT h.merchant_id ) Merchants, sum( impressions ) Impressions, sum( hits ) '+Hits', sum( actions ) '+Actions', sum( revenue_amt ) '+Revenue' FROM Rev_Hist h, Rev_Import i WHERE h.import_id = i.import_id AND h.prog_cd = '$prog_cd' GROUP BY i.year, ceil(i.month/3) ORDER BY i.year DESC, Quarter DESC"); } function networkSum() { displayHead("Merchant Network Summary"); echo showBlob(0); sqlTable("Network Summary",'',"SELECT h.prog_cd, n.prog_nm Network, count(distinct merchant_id) '+Merchants', concat('',sum(hits),'') '+Hits', sum(actions) '+Actions', sum(sales_amt) '+Sales', sum(revenue_amt) '+Revenue', (sum(revenue_amt) *100 / sum(hits)) EPC, (sum(revenue_amt) / count(distinct merchant_id)) 'Avg Merchant' FROM Rev_Hist h LEFT JOIN Merchant_Network n ON h.prog_cd = n.prog_cd GROUP BY h.prog_cd ORDER BY h.prog_cd"); } function merchantError() { displayHead("Merchant Errors"); echo "

This reports shows traffic to Share-a-Sale Merchants generating errors. If a merchant falls behind in their payments, SaS sends the click back to the referrer. SaS implemented these procedure to encourage merchants to keep up with their payments. This report shows the number of merchant errors in the last 60 days.

\n"; sqlTable("Merchant Error Report",'',"SELECT concat('',m.merchant_nm,'') Merchant, count(*) Hits, date_format(min(ts),'%Y-%m-%e') First, date_format(max(ts),'%Y-%m-%e') Last FROM Merchant m, Merchant_Error e WHERE e.merchant_id = m.merchant_id and e.ts > DATE_SUB(CURDATE(),INTERVAL 60 DAY) GROUP BY e.merchant_id"); } function getPages($merchant_id) { $rv=''; $sql = "SELECT p.community_id, p.pg, p.hits, c.community_nm, c.url FROM Merchant_Page p, Community c WHERE p.merchant_id = $merchant_id and p.community_id = c.community_id"; $tHits = 0; if ($result = mysql_query($sql)) { while (list($community_id, $pg, $hits, $community_nm, $url) = mysql_fetch_row($result)) { if ($rv != '') $rv .= "
"; $rv .= "($hits hits) $community_nm "; $tHits += $hits; } } $rv .= ($tHits > 0)? "
Total: $tHits" : ''; return $rv; } function getReviews($merchant_id) { $sql = 'SELECT dt, site_nm, hits FROM Merchant_Cool WHERE merchant_id = '.$merchant_id; $rv = ''; if ($r=mysql_query($sql)) { while (list($dt, $nm, $hits) = mysql_fetch_row($r)) { if ($rv != '') $rv .= '
'; $rv .= "$nm ($dt: $hits hits)"; } } if ($rv !='') hPC("Review",$rv); } function showMerchant($merchant_id,$merchant_nm, $prog, $weight, $display_yn, $foreign_id, $ticker, $city, $state_cd, $url, $ad_url) { displayHead("Merchant Detail - $merchant_nm"); hTable("Merchant Detail"); hPC("Merchant Name",$merchant_nm); hPC("Program",$prog); // hPC("Display",inpCB('display_yn',$display_yn,'Y')); // hPC("Weight +1 9- ",numberSelect("weight",$weight,1,9)); // hPC("Foreign ID",inpTxt("foreign_id",$foreign_id,25,32)); if ($ticker != '') hPC("Stock Ticker",$ticker); if ($city != '') hPC("Headquarters",$city.", ".$state_cd); if ($url!= '') hPC("Company URL","$url"); if ($ad_url != '') hPC("Company URL","$ad_url"); getReviews($merchant_id); hPC("Pages",getPages($merchant_id)); hPC("Notes",getMNotes($merchant_id)); if (hasAccess()) hPC('Administration','edit'); echo "\n"; echo "

The page section shows summary information on merchants. The purpose of this page is to help me keep track of advertisers on the directories I created. It includes links to different places where ads appear. The earnings report show earnings by month. The imprs column is inaccurate for most merchants, the hits and revenue is generally more accurate. The aFOB table shows if the site appears in a Fountain of Bargains.

"; sqlTable("Earnings History",'',"SELECT concat(i.year,'-',floor((i.month + 2)/3)) 'Month', sum(impressions) '+Imprs', sum(h.hits) '+Hits', sum(h.actions) '+Actions', sum(h.sales_amt) '+Sales', sum(h.revenue_amt) '+Commission' FROM Rev_Import i, Rev_Hist h WHERE h.merchant_id = $merchant_id and h.import_id = i.import_id GROUP BY i.year, floor((i.month + 2)/3) ORDER BY i.year DESC, i.month DESC"); sqlTable("A Fountain of Bargains",'',"SELECT concat('' ,c.category_nm,'') Page, f.start_dt 'Start', f.end_dt 'End' FROM FOB_Listing f, FOB_Category c WHERE f.merchant_id = $merchant_id and f.category_id = c.category_id and (f.end_dt > now() or f.end_dt='0000-00-00' or f.end_dt is null)"); } function merchantInfo($m) { $merchant_id = strval($m) + 0; if ($merchant_id > 0) { list($merchant_id,$merchant_nm, $prog, $weight, $display_yn, $foreign_id, $ticker, $city, $state_cd, $url, $ad_url) = sqlRow("SELECT merchant_id,merchant_nm, prog, weight, display_yn, foreign_id, ticker, city, state_cd, url, ad_url FROM Merchant WHERE merchant_id = $merchant_id"); showMerchant($merchant_id,$merchant_nm, $prog, $weight, $display_yn, $foreign_id, $ticker, $city, $state_cd, $url, $ad_url); } else { echo "invalid merchant id $merchant_id"; } } function monthInfo($showLinks) { $ym = $_REQUEST['ym']; $year = strval(substr($ym,0,4)); $month = strval(substr($ym,4)); displayHead('Quarterly Income - '.$ym); echo "

This report shows the quarterly income for the Community Color family of web sites. The report includes the number of hits sent to advertisers and reported commissions. Paid commissions is lower. The costs for my ISP, hosting, phone, etc., come to $600 a quarter. I would need $5,000 a quarter to hire one minimum wage clerk. The first row actually shows all the income prior to 2003.

"; if ($year > 0 and $month > 0 and $showLinks == 'Y') { $sql = "SELECT concat('',m.merchant_nm,'') Merchant, sum(h.impressions) '+Imprs', sum(h.hits) '+Hits', sum(h.revenue_amt) '+Total', round(sum(revenue_amt) * 100 / sum( hits ),2) 'EPC' FROM Rev_Import i, Rev_Hist h, Merchant m WHERE h.merchant_id = m.merchant_id and i.import_id = h.import_id and i.year = $year and i.month = $month GROUP BY h.merchant_id ORDER BY '+Hits' DESC"; sqlTable("Detail",'',$sql); } else { $mLink = "concat(i.year,' Q',ceil(i.month/3))" ; $sql = "SELECT $mLink Month, count(distinct h.merchant_id) Merchants, sum(h.hits) '+Hits', sum(h.revenue_amt) '+Earnings', round(sum(h.revenue_amt) * 100 / sum( h.hits ),2) 'EPC' FROM Rev_Import i, Rev_Hist h WHERE i.import_id = h.import_id GROUP BY i.year, ceil(i.month/3) ORDER BY i.year DESC, i.month DESC"; // echo "
$sql
"; sqlTable("Summary by Quarter",'',$sql); } } function getPct($x,$tot) { return ($tot > 0)? round(100*$x/$tot,3).'%' : $x.'/'.$tot; } function distRow($def,$bCnt,$bHits,$bEarn,$totCnt,$totHits,$totEarnings) { echo "$def".$bCnt ."".$bHits ."".$bEarn ."".getPct($bCnt,$totCnt) ."".getPct($bHits,$totHits) ."".getPct($bEarn,$totEarnings)."\n"; } function totalRpt() { displayHead('Total Earnings'); $sortOrder = (isset($_REQUEST['so']))? (($_REQUEST['so'] == 'e')? 'tot_commissions DESC, tot_hits' : 'tot_hits DESC, tot_commissions ') : 'tot_hits'; $showActive = (isset($_REQUEST['showActive']))? substr($_REQUEST['showActive'],0,1) : ''; if ($showActive=='Y') { $actWhere=" WHERE active_cd ='Y'"; } elseif ($showActive=='N') { $actWhere=" WHERE active_cd ='N'"; } else { $actWhere = ''; } echo '

This report shows the summary information by merchant. The Distribution Report at the bottom of the page breaks down the data into buckets.

Active Inctive All
order by hits order by earnings

'; $sql="SELECT merchant_id, active_cd, merchant_nm, prog, tot_hits 'Hits' , tot_commissions 'Earnings' FROM Merchant m ".$actWhere." ORDER BY ".$sortOrder.' DESC'; echo '
'.$sql.'
'; $buckets=array(0,0,0,0,0); $bucketE=array(0,0,0,0,0); $bucketHits=array(0,0,0,0,0); hTable("Total Earnings",7); $cnt=0; $totHits=0; $totEarnings =0; echo "PosMerchantAprogHitsEarningsEPC\n"; if ($r = mysql_query($sql)) { while (list($merchant_id, $active_cd, $merchant_nm, $prog, $hits, $earnings)=mysql_fetch_row($r)) { $epc = ($earnings > 0 && $hits > 0)? number_format($earnings * 100 / $hits,2) : ''; if ($earnings <= 0) { $buckets[0]++; $bucketHits[0]+= $hits; } elseif ($earnings < 10) { $buckets[1]++; $bucketHits[1]+= $hits; $bucketE[1] += $earnings; } elseif ($earnings < 50) { $buckets[2]++; $bucketHits[2]+= $hits; $bucketE[2] += $earnings; } elseif ($earnings < 100) { $buckets[3]++; $bucketHits[3]+= $hits; $bucketE[3] += $earnings; } elseif ($earnings < 1000) { $buckets[4]++; $bucketHits[4]+= $hits; $bucketE[4] += $earnings; } else { $buckets[5]++; $bucketHits[5]+= $hits; $bucketE[5] += $earnings; } $totHits += $hits; $totEarnings += $earnings; hRowColor(); hTD(++$cnt); hTd("$merchant_nm"); hTd($active_cd); hTd($prog); hTd($hits,'R'); hTd($earnings,'R'); hTd($epc,'R'); } } echo ""; hTable("Distribution",7); echo "BucketMerchantsHitsEarningsPct MerchantsPct HitsPct Earnings\n"; distRow('Fat Zeros',$buckets[0],$bucketHits[0],$bucketE[0],$cnt,$totHits,$totEarnings); distRow('$0-$9.99',$buckets[1],$bucketHits[1],$bucketE[1],$cnt,$totHits,$totEarnings); distRow('$10-$49.99',$buckets[2],$bucketHits[2],$bucketE[2],$cnt,$totHits,$totEarnings); distRow('$50-$99.99',$buckets[3],$bucketHits[3],$bucketE[3],$cnt,$totHits,$totEarnings); distRow('$100-$999.99',$buckets[4],$bucketHits[4],$bucketE[4],$cnt,$totHits,$totEarnings); distRow('$1000+',$buckets[5],$bucketHits[5],$bucketE[5],$cnt,$totHits,$totEarnings); echo "Total$cnt$totHits$totEarnings~ ~~ ~~ ~\n"; echo "\n"; } function epcRpt($month) { displayHead("EPC Report"); echo "

Expected Earnings Report

The Commission Junction and Share-a-Sale programs report the system wide EPC (Earnings Per Click) for their merchants. This figure is extremely helpful in determining if a merchant's program is legitimate or not. The figure gives affiliates some notion of the expected performance of the program.

This report shows commissions from Share a Sale and CJ programs compared to what I would make if I were paid the EPC. The final column 'Diff' shows where I differ from the expected earnings. Please note, I simply don't have enough traffic for my data to say anything meaningful. I do notice that people are more likely to click on some links than others. For example, financial links tend to have high EPCs; since casual web surfers rarely just click on their links. Lingerie merchants have low EPCs as there are many web surfers who are interested in pictures of underwear models.

"; $sql = "SELECT h.merchant_id, m.merchant_nm, m.epc_amt, count(*) rows, sum(hits) thits, sum(revenue_amt) Rev FROM Merchant m, Rev_Hist h WHERE m.merchant_id = h.merchant_id and m.epc_amt > 0 GROUP BY h.merchant_id ORDER BY Rev DESC, thits DESC"; $tExpected=0; $tHits=0; $tRev=0; hTable("Expected Amount",8); echo "MerchantEarningsHitsMy EPCSystem EPCExpectedDiff\n"; if ($result=mysql_query($sql)) { while (list($merchant_id, $merchant_nm, $mEPC, $cnt, $hits, $rev)=mysql_fetch_row($result)) { $epc = ($rev > 0 && $hits > 0)? number_format($rev*100/$hits,2) : ''; $expected = $mEPC * $hits/100; $difference = $rev-$expected; $diff = ($difference < 0)? "".number_format($difference,2)."" : number_format($difference,2); $tExpected += $expected; $tHits += $hits; $tRev += $rev; hRowColor(); hTd($merchant_nm); hTd('$'.$rev,'R'); hTd($hits,'R'); hTd($epc,'R'); hTd($mEPC,'R'); hTd('$'.number_format($expected,2),'R'); hTd($diff,'R'); } } $difference = $tRev-$tExpected; $diff = ($difference < 0)? "".number_format($difference,2)."" : number_format($difference,2); echo ""; hTd("Total"); hTd($tRev); hTd($tHits); hTd(''); hTd(''); hTd('$'.number_format($tExpected,2),'R'); hTd($diff); echo ""; } $showBottom = true; if (isset($_GET['qx'])) { qxDetails(); $showBottom = false; } elseif ($btn=='net') { networkSum(); } elseif ($btn=='cSum') { catSum(); } elseif (substr($q,0,2)=='nm') { networkMonth(substr($q,2)); } elseif (!hasAccess()) { monthInfo('N'); } elseif ($btn=='err') { merchantError(); } elseif ($btn=='tot' or $btn==TOTAL_REPORT_BTN) { totalRpt(); } elseif ($btn=="epc") { epcRpt($month); } elseif ($m > 0) { merchantInfo($m); } else { monthInfo($ym,'Y'); } if ($showBottom) { echo "

total ~ network ~ category

"; // ~ epc // ~ errors displayFoot(); } ?>