Code Monkey home page Code Monkey logo

bigcommerce-datalayer's Introduction

BigCommerce GA4 Ecommerce dataLayer

Note: the script has been drastically changed from the forked version to adapt to our GTM specifications.

A dataLayer implementation for BigCommerce, based upon the Google Analytics 4 Ecommerce specification.

Brought to you by Fueled Inc.

Overview

dataLayers provide a uniformed way for tracking and attribution scripts, such as Segment's Analytics.js library, to interact with your BigCommerce site. Implementing a dataLayer will ensure that all scripts use consistent attribution values and calculations. They can also cut down on custom code. Finally, they are exposed to Google Tag Manager, if you choose to implement tracking via GTM.

This dataLayer project implements Google's "Google Analytics v4 Ecommerce Event Specification", as described in the following docs:

Installation

This project is installed via BigCommerce's Script Manager. The script should be loaded on all pages.

  1. From your dashboard open the Storefront settings and under that, click into Script manager.
  2. Click the "Create Script" button
  3. Give the script a name and (optional) description, make sure it's running on All Pages and is set to Essential
  4. Select a script type of Script and in the bellow text box type in following <script></script>
  5. Paste your compiled script inside the script tags you added. <script>Your code</script>
  6. Save

Build

Note: I had issues with build-min script in that minified code didn't work correctly. Instead, I used https://www.uglifyjs.net/ and chose to Mangle names and Mangle function names. I pasted the results into dist/dataLayer.min.js.

To build and bundle the dataLayer from source, run (You will need Node installed):

npm install this will install the required components npm run build-min this is compile the minified script into the ./dist folder npm run build this will create a copy of the script using Webpacks eval function

Ecommerce Events Tracked via the dataLayer

Additional script variable definitions coming soon.

Customization

This script has been designed to work with HTML elements generated by BigCommerce's default theme, Cornerstone. It can be extended to work with custom themes, as well as legacy Blueprint themes, to track additional client interactions.

To modify the selectors the script watches for you can make those changes starting on line 86 of ./src/index.js

var  productDetailsButton = document.getElementsByClassName('card-figure__link') || []; //Product card selector  
var  mainPageAddButton = document.querySelectorAll("[data-button-type='add-cart']") || []; //Add to cart button selector
var  productPageAddButton = document.getElementById('form-action-addToCart'); //Add to cart form selector
var  cartPageRemoveButton = document.getElementsByClassName('cart-remove') || []; //Remove from cart button selector
var  cartButton = document.getElementsByClassName('navUser-item--cart') || []; //Show Cart selector

Once your customizations are made you can follow the build/installation instructions.

Need Support?

As an open source project, this solution is provided as is, without warranty or a commitment to customer support. That said, we are committed to the BigCommerce community and will do our best to answer questions and help you leverage this dataLayer. If you have questions, please feel free to email [email protected].

Licensing

This is an open source project, licensed under the GPLv3.

bigcommerce-datalayer's People

Contributors

vladgrigacodeart avatar boodavia avatar esvirsky avatar foussjd avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.