Class GoogleAnalytics4Processor

java.lang.Object
org.broadleafcommerce.presentation.dialect.AbstractBroadleafTagReplacementProcessor
org.broadleafcommerce.core.web.processor.GoogleAnalytics4Processor
Record Components:
ordernumber - the order number to look up for ecommerce tracking, such as on the confirmation page
All Implemented Interfaces:
org.broadleafcommerce.presentation.dialect.BroadleafProcessor, org.broadleafcommerce.presentation.dialect.BroadleafTagReplacementProcessor

@Component("blGoogleAnalytics4Processor") @ConditionalOnTemplating public class GoogleAnalytics4Processor extends org.broadleafcommerce.presentation.dialect.AbstractBroadleafTagReplacementProcessor

Takes advantage of the new-type gtag.js from Google Analytics rather than the deprecated analytics.js. This also supports a pre-processed orderNumber attribute that can be null, suitable for things like the order confirmation page to send e-commerce transactions. Example usage:

 <google_analytics_4 ordernumber="${order?.orderNumber" />
 

This processor also supports:

  • Multiple trackers (extensible via #getTrackers() or by setting the googleAnalytics4.masterWebPropertyId and googleAnalytics4.webPropertyId)
  • Affiliates for e-commerce ({@ googleAnalytics.affiliation property})
  • Link attribution (googleAnalytics4.enableLinkAttribution system property, default true)
  • Display Advertising (googleAnalytics4.enableDisplayAdvertising system property, default false)
Author:
Markiian Buryi (MarekB01)
  • Field Details

    • googleAnalytics4PropertyId

      @Value("${googleAnalytics4.masterWebPropertyId:null}") protected String googleAnalytics4PropertyId
      Global value, intentionally only retrieved as a file property NOT via the system properties service
    • googleAnalytics4WebPropertyId

      @Value("${googleAnalytics4.webPropertyId:null}") protected String googleAnalytics4WebPropertyId
    • tagId

      @Value("${googleAnalytics4.tagIdForProperty:null}") protected String tagId
    • orderService

      protected OrderService orderService
    • testLocal

      @Value("${googleAnalytics4.testLocal:false}") protected boolean testLocal
      This will force the domain to 127.0.0.1 which is useful to determine if the Google Analytics tag is sending a request to Google
  • Constructor Details

    • GoogleAnalytics4Processor

      public GoogleAnalytics4Processor()
  • Method Details

    • getName

      public String getName()
    • getPrecedence

      public int getPrecedence()
      Specified by:
      getPrecedence in interface org.broadleafcommerce.presentation.dialect.BroadleafProcessor
      Overrides:
      getPrecedence in class org.broadleafcommerce.presentation.dialect.AbstractBroadleafTagReplacementProcessor
    • getReplacementModel

      public org.broadleafcommerce.presentation.model.BroadleafTemplateModel getReplacementModel(String tagName, Map<String,String> tagAttributes, org.broadleafcommerce.presentation.model.BroadleafTemplateContext context)
    • getTransactionJs

      protected String getTransactionJs(Order order)
      /** Builds the transaction analytics for the given tracker name. Invokes for each item in the given <b>order</b>.
    • getItemJs

      protected String getItemJs(Order order)
    • getVariation

      protected String getVariation(OrderItem item)
      Returns the product option values separated by a space if they are relevant for the item, or the product category if no options are available
      Returns:
    • getTagIdForProperty

      public String getTagIdForProperty()
    • getWebPropertyId

      public String getWebPropertyId()
    • getAffiliation

      public String getAffiliation()
    • isIncludeLinkAttribution

      public boolean isIncludeLinkAttribution()
    • isIncludeDisplayAdvertising

      public boolean isIncludeDisplayAdvertising()