-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(plugins): add Google Analytics plugin (#66)
- Loading branch information
1 parent
9605c18
commit ac61bb0
Showing
7 changed files
with
96 additions
and
4 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 |
---|---|---|
@@ -1,3 +1,8 @@ | ||
## 2.2.0 | ||
|
||
### Features | ||
- Add `Google Analytics` plugin. | ||
|
||
## 2.1.0 | ||
### Features | ||
- Add search plugin | ||
|
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
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,42 @@ | ||
// From https://github.com/egoist/vue-ga/blob/master/src/index.js | ||
|
||
function appendScript () { | ||
const script = document.createElement('script') | ||
script.async = true | ||
script.src = 'https://www.google-analytics.com/analytics.js' | ||
document.body.appendChild(script) | ||
} | ||
|
||
function init (id) { | ||
if (!window.ga) { | ||
appendScript() | ||
window.ga = window.ga || function () { | ||
(window.ga.q = window.ga.q || []).push(arguments) | ||
} | ||
window.ga.l = Number(new Date()) | ||
window.ga('create', id, 'auto') | ||
} | ||
} | ||
|
||
function collect () { | ||
init(window.$docsify.ga) | ||
window.ga('set', 'page', location.href) | ||
window.ga('send', 'pageview') | ||
} | ||
|
||
const install = function () { | ||
if (!window.Docsify || !window.Docsify.installed) { | ||
console.error('[Docsify] Please load docsify.js first.') | ||
return | ||
} | ||
|
||
if (!window.$docsify.ga) { | ||
console.error('[Docsify] ga is required.') | ||
return | ||
} | ||
|
||
collect() | ||
window.$docsify.plugins = [].concat(window.$docsify.plugins, collect) | ||
} | ||
|
||
export default install() |