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
Yahoo SEM Conversion Tracking
-
- Ensign (ENS)
- Posts: 20
- Joined: Fri Nov 21, 2008 5:15 pm
Re: Yahoo SEM Conversion Tracking
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
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]]
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>
[[ConLib:Custom\SEMWidget]]
-
- Ensign (ENS)
- Posts: 20
- Joined: Fri Nov 21, 2008 5:15 pm
Re: Yahoo SEM Conversion Tracking
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
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