Content block snippets can be used for many other purposes, such as adding analytics, affiliate, comparison and social media tracking codes or for simply adding simple site inclusions such as logos, wallpaper and promotional messages to specific areas of the site.
To use this tool, there needs to be an appreciation of the code and structure of the site(s) and channels being serviced.
It is advised that all changes should be carefully tested before they are applied to the live site, to avoid any detrimental impact on customer experience.
- Go to Storefront > Content Blocks
- Click New Content Block
- Select the folder
- Fill out the details as per your requirement, For more details refer to the below table
Snippet Information Snippet Name Display name of the snippet Content-Type Content Blocks are made up of ‘Snippets’ of either JavaScript, HTML, or text. Snippet Placement Location of the snippet example head, footer, left panel of the site Snippet The actual snippet code goes here Configuration Is Active Enable or disable a snippet Show Across Site Enable if needed to be used across the site with an option to exclude some of the URLs Show On Specific Pages If needed to be used on specific pages only Specific URLs Place holder in case want to execute these snippets on specific URLs - Click Save
Snippets list can be seen and filtered based on the below filters:
- Snippet Type: Javascript, Html, or Text
- Status: Active or Inactive
- Dynamic Type: Yes or No
- Show Across Site: Yes or No
Snippets provide a valuable feature to the business, in so far as they enable you with an understanding of HTML, JavaScript and Text files, to add in snippets of code to the site as needed.
A good example of where this could be useful is in the inclusion of Google Analytics tagging, where tags are required to be added within different locations e.g. Head or Body tags.
Lets explore some examples of how snippets can be used.
Drilling down into the individual snippets you can see that we have two examples of how Google Analytics (GA) can be applied to a site using a content block.
Configuration: The snippet of HTML code to be added to the entire site and applied across the (desktop, in-store, mobile, tablet and web) site(s).
The code being added here is the account number for GA, which in this case is the same across all sites.
If you have a different GA Account per country then you would set up a snippet as above, but for each domain/site. The example above on the right is for the Order Confirmation Page and is therefore only applied to this specific page. The JavaScript in this snippet is written to collect a set of data for GA from the order being taken, including the line-level detail of Product SKU, Unit Price, Line Quantity as well as the overall order value and delivery costs.
Note- BetterCommerce allows you to create multiple folders and move individual snippets to these folders as well