forked from umami-software/umami
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request umami-software#162 from freeyourmusic/bh/unregister
Ability to unregister umami
- Loading branch information
Showing
6 changed files
with
121 additions
and
38 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
# production | ||
/build | ||
/public/umami.js | ||
/public/snippet.js | ||
/lang-compiled | ||
/lang-formatted | ||
|
||
|
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,19 @@ | ||
import 'dotenv/config'; | ||
import buble from '@rollup/plugin-buble'; | ||
import replace from '@rollup/plugin-replace'; | ||
import resolve from '@rollup/plugin-node-resolve'; | ||
import { terser } from 'rollup-plugin-terser'; | ||
|
||
export default { | ||
input: 'tracker/snippet.js', | ||
output: { | ||
file: 'public/snippet.js', | ||
format: 'iife', | ||
}, | ||
plugins: [ | ||
replace({ __DNT__: !!process.env.ENABLE_DNT }), | ||
resolve(), | ||
buble(), | ||
terser({ compress: { evaluate: false } }), | ||
], | ||
}; |
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,43 @@ | ||
(window => { | ||
const umami = window.umami = window.umami || []; | ||
if (!umami.registerAutoEvents) { | ||
if (umami.invoked) { | ||
window.console && console.error && console.error('Umami snippet included twice.'); | ||
} else { | ||
umami.invoked = true; | ||
umami.calls = []; | ||
umami.methods = ['registerAutoEvents', 'event', 'pageView']; | ||
umami.factory = t => { | ||
return function() { | ||
const e = Array.prototype.slice.call(arguments); | ||
e.unshift(t); | ||
umami.calls.push(e); | ||
return umami; | ||
}; | ||
}; | ||
for (let t = 0; t < umami.methods.length; t++) { | ||
let e = umami.methods[t]; | ||
umami[e] = umami.factory(e); | ||
} | ||
umami.load = function(umamiScript, umamiUUID, skipAuto) { | ||
const scriptElement = document.createElement('script'); | ||
scriptElement.type = 'text/javascript'; | ||
scriptElement.defer = true; | ||
scriptElement.async = true; | ||
scriptElement.setAttribute('data-website-id', umamiUUID); | ||
if (skipAuto) { | ||
scriptElement.setAttribute('data-skip-auto', 'true'); | ||
} | ||
scriptElement.src = umamiScript; | ||
const otherScript = document.getElementsByTagName('script')[0]; | ||
otherScript.parentNode.insertBefore(scriptElement, otherScript); | ||
}; | ||
|
||
umami.load('[HOST]/umami.js', '[UMAMI_UUID]', false); | ||
} | ||
} | ||
})(window); | ||
// This snippet is for more advanced use case of Umami. If you want to track custom events, | ||
// and not worry about having blocking script in the header, | ||
// use this snippet (compiled version available in /public/snippet.js). | ||
// Just remember to replace [HOST] and [UMAMI_UUID] when pasting it. |