flamingo.me/flamingo-commerce/v3@v3.11.0/w3cdatalayer/Readme.md (about)

     1  # W3C Datalayer Module
     2  
     3  Module that makes it easy to add common datalayer to your website - which makes it easier to connect to analytics and 
     4  to implement tracking pixels and tag managers.
     5  
     6  The datastructure is oriented at:
     7  [www.w3.org/community/custexpdata/](https://www.w3.org/community/custexpdata/)
     8  
     9  The datalayer information provides an easy access to common information relevant for tracking and datalayer.
    10  The datalayer module therefore listens to various events and adds information to the datalayer
    11  
    12  
    13  ## Configurations:
    14  ```yaml
    15  w3cDatalayer:
    16    pageInstanceIDPrefix: "mywebsite"
    17    pageInstanceIDStage: "%%ENV:STAGE%%production"
    18    pageNamePrefix: My Shop
    19    siteName:  My Shop
    20    defaultCurrency: GBP
    21    version: 1.0
    22    # If you want sha512 hashes instead real user values
    23    hashUserValues: true
    24  ```
    25  
    26  Also it reuses the configuration from locale package to extract the language:
    27  ```yaml
    28  locale:
    29    locale: en-gb
    30  ``` 
    31  
    32  
    33  ## Usage example:
    34  
    35  ### Template function `w3cDatalayerService`
    36  
    37  The template function provides access to the current requests datalayer.
    38  You can get the datalayer and you can modify it:
    39  
    40  For some values in the datalayer the template knows better than the backend what to put in, so please call the appropriate setter like this:
    41  ```pug
    42    - var result = w3cDatalayerService().setPageCategories("masterdata","brand","detail")
    43    - var result = w3cDatalayerService().setBreadCrumb("Home/Checkout/Step1")
    44    - var result = w3cDatalayerService().setPageInfos("pageID","pageName")
    45    - var result = w3cDatalayerService().setCartData(decoratedCart)
    46    - var result = w3cDatalayerService().setTransaction(cartTotals, decoratedItems, orderid)
    47    - var result = w3cDatalayerService().addProduct(product)
    48    - var result = w3cDatalayerService().addEvent("eventName")
    49        
    50  ```
    51  
    52  If you want to populate the w3c datalayer to your page you can render the final digitalData object like this:
    53  ```pug
    54  - var w3cDatalayerData = w3cDatalayerService().get()
    55  script(type="text/javascript").
    56    var digitalData = !{w3cDatalayerData}
    57    digitalData.page.pageInfo.referringUrl = document.referrer
    58    digitalData.siteInfo.domain = document.location.hostname
    59  ```
    60