@parcellab/react-use-umami
Advanced tools
Comparing version 1.1.0 to 2.0.1
19
index.js
const React = require('react') | ||
module.exports = (url, referrer, websiteId, skipPageView) => { | ||
export const registerUmamiScript = (url, websiteId, dataDomain) => { | ||
if (url && websiteId && dataDomain) { | ||
const head = document.getElementsByTagName('head')[0] | ||
const script = document.createElement('script') | ||
script.type = 'text/javascript'; | ||
script.src = url; | ||
script.async = 'async' | ||
script.defer = 'defer' | ||
script.setAttribute('data-auto-track', 'false') | ||
script.setAttribute('data-domains', dataDomain) | ||
script.setAttribute('data-website-id', websiteId) | ||
head.appendChild(script); | ||
} | ||
} | ||
export default (url, referrer, websiteId, skipPageView) => { | ||
skipPageView = skipPageView || false | ||
React.useEffect(() => { | ||
if (!skipPageView) { | ||
if (!skipPageView && window.umami) { | ||
try { | ||
@@ -8,0 +23,0 @@ const umami = window.umami |
@@ -1,1 +0,1 @@ | ||
"use strict";var React=require("react");module.exports=function(url,referrer,websiteId,skipPageView){skipPageView=skipPageView||false;React.useEffect(function(){if(!skipPageView){try{var umami=window.umami;umami.trackView(url,referrer,websiteId)}catch(err){console.warn&&console.warn(err.message)}}},[url,referrer,websiteId,skipPageView]);var trackEvent=function trackEvent(eventValue,eventType){try{eventType=eventType||"custom";var umami=window.umami;umami.trackEvent(eventValue,eventType,url,websiteId)}catch(err){console.warn&&console.warn(err.message)}};return trackEvent}; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.default=exports.registerUmamiScript=void 0;var React=require("react");var registerUmamiScript=function registerUmamiScript(url,websiteId,dataDomain){if(url&&websiteId&&dataDomain){var head=document.getElementsByTagName("head")[0];var script=document.createElement("script");script.type="text/javascript";script.src=url;script.async="async";script.defer="defer";script.setAttribute("data-auto-track","false");script.setAttribute("data-domains",dataDomain);script.setAttribute("data-website-id",websiteId);head.appendChild(script)}};exports.registerUmamiScript=registerUmamiScript;var _default=function _default(url,referrer,websiteId,skipPageView){skipPageView=skipPageView||false;React.useEffect(function(){if(!skipPageView&&window.umami){try{var umami=window.umami;umami.trackView(url,referrer,websiteId)}catch(err){console.warn&&console.warn(err.message)}}},[url,referrer,websiteId,skipPageView]);var trackEvent=function trackEvent(eventValue,eventType){try{eventType=eventType||"custom";var umami=window.umami;umami.trackEvent(eventValue,eventType,url,websiteId)}catch(err){console.warn&&console.warn(err.message)}};return trackEvent};exports.default=_default; |
{ | ||
"name": "@parcellab/react-use-umami", | ||
"version": "1.1.0", | ||
"version": "2.0.1", | ||
"description": "React tools for Umami Analytics.", | ||
@@ -22,4 +22,6 @@ "main": "index.min.js", | ||
"devDependencies": { | ||
"@babel/cli": "^7.14.5", | ||
"@babel/core": "^7.14.6", | ||
"@babel/preset-env": "^7.12.11" | ||
} | ||
} |
@@ -11,3 +11,4 @@ # 🥓 react-use-umami | ||
Then follow the instructions on the [umami docs page](https://umami.is/docs/) to add the script to the `<head>` section of your page if you have not already. After this (disable the automatic page view tracking)[https://umami.is/docs/tracker-config] ba adding | ||
Then you'll need to add the script to the `<head>` section of your page. | ||
* This can be done manually: Follow the instructions on the [umami docs page](https://umami.is/docs/) to add the script to the `<head>` section of your page if you have not already. After this (disable the automatic page view tracking)[https://umami.is/docs/tracker-config] ba adding | ||
`data-auto-track="false"` to your tracking script so it looks something like this: | ||
@@ -21,2 +22,19 @@ ``` | ||
``` | ||
* Or using `registerUmamiScript` function from the package. | ||
```javascript | ||
import React from 'react' | ||
import { registerUmamiScript } from '@parcellab/react-use-umami' | ||
export default function App ({ url, websiteId, dataDomain }) { | ||
React.useEffect(() => { | ||
registerUmamiScript(url, websiteId, dataDomain) | ||
}, []) | ||
return ( | ||
<> | ||
<HomePage /> | ||
... | ||
</> | ||
) | ||
} | ||
``` | ||
@@ -54,1 +72,4 @@ ## Usage | ||
Tracks a (custom) event. If **event_type** is omitted it will default to 'custom'. Can be called multiple times. | ||
### registerUmamiScript(url, websiteId, dataDomain) : function registerUmamiScript | ||
Adds script with url, websiteId and dataDomain to the header of the html page. Should be triggerd once in the root component (use `useEffect` hook with an empty array as a second argument to trigger once). This can also be done manually without usage of this function. For reference see the docs [umami docs page](https://umami.is/docs/) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
6063
43
73
3