Page 1 of 1

Yahoo SEM Conversion Tracking

Posted: Wed Oct 07, 2009 1:20 pm
by divers-supply
I am trying to use Yahoo's code to track conversions through their SEM program. They require the code to be between the Head tags on the receipt page.

Here is the code:

<!-- yahoo SEM tracking code -->
<SCRIPT language="JavaScript" type="text/javascript">
<!-- Yahoo! Inc.
window.ysm_customData = new Object();
window.ysm_customData.conversion = "transId='<%=Order.OrderId%>',currency=USD,amount='<%=Order.TotalCharges%>'";
var ysm_accountid = "1HN52F8HQCG61MTLRHC3954OAQ8";
document.write("<SCR" + "IPT language='JavaScript' type='text/javascript' "
+ "SRC=//" + "srv1.wa.marketingsolutions.yahoo.com" + "/script/ScriptServlet" + "?aid=" + ysm_accountid
+ "></SCR" + "IPT>");
// -->
</SCRIPT>

I have tried to put this code in the CheckOutHeader.htm and several other places but it is not working.

I did put it in the Receipt.aspx and it works however, it won't send the data to Yahoo becuase they require it to be in between the HEAD tags on the receipt page which would be in the CheckoutHeader.htm

Any assistance would be greatly appreciated.
Thank you

Re: Yahoo SEM Conversion Tracking

Posted: Thu Oct 08, 2009 3:15 am
by mazhar
For this you need to write a custom user control that will build and inject this script to receipt page when you add it to header of that page. I am attaching a control you can try it on your reciept page, I didn't tested it. Here is its code

Code: Select all

<%@ Control Language="C#" ClassName="SEMWidget" %>

<script runat="server">
    int _OrderId;
    Order _Order;

    protected void Page_Load(object sender, EventArgs e)
    {
        _OrderId = PageHelper.GetOrderId();
        _Order = OrderDataSource.Load(_OrderId);
        Page.RegisterClientScriptBlock("Yahoo SEM tracking Widget code", BuildScript());
    }

    protected string BuildScript()
    {
        StringBuilder sb = new StringBuilder();

        sb.Append("<!-- yahoo SEM tracking code -->");
        sb.Append("<SCRIPT language='JavaScript' type='text/javascript'>");
        sb.Append("<!-- Yahoo! Inc.  ");
        sb.Append("window.ysm_customData = new Object();");
        sb.Append(string.Format("window.ysm_customData.conversion = \"transId='{0}',currency=USD,amount='{1}'\";", _OrderId, _Order.TotalCharges()));
        sb.Append("var ysm_accountid = \"1HN52F8HQCG61MTLRHC3954OAQ8\";");
        sb.Append("document.write(\"<SCRIPT language='JavaScript' type='text/javascript' SRC=\" srv1.wa.marketingsolutions.yahoo.com/script/ScriptServlet?aid=ysm_accountid\"></SCRIPT>\");// -->");
        return sb.ToString();
    }
</script>
Download attached file unzip it and then place SEMWidget in ConLib/Custom folder. Finally on receipt page scriptlet make use of it as below
[[ConLib:Custom\SEMWidget]]

Re: Yahoo SEM Conversion Tracking

Posted: Mon Oct 12, 2009 6:00 am
by divers-supply
Mazhar,

Thanks so much for the code...I did test it and I am getting this error:

[[ConLib:Custom\SEMWidget]] d:\Internet\Divers-Supply.com\ConLib\Custom\SEMWidget.ascx(24): error CS1010: Newline in constant

I can't seem to figure out what the problem is...Any help would be appreciated.

Thanks so much