High-Performance Development - C#, VB, SQL, ASP.NET

Slogan Text

This article describes how to insert HTML tags into the HTML <head> tag.

One of my clients signed up for the Yahoo Search Marketing Analytics service. Yahoo provides a script which records a purchase by a customer on the client's web site. Yahoo requests the user place the script between the <head></head> tags on the web page completing or confirming the sale.

The Yahoo script contains an assignment statement which specifies the Yahoo account id and the transaction amount. The Yahoo service records the transaction amount in the user's account.

My client signed up for three (3) geographical regions in the Yahoo service: U.S., UK, and Australia. A different subaccount id was associated with each region. 

Putting all of the above together the code had to dynamically generate the script with the correct subaccount id, transaction amount, and then insert the script between the <head></head> tags.

I developed a server control that reads the Yahoo script from a resource file, inserts the account id, fee, currency, server url, and transaction id into the Yahoo script.

    AnalyticControlObj = new SPCG_YahooSearchMarketingAnalytics();
    AnalyticControlObj.AccountId = "123";
    AnalyticControlObj.Amount = Fee;
    AnalyticControlObj.Currency = "USD";
    AnalyticControlObj.ServerUrl = "srv3.wa.marketingsolutions.yahoo.com";
    AnalyticControlObj.TransId = "" + ApplicationId;
    AnalyticControlObj.Visible = PaymentStatus;

Once we've set the values for the script in the Page_Load method of the web page (.ASPX) we add the control to the page header tag:

    Page.Header.Controls.Add(AnalyticControlObj);