-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
feat: add google analytics gtag.js plugin #1702
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
6554fb8
feat: add google analytics gtag.js plugin
ekoz b3eeeed
feat: add google universal analytics gtag.js plugin
ekoz b22e866
Merge branch 'develop' into develop
trusktr db4a103
Merge branch 'develop' into develop
trusktr 515fbdc
Merge branch 'develop' into develop
sy-records 5a05b30
Update gtag.js
sy-records 7fc9b52
Merge branch 'develop' into develop
sy-records b3a8703
feat: add google universal analytics gtag.js plugin
ekoz 9e43564
feat: add google universal analytics gtag.js plugin
ekoz c97b35b
feat: add google universal analytics gtag.js plugin
ekoz 3410580
feat: add google universal analytics gtag.js plugin
ekoz 456f844
feat: add google universal analytics gtag.js plugin
ekoz 6a3bd84
Merge branch 'develop' into develop
jhildenbiddle 9a854ec
feat: add Google Analytics 4 (GA4) gtag.js plugin (#1695)
d33b805
Merge branch 'develop' into develop
jhildenbiddle 390dd64
Merge branch 'develop' into develop
sy-records 9b34990
Merge branch 'docsifyjs:develop' into develop
ekoz 6fc4933
Merge branch 'develop' into develop
sy-records 44da1a6
Merge branch 'develop' into develop
sy-records File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,47 @@ | ||
/* eslint-disable no-console */ | ||
// copy from ./ga.js | ||
// usage is the same as ./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); | ||
} | ||
|
||
function init(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); | ||
} | ||
|
||
function collect() { | ||
if (!window.ga) { | ||
init($docsify.ga); | ||
} | ||
|
||
// usage: https://developers.google.com/analytics/devguides/collection/gtagjs/pages | ||
window.gtag('event', 'page_view', { | ||
page_title: document.title, | ||
page_location: location.href, | ||
page_path: location.pathname, | ||
}); | ||
} | ||
|
||
const install = function(hook) { | ||
if (!$docsify.ga) { | ||
console.error('[Docsify] ga is required.'); | ||
return; | ||
} | ||
|
||
hook.beforeEach(collect); | ||
}; | ||
|
||
$docsify.plugins = [].concat(install, $docsify.plugins); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.