Code for tracking clicks on 'add to cart' button?

by 4 replies
6
Hi,

I have an 'add to cart' button, not using paypal, and would like to track how many times someone clicks on that image button.

The button can be seen on the site, Claim Back Your Ex


Bret
#programming #add #button #cart #clicks #code #tracking
  • Gowebmkt,

    You could use Google Analytics and track using virtual page views. This requires that you have an account with Google, install the tracking code at least on the page that you are tracking (whole site would be better), and that you add a line of JavaScript code to the link where the button is. Another solution is to use event tracking as virtual page views may skew your page view metric however if you don’t use Analytics for any other data but tracking clicks on that button it won’t really matter.

    Here is a video on how to implement,

    24. Event Tracking and Virtual Pageviews | Google Analytics IQ Lessons - YouTube
    Hope that helps,

    Shawn
    • [ 1 ] Thanks
    • [1] reply
    • I forgot to mention, I do have GA on the site pages.

      Ill check out the video for the JS code to use.

      Thanks!
  • If it was me Id do it with JQUERY and PHP

    add to image--
    onclick="$.post("trackclick.php");"

    PHP file: trackclick.php
    <?php

    $File = "clickcount.txt"; $fh = fopen($File, 'r'); $Clicks = fread($fh, filesize($File)); fclose($fh);

    $Clicks=$Clicks+1;

    $File = "clickcount.txt"; $fh = fopen($File, 'w') or die("can't open file"); fwrite($fh, $Clicks);
    fclose($fh);
    ?>
    • [ 1 ] Thanks
  • Here's an excellent article on using google analytics event tracking:
    Idiot's Guide to Event Tracking | .eduGuru
    This is the way to go!
    • [ 1 ] Thanks

Next Topics on Trending Feed