Developer forum

Forum » Templates » Analytics Asynchronous Syntax in DW

Analytics Asynchronous Syntax in DW


Reply
Hi there,

I've got a problem maybe you guys could help me out.

Google Analytics is recommending the use off their e-commerce tracking code in a specific way (Asynchronous Syntax). You can find some more useful documentation here: http://code.google.com/intl/nl/apis/analytics/docs/tracking/gaTrackingEcommerce.html.

You add on a certain page in your shopping cart a script in the head off your document. This script uses data from the transaction such as order id, product name and pricing to post data to Google Analytics.

In DW this data is available and can be used in the script. However Google recommends to place this data inside the head of the document. DynamicWeb has this data just available in the paragraph (shopping cart).

My question:
Is there a possibilty to implement this code the recommended way? Maybe by making it possible placing paragraphs in the head section of the document?

Thanks in advance!

Replies

 
Reply
Hi!
Yes, I think it possible.
1) Add a tag for script in master template into head section (You can see what template is used in the Frontpage or Language/Area module in the administration. Or just say view source on the page - in the bottom you can see the filename of the master template.)
2) Write subscriber.

Something like:

Imports Dynamicweb
Imports Dynamicweb.Frontend
Imports Dynamicweb.Extensibility
Imports Dynamicweb.Ecom7.Cart.Notifications

Namespace eCommerce.Frontend

    <Subscribe(Dynamicweb.Ecom7.Cart.Notifications.CheckoutDoneOrderIsComplete)>
    Public Class OrderCompleteSubscriber
        Inherits NotificationSubscriber

        Public Overrides Sub OnNotify(ByVal notification As String, ByVal args As NotificationArgs)
            Dim myArgs As CheckoutDoneOrderIsCompleteArgs = CType(args, CheckoutDoneOrderIsCompleteArgs)
            Dim pv As PageView = Dynamicweb.Frontend.PageView.Current()
            Dim myScript As String = GoogleAnaliticScript(myArgs.Order)
            pv.TemplateMaster.SetTemplateValue("MyJavascripts", myScript)
        End Sub

        Private Function GoogleAnaliticScript(ByVal order As Dynamicweb.eCommerce.Orders.Order) As String
            '''
        End Function

    End Class
   
End Namespace

Best regards, Vladimir

 

You must be logged in to post in the forum