@dollarshaveclub/js-utils
v73.13.2
Published
<h1 align="center">DSC JS Utils</h1> <h5 align="center">JS utilities to be used across JS repositories.</h5>
Downloads
591
Keywords
Readme
⚠️⚠️ NOTE: this package is published publicly, so do not put any sensitive information in this repository. ⚠️⚠️
Folders
There are 2 key folders which contain utility scripts—browser and isomorphic. Browser utility scripts are meant to be used within a browser. Isomorphic utility scripts are scripts that can be run within any environment.
Browser
Browser-specific utilities scripts.
- Uses ES6 Modules import/export syntax. Read more about ES6 Modules. Read more.
Isomorphic
Utility scripts that work in any JavaScript environment. Read more.
- Use CommonJS node module syntax. Read more about CommonJS.
Installing NPM:
npm i --save @dollarshaveclub/js-utils
Import the built versions of files from the build folder:
const {
SHOP_CODES,
ENVIRONMENTS,
} = require('@dollarshaveclub/js-utils/build/isomorphic/config')
You may be able to use the non-built versions in server environments, but always use the built versions in browser environments.
If interfacing with Tracksuit, initialize analytics in the following way.
Initialize once:
// src/bootstrap.js
import bootstrap from '@dollarshaveclub/js-utils/build/browser/bootstrap-data'
import { initializeAnalytics } from '@dollarshaveclub/js-utils/build/browser/analytics'
const faceAssetsFixtures = window.FaceAssetsFixtures
const { study, features } = bootstrap(faceAssetsFixtures)
// Be sure to provide Fixtures, AB Tests, and your specified vendors. Also be
// sure to export this constant if you wish to interface with your analytics
export const analytics = initializeAnalytics(
faceAssetsFixtures,
study.assignments(),
{
DTM: true,
GTM: true,
}
)
Access the export in other files
// app/home/index.js
import { analytics } from '../../bootstrap'
analytics.call('page') // Track page information
analytics.call('trackEvent', {
event: 'butt',
category: 'Link Click',
action: 'movies',
label: 'The Room',
value: '',
})
The analytics
API uses Tracksuit under the hood. You may pass any Tracksuit
function name to the analytics.call
function to execute it. All parameters are
retained.
Publishing
Automatically updated and published when a release is cut. Also after a successful deploy, please be sure to update the version number and update face-web as well.