tracking ad clicks in database

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
User avatar
Intelliflex
Lieutenant (LT)
Lieutenant (LT)
Posts: 78
Joined: Tue Feb 17, 2004 7:51 pm

tracking ad clicks in database

Post by Intelliflex » Tue Apr 14, 2009 3:55 pm

Good Day All...

I am getting significant advertisers on the site and I want to track the ad click-throughs. The best way I can think is to have the ad image "on-click" event write an entry to a table in the database with the ad id and a date/time stamp and then I can write reports against that table.

Assuming this is the best way to acomplish this, how would I connect to the database, as it is encrypted in the web.config file? Is there a call in any of the dlls I can use to open and close the connection?

Feel free to throw out ideas or alternatives here...

Thanks!
Dave

User avatar
nickc
Captain (CAPT)
Captain (CAPT)
Posts: 276
Joined: Thu Nov 29, 2007 3:48 pm

Re: tracking ad clicks in database

Post by nickc » Tue Apr 14, 2009 5:30 pm

Use jQuery to make an asynchronous request to a logger aspx, mapped to onclick in Page_Load:

Code: Select all

AdButton.OnClientClick = "javascript:$.ajax({url: '/_eventlogger.aspx', data: 'a=AdClick&o=" + AdName + "&p=" + Convert.ToString(_ProductId) + "', cache: false });
The logger can then be completely outside the Able universe, so you decide on connectString, etc....

Code: Select all

public partial class _eventlogger : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string _action = Request.QueryString["a"] + "";
        string _object = Request.QueryString["o"] + "";
        int _product = Convert.ToInt32(Request.QueryString["p"] + "");
        PageEventLogger pel = new PageEventLogger(HttpContext.Current, SiteInformation.Current);
        PageEventLogger.PageEventAction pea;
        try
        {
            pea = (PageEventLogger.PageEventAction)Enum.Parse(typeof(PageEventLogger.PageEventAction), _action);
        }
        catch
        {
            pea = PageEventLogger.PageEventAction.Button_Click;
        }
        pel.LogPageEvent(pea, _product, _object);
    }
}

User avatar
Intelliflex
Lieutenant (LT)
Lieutenant (LT)
Posts: 78
Joined: Tue Feb 17, 2004 7:51 pm

Re: tracking ad clicks in database

Post by Intelliflex » Tue Apr 14, 2009 6:08 pm

Nick

Thanks for the quick reply. Good code, but I think for reporting purposes, the database would be a better route. Let me elaborate a bit more. Let say I have a side bar that has 5 images that link to other outside websites. I want to be able to run reports aganst a table where I can search for ads for a particular advertiser, either by name or account number, and also by date range, as I will track a date stamp. This will be much easier letting SQL handle the searches for the date ranges. Basically "pay-per-click" advertising.

What I had in mind was to create a table that had account number, account name, datestamp, and IP address fields. This way I can pass this information to a stored procedure that will write to the table. On the report side, I'll use another stored procedure that will filter for a single advertiser, a date range, and filter out multiple clicks from the same IP address per day. I want to run reports for us that has all advertiser information grouped by advertiser, but also a report that is automatically emailed to the advertiser every month to show traffic.

I can hard code the username and password for the database, but keeping security in mind, I was thinking there might be something in Able code that I could call to connect and disconnect the database.

Thanks again for your help!
Dave

User avatar
nickc
Captain (CAPT)
Captain (CAPT)
Posts: 276
Joined: Thu Nov 29, 2007 3:48 pm

Re: tracking ad clicks in database

Post by nickc » Tue Apr 14, 2009 6:50 pm

In my example, the PageEventLogger class looks after extracting the appropriate values from context and writing to the database. It's basically the DAL for the SessionLog and PageEventLog tables in my database.

Post Reply