@rhc-shared-components/rhc-eddl
v1.0.4
Published
> EDDL analytics for RHC SPAs
Downloads
30
Keywords
Readme
@rhc-shared-components/rhc-eddl
EDDL analytics for RHC SPAs
Install
npm install --save @rhc-shared-components/rhc-eddl
Usage
Add the following to your index.html as first item inside <head></head>
<script>
(function () {
// took inspiration from catalog EDDL code: https://red.ht/4aAG6E4
function insertAnalyticsScript(doc, src) {
var script = doc.createElement('script');
script.src = src;
var ref = doc.querySelector('script');
ref.parentNode.insertBefore(script, ref);
}
var srcs = [];
if ('querySelector' in document) {
// Is this production?
// DPAL scripts needed for analytics/EDDL metrics; do not remove, please
if (window.location.hostname === "connect.redhat.com") {
srcs = ["https://www.redhat.com/ma/dpal.js", "https://static.redhat.com/libs/redhat/marketing/latest/trustarc/trustarc.js"];
} else if (['connect.stage.redhat.com', 'connect.qa.redhat.com', `connect.uat.redhat.com`].indexOf(window.location.hostname) !== -1) {
srcs = ["https://www.redhat.com/ma/dpal-staging.js", "https://static.redhat.com/libs/redhat/marketing/latest/trustarc/trustarc.stage.js"];
}
for (var i = 0; i < srcs.length; i++) {
insertAnalyticsScript(document, srcs[i]);
}
}
}())
</script>
import React from 'react';
import { useRHCAuthContext } from '@rhc-shared-components/rhc-sso';
import { Formik } from 'formik';
import { checkAndSendAnalytics } from '@rhc-shared-components/rhc-eddl';
const App = () => {
const { isAuthenticated } = useRHCAuthContext(); // Auth status
const { pathname } = useLocation();
useEffect(() => {
checkAndSendAnalytics({spaName: "demo-spa"});
}, [pathname, isAuthenticated]);
return (
<div>
Hello World
</div>
)
}
export default App;