Version 7.x > API > Google Analytics eCommerce View modes: 
User avatar
Certified Developer v7
Certified  Developer v7
daren-webdesignmagic.com - 10/13/2013 11:38:18 PM
Google Analytics eCommerce

I am reaching out here to ask if anyone has developed a module for Google Analytics eCommerce (https://developers.google.com/analytics/devguides/collection/gajs/gaTrackingEcommerce) for Version 7 of Kentico?

It would be great to find someone who can share this code.

Thanks Daren

User avatar
kentico_sandroj - 10/20/2013 2:17:33 PM
RE:Google Analytics eCommerce

There doesn't seem to be a module available but I can try to point you in the right direction. As far as I understand some javascript code with order information needs to be generated to rendered HTML page. The best place in Kentico CMS when/where this code with order information and product information can be added to page is after the order is saved in database – then in the following step.

Order is saved into database in ShoppingCartPreview step (~\CMS\CMSModules\Ecommerce\Controls\ShoppingCart\ShoppingCartPreview.ascx.cs) in ProcessStep method.

I assume that you are using PayPal and Authorize .NET payment gateways which are already included in Kentico CMS.

When using Authorize .NET payment method, you can include google javascript code into Authorize .NET payment gateway form (~\CMSModules\Ecommerce\Controls\PaymentGateways\AuthorizeNetForm.ascx) –this is place where order is already saved so order information is available.

When using PayPal payment method similarly, you can include google javascript code into PayPal payment gateway form (~\CMSModules\Ecommerce\Controls\PaymentGateways\PayPalForm.ascx).

You can use following code in mentioned files to access any order information:
OrderInfo oi = OrderInfoProvider.GetOrderInfo(this.ShoppingCartInfoObj.OrderId);
// oi.OrderTotalPrice
// oi.OrderTotalTax

You can render the javascript code to page in mentioned places with ScriptHelper.RegisterStartupScript() method, the same way as google analytics code is rendered.

Example on how to use this method (RegisterStartupScript) can be found in following file in SetupControl method:


Detailed information about google e-commerce tracking codes can be found here.

More information about our API can be found here.

So, I assume that once the order is created, in mentioned files you should render the google javascript codes to rendered HTML page with RegisterStartupScript method. You should render information about the order with addTrans google method, information about each item from the order with addItem method (for each item in order) and also trackTrans method.

See also:
Analytics without Javascript