diff --git a/CHANGELOG.md b/CHANGELOG.md index c9275776b5..110ab4d874 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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]) @@ -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 diff --git a/src/Writers/HTMLWriter.jl b/src/Writers/HTMLWriter.jl index 46f02192e4..0aa49f2878 100644 --- a/src/Writers/HTMLWriter.jl +++ b/src/Writers/HTMLWriter.jl @@ -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