Click Through Rate script

Posted By: Ian on Feb 01, 2015 in PHP, Snippets

How does Banner Bar work out the Click Through Rate CTR for the banners on my site.


/* Click Through Rate */
function ctr($v1, $v2)
    $clicks      = $v1;
    $impressions = $v2;
    /* if impressions are not equal to 0 divide 
     * clicks by impressions and times by 100 
     * then show only the first 5 characters */
    if ($impressions != 0) {
        $ctr = ($clicks / $impressions) * 100;
        return substr($ctr, 0, 5) . "%";
    } else {
        return '0';
print ctr("370", "3987");



Did this help you? Please Let me know by commenting below even if it’s just to say “Thanks”

leave a comment

About This Site

Dreams are built from lines of code well it's true!
If you can dream it you can usually code it.

I have learned so much from other people on the Internet and this site is for me to give back some of what i have learned and hope people can now learn from me.
Have fun and surf safely,

protected by copyscape duplicate content check


Powered by Banner Bar 125