Skip to content
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

Update from analytics.js to gtag.js #1559

Merged
merged 6 commits into from
Jun 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

* ![Enhancement][badge-enhancement] The generated HTML sites can now detect if the version the user is browsing is not for the latest version of the package and display a notice box to the user with a link to the latest version. In addition, the pages get a `noindex` tag which should aid in removing outdated versions from search engine results. ([#1302][github-1302], [#1449][github-1449], [#1577][github-1577])

* ![Enhancement][badge-enhancement] The analytics in the HTML output now use the `gtag.js` script, replacing the old deprecated setup. ([#1559][github-1559])

* ![Bugfix][badge-bugfix] A bad `repo` argument to `deploydocs` containing a protocol now throws an error instead of being misinterpreted. ([#1531][github-1531], [#1533][github-1533])

* ![Bugfix][badge-bugfix] SVG images generated by `@example` blocks are now properly scaled to page width by URI-encoding the images, instead of directly embedding the SVG tags into the HTML. ([#1537][github-1537], [#1538][github-1538])
Expand Down Expand Up @@ -788,6 +790,7 @@
[github-1553]: https://github.com/JuliaDocs/Documenter.jl/pull/1553
[github-1556]: https://github.com/JuliaDocs/Documenter.jl/issues/1556
[github-1557]: https://github.com/JuliaDocs/Documenter.jl/pull/1557
[github-1559]: https://github.com/JuliaDocs/Documenter.jl/pull/1559
[github-1567]: https://github.com/JuliaDocs/Documenter.jl/pull/1567
[github-1577]: https://github.com/JuliaDocs/Documenter.jl/pull/1577

Expand Down
24 changes: 12 additions & 12 deletions src/Writers/HTMLWriter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -899,18 +899,18 @@ function asset_links(src::AbstractString, assets::Vector{HTMLAsset})
return links
end

analytics_script(tracking_id::AbstractString) =
isempty(tracking_id) ? Tag(Symbol("#RAW#"))("") : Tag(:script)(
"""
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

ga('create', '$(tracking_id)', 'auto');
ga('send', 'pageview', {'page': location.pathname + location.search + location.hash});
"""
)
function analytics_script(tracking_id::AbstractString)
@tags script
isempty(tracking_id) ? Tag(Symbol("#RAW#"))("") : [
script[:async, :src => "https://www.googletagmanager.com/gtag/js?id=$(tracking_id)"](),
script("""
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '$(tracking_id)', {'page_path': location.pathname + location.search + location.hash});
""")
]
end

function warning_script(src, ctx)
if ctx.settings.warn_outdated
Expand Down