J
James Irvine
I'm trying to dynamically build the example script below from C#, substituting the sale item details with data values I get from an online transaction. Is
there a preferred method to do this? My approach so far has been to concatenate a bunch of strings, then plug it into a ClientScript.RegisterStartupScript,
like this:
string line1 = @"<script type=""text/javascript"">";
string line2 = @"var pageTracker = _gat._getTracker(""UA-2263877-1"");";
string line3 = " pageTracker._initData(); pageTracker._trackPageview(); pageTracker._addTrans(";
etc...
string gxAnalyticsScriptx = line1 + line2 + line3;
ClientScript.RegisterStartupScript(this.GetType(), "whatever", gxAnalyticsScriptx);
But with all the embedded quotes and all to deal with, it's getting messy real quick. Is there some more standard way to get this done? thanks -James
This is the example script I'm trying to dynamically build, substituting item details from my shopping cart:
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-XXXXX-1");
pageTracker._initData();
pageTracker._trackPageview();
pageTracker._addTrans(
"1234", // Order ID
"Mountain View", // Affiliation
"11.99", // Total
"1.29", // Tax
"5", // Shipping
"San Jose", // City
"California", // State
"USA" // Country
);
pageTracker._addItem(
"1234", // Order ID
"DD44", // SKU
"T-Shirt", // Product Name
"Green Medium", // Category
"11.99", // Price
"1" // Quantity
);
pageTracker._trackTrans();
</script>
there a preferred method to do this? My approach so far has been to concatenate a bunch of strings, then plug it into a ClientScript.RegisterStartupScript,
like this:
string line1 = @"<script type=""text/javascript"">";
string line2 = @"var pageTracker = _gat._getTracker(""UA-2263877-1"");";
string line3 = " pageTracker._initData(); pageTracker._trackPageview(); pageTracker._addTrans(";
etc...
string gxAnalyticsScriptx = line1 + line2 + line3;
ClientScript.RegisterStartupScript(this.GetType(), "whatever", gxAnalyticsScriptx);
But with all the embedded quotes and all to deal with, it's getting messy real quick. Is there some more standard way to get this done? thanks -James
This is the example script I'm trying to dynamically build, substituting item details from my shopping cart:
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-XXXXX-1");
pageTracker._initData();
pageTracker._trackPageview();
pageTracker._addTrans(
"1234", // Order ID
"Mountain View", // Affiliation
"11.99", // Total
"1.29", // Tax
"5", // Shipping
"San Jose", // City
"California", // State
"USA" // Country
);
pageTracker._addItem(
"1234", // Order ID
"DD44", // SKU
"T-Shirt", // Product Name
"Green Medium", // Category
"11.99", // Price
"1" // Quantity
);
pageTracker._trackTrans();
</script>