与第 3 方开发人员合作,结合 Paypal 实施 Google Analytics(分析)服务器端电子商务跟踪。参考代码项目(http://www.codeproject.com/Articles/493455/Server-side-Google-Analytics-Transactions)上的源代码,我们在暂存时实现了以下谷歌分析代码,但它没有触发任何事务:
private void GoogleAnalytics(Order order)
{
var wrapper = new HttpRequestWrapper(Request);
try
{
GoogleRequest request = new GoogleRequest("UA-3820067-1", wrapper);
request.Culture = System.Threading.Thread.CurrentThread.CurrentCulture.ToString();
request.HostName = System.Web.HttpContext.Current.Request.Url.ToString();
request.PageTitle = "ShoppingCart";
Transaction trans = new Transaction(Convert.ToInt32(order.OrderId), string.IsNullOrEmpty(order.Billing_City) ? (string.IsNullOrEmpty(order.Shipping_City) ? "" : order.Shipping_City) : order.Billing_City, string.IsNullOrEmpty(order.Shipping_Country) ? "" : order.Shipping_Country,
Convert.ToString(order.RegionId), "store", string.IsNullOrEmpty(order.Shipping_Additional) ? 0 : Convert.ToDecimal(order.Shipping_Additional), Convert.ToDecimal(order.Total), Convert.ToDecimal(order.TaxAmount));
foreach (OrderItem orderItem in order.Items)
{
//ProductCode or SKU, ProductName, ItemPrice, Quantity, GroupName
TransactionItem item = new TransactionItem(Convert.ToString(orderItem.SurveyId), orderItem.SurveyName, Convert.ToDecimal(orderItem.Price), orderItem.Quantity, "Survey");
trans.AddTransactionItem(item);
}
//Now just make a request for this transaction object
request.SendRequest(trans);
}
catch (Exception ex)
{
log.Error("Exception occured while Google Analytics process ", ex);
}
}
我们还实施了 Paypal PDT 以接收交易信息,目前运行正常。以下是我们在 PDTResponse 成功时调用的内容。
if (strResponse.StartsWith("SUCCESS"))
{
PDTHolder pdt = PDTHolder.Parse(strResponse);
strCustom = pdt.Custom;
strCustom = HttpUtility.UrlDecode(strCustom);
if (strCustom.Contains("&"))
{
string[] arrCustom = strCustom.Split('&');
cc = arrCustom[0].Split('=')[1];
pp = arrCustom[1].Split('=')[1];
orderID = Convert.ToInt32(arrCustom[2].Split('=')[1]);
cartID = arrCustom[3].Split('=')[1];
}
order.OrderId = Convert.ToInt32(orderID);
order.LoadByOrderId(Config.SurveyDsn);
this.GoogleAnalytics(order);
}
else
{
log.Debug("PDT failure");
}
对此的任何帮助将不胜感激,因为我被困在接下来要做什么以从 Paypal 接收信息并将其发送到 Google Analytics 服务器。