Page 1 of 1

Google Analytics

Posted: Wed Jan 30, 2013 3:41 am
by bhavani
Hi,

How to add Google analytics tracking codes in my development??
Pls help me on this...

Re: Google Analytics

Posted: Wed Jan 30, 2013 10:29 am
by phillipuniverse
Look at GoogleAnalyticsProcessor.java to see the logic for generating the javascript.

There is an example of using this already: https://github.com/BroadleafCommerce/De ... /head.html

Code: Select all

<blc:googleAnalytics th:attr="orderNumber=${order != null ? order.orderNumber : null}" />
<script th:utext="${analytics}"></script>


You will also need to define the googleAnalytics.webPropertyId in your properties file (you may wish to define different values for dev, qa and production; see common-shared.properties for more info).

Re: Google Analytics

Posted: Mon Jun 30, 2014 9:51 am
by surfratwalt
Hi, I have been trying to find an answer to this question, but I can't seem to get this working as describe. I've followed the demo site usage, i.e.

Code: Select all

<blc:googleAnalytics ordernumber="${order?.orderNumber}" />
<script th:utext="${analytics}"></script>


And I've got a webPropertyId set, however the processor seems to fail to set an ${analytics} that's accessible in scope when the page is generated. I've debugged the processor and it does actually seem to set this variable, but the finished output simply has an empty script block.

Code: Select all

<script></script>


I can test for ${analytics} in the page and can confirm that thymeleaf believes it's null. I'm going to keep digging into thymeleaf to see if I can get to the bottom of it but thought I'd pose the question in case anyone has had a similar issue.

I'm on 3.1.2. Note it didn't work in 3.1.1 either.

Re: Google Analytics

Posted: Mon Jun 30, 2014 11:39 am
by phillipuniverse
Surfratwait, you should consider instead using <blc:google_universal_analytics /> which is new as of 3.1.3-GA (current Broadleaf release is 3.1.5-GA). Google has deprecated the older API that <blc:googleAnalytics> was using in favor of Universal Analytics and as of 3.1.3-GA we have deprecated the older-style processor.

Re: Google Analytics

Posted: Mon Jun 30, 2014 11:41 am
by phillipuniverse
By the way, with the google universal analytics processor you don't need the extra <script> tag. Instead, you can just put in the processor invocation and it will transform to a valid <script> tag with the GA tracking code:

Code: Select all

<blc:google_universal_analytics ordernumber="${order?.orderNumber}" />

Re: Google Analytics

Posted: Sun Jul 06, 2014 3:10 am
by surfratwalt
Thanks for the tip @phillipuniverse. I have upgraded to the latest GA release, and am now using the google universal analytics processor successfully in dev.