-
Notifications
You must be signed in to change notification settings - Fork 1
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
2 changed files
with
74 additions
and
3 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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* eslint-disable no-console */ | ||
// From ./ga.js | ||
|
||
function appendScript(id) { | ||
const script = document.createElement('script'); | ||
script.async = true; | ||
script.src = 'https://www.googletagmanager.com/gtag/js?id=' + id; | ||
document.body.appendChild(script); | ||
} | ||
|
||
// global site tag instance initialized | ||
function initGlobalSiteTag(id) { | ||
appendScript(id); | ||
|
||
window.dataLayer = window.dataLayer || []; | ||
window.gtag = | ||
window.gtag || | ||
function () { | ||
window.dataLayer.push(arguments); | ||
}; | ||
|
||
window.gtag('js', new Date()); | ||
window.gtag('config', id); | ||
} | ||
|
||
// add additional products to your tag | ||
// https://developers.google.com/tag-platform/gtagjs/install | ||
function initAdditionalTag(id) { | ||
window.gtag('config', id); | ||
} | ||
|
||
function init(ids) { | ||
if (Array.isArray(ids)) { | ||
// set the first id to be a global site tag | ||
initGlobalSiteTag(ids[0]); | ||
|
||
// the rest ids | ||
ids.forEach((id, index) => { | ||
if (index > 0) { | ||
initAdditionalTag(id); | ||
} | ||
}); | ||
} else { | ||
initGlobalSiteTag(ids); | ||
} | ||
} | ||
|
||
function collect() { | ||
if (!window.gtag) { | ||
init($docsify.gtag); | ||
} | ||
|
||
// usage: https://developers.google.com/analytics/devguides/collection/gtagjs/pages | ||
window.gtag('event', 'page_view', { | ||
/* eslint-disable camelcase */ | ||
page_title: document.title, | ||
page_location: location.href, | ||
page_path: location.pathname, | ||
/* eslint-disable camelcase */ | ||
}); | ||
} | ||
|
||
const install = function (hook) { | ||
if (!$docsify.gtag) { | ||
console.error('[Docsify] gtag is required.'); | ||
return; | ||
} | ||
|
||
hook.beforeEach(collect); | ||
}; | ||
|
||
$docsify.plugins = [].concat(install, $docsify.plugins); |
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 |
---|---|---|
|
@@ -20,15 +20,14 @@ | |
loadSidebar: true, | ||
search: 'auto', | ||
themeColor: '#E57A44', | ||
ga: 'G-4W227SRJTC' | ||
gtag: 'G-4W227SRJTC' | ||
} | ||
</script> | ||
<!-- Docsify v4 --> | ||
<script src="//cdn.jsdelivr.net/npm/docsify@4"></script> | ||
<script src="//cdn.jsdelivr.net/npm/docsify-copy-code/dist/docsify-copy-code.min.js"></script> | ||
<script src="//cdn.jsdelivr.net/npm/[email protected]/components/prism-json.min.js"></script> | ||
<script src="//cdn.jsdelivr.net/npm/docsify/lib/plugins/ga.min.js"></script> | ||
<script src="_assets/gtag.js"></script> | ||
<script src="_assets/prism-rpa.js"></script> | ||
<!--<script src="//cdn.jsdelivr.net/npm/docsify-darklight-theme@latest/dist/index.min.js" type="text/javascript"></script>--> | ||
</body> | ||
</html> |