-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
1,362 additions
and
374 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
coverage | ||
dist | ||
node_modules | ||
__mocks__/ | ||
__snapshots__/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const { createConfig } = require('@edx/frontend-build'); | ||
const extendESLintConfig = require('../../common/extendESLintConfig'); | ||
|
||
const config = createConfig('eslint'); | ||
extendESLintConfig(config); | ||
|
||
module.exports = config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules | ||
dist | ||
coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
*.config.js* | ||
coverage | ||
Makefile | ||
src/**/*.test.js | ||
src/**/*.test.jsx | ||
src/**/tests | ||
src/**/setupTest.js |
Empty file.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
build: | ||
make clean | ||
../../node_modules/.bin/fedx-scripts babel src --out-dir dist --source-maps --ignore **/*.test.jsx,**/*.test.js,**/setupTest.js --copy-files | ||
@# --copy-files will bring in everything else that wasn't processed by babel. Remove what we don't want. | ||
@find dist -name '*.test.js*' -delete | ||
cp ./package.json ./dist/package.json | ||
cp ./LICENSE ./dist/LICENSE | ||
cp ./README.rst ./dist/README.rst | ||
cp ./CHANGELOG.md ./dist/CHANGELOG.md | ||
|
||
clean: | ||
rm -rf ./dist ./node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
@edx/frontend-enterprise-hotjar | ||
============= | ||
|
||
|Build Status| |npm_version| |npm_downloads| |license| | ||
|
||
This package exports useful React hooks, utility functions, and constants for using Hotjar. | ||
|
||
.. |Build Status| image:: https://github.com/edx/frontend-enterprise/actions/workflows/release.yml/badge.svg | ||
:target: https://github.com/edx/frontend-enterprise/actions | ||
.. |npm_version| image:: https://img.shields.io/npm/v/@edx/frontend-enterprise-utils.svg | ||
:target: @edx/frontend-enterprise-utils | ||
.. |npm_downloads| image:: https://img.shields.io/npm/dt/@edx/frontend-enterprise-utils.svg | ||
:target: @edx/frontend-enterprise-utils | ||
.. |license| image:: https://img.shields.io/npm/l/@edx/frontend-enterprise-utils.svg | ||
:target: @edx/frontend-enterprise-utils |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const { createConfig } = require('@edx/frontend-build'); | ||
|
||
module.exports = createConfig('babel-preserve-modules'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const { createConfig } = require('@edx/frontend-build'); | ||
const extendJestConfig = require('../../common/extendJestConfig'); | ||
|
||
const config = createConfig('jest'); | ||
extendJestConfig(config); | ||
|
||
module.exports = config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{ | ||
"name": "@edx/frontend-enterprise-hotjar", | ||
"version": "1.0.0", | ||
"description": "Utils for Hotjar.", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/edx/frontend-enterprise.git" | ||
}, | ||
"watch": { | ||
"build": { | ||
"patterns": [ | ||
"src" | ||
], | ||
"extensions": "js,jsx" | ||
} | ||
}, | ||
"scripts": { | ||
"dev": "npx npm-watch build", | ||
"clean": "make clean", | ||
"build": "make build", | ||
"i18n_extract": "BABEL_ENV=i18n fedx-scripts babel src --quiet > /dev/null", | ||
"lint": "fedx-scripts eslint --ext .js --ext .jsx .", | ||
"lint:fix": "fedx-scripts eslint --fix --ext .js --ext .jsx .", | ||
"snapshot": "fedx-scripts jest --updateSnapshot", | ||
"test": "fedx-scripts jest --coverage --passWithNoTests", | ||
"test:watch": "npm run test -- --watch" | ||
}, | ||
"author": "edX", | ||
"license": "AGPL-3.0", | ||
"homepage": "https://github.com/edx/frontend-enterprise#readme", | ||
"publishConfig": { | ||
"access": "public", | ||
"directory": "dist" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/edx/frontend-enterprise/issues" | ||
}, | ||
"sideEffects": false, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"@edx/browserslist-config": "1.1.0", | ||
"@edx/frontend-build": "11.0.1", | ||
"react": "16.14.0", | ||
"react-dom": "16.14.0", | ||
"react-router-dom": "5.2.0" | ||
}, | ||
"peerDependencies": { | ||
"react": "^16.12.0", | ||
"react-dom": "^16.12.0", | ||
"react-router-dom": "^5.2.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* eslint-disable no-console */ | ||
|
||
export const appendHeadScript = ({ | ||
scriptText, | ||
scriptId, | ||
}) => { | ||
try { | ||
const existingScript = document.getElementById( | ||
scriptId, | ||
); | ||
|
||
if (existingScript) { | ||
console.error(`Script ${scriptId} already exists.`); | ||
return true; | ||
} | ||
|
||
const script = existingScript || document.createElement('script'); | ||
script.id = scriptId; | ||
script.innerText = scriptText; | ||
script.crossOrigin = 'anonymous'; | ||
|
||
document.head.appendChild(script); | ||
|
||
return true; | ||
} catch { | ||
console.error(`Failed to append script ${scriptId}.`); | ||
return false; | ||
} | ||
}; | ||
|
||
export const createHotjarScriptText = ({ | ||
hotjarId, | ||
hotjarVersion, | ||
hotjarDebug, | ||
}) => `(function(h,o,t,j,a,r){h.hj=h.hj||function(){(h.hj.q=h.hj.q||[]).push(arguments)};h._hjSettings={hjid:${hotjarId},hjsv:${hotjarVersion},hjdebug:${hotjarDebug}};a=o.getElementsByTagName('head')[0];r=o.createElement('script');r.async=1;r.src=t+h._hjSettings.hjid+j+h._hjSettings.hjsv;a.appendChild(r);})(window,document,'https://static.hotjar.com/c/hotjar-','.js?sv=');`; | ||
|
||
export const initializeHotjar = ( | ||
{ | ||
hotjarId, | ||
hotjarVersion, | ||
hotjarDebug, | ||
onInitialize, | ||
}, | ||
) => { | ||
const hasWindow = typeof window !== 'undefined'; | ||
|
||
if (!hasWindow) { throw Error('Hotjar depends on window. Window is undefined.'); } | ||
|
||
const hotjarScriptText = createHotjarScriptText({ | ||
hotjarId, | ||
hotjarVersion, | ||
hotjarDebug, | ||
}); | ||
const isAppended = appendHeadScript({ | ||
scriptText: hotjarScriptText, | ||
scriptId: 'hotjar-init-script', | ||
}); | ||
|
||
if (isAppended && hasWindow && window.hj) { | ||
if (onInitialize) { | ||
onInitialize(); | ||
} | ||
} else { | ||
throw Error('Hotjar initialization failed!'); | ||
} | ||
}; | ||
|
||
export const isHotjarInitialized = () => { | ||
const hasWindow = typeof window !== 'undefined'; | ||
return hasWindow && window.hj; | ||
}; | ||
|
||
export const identifyHotjar = ({ | ||
userId, | ||
userInfo, | ||
}) => { | ||
const initialized = isHotjarInitialized(); | ||
|
||
if (initialized) { | ||
return window.hj( | ||
'identify', | ||
userId, | ||
userInfo, | ||
); | ||
} | ||
|
||
throw Error('Hotjar is not available! Is Hotjar initialized?'); | ||
}; |
Oops, something went wrong.