Skip to content

Commit

Permalink
Update from analytics.js to gtag.js (#1559)
Browse files Browse the repository at this point in the history
Co-authored-by: Ian Butterworth <[email protected]>
Co-authored-by: Morten Piibeleht <[email protected]>
  • Loading branch information
3 people authored Jun 10, 2021
1 parent 4d381ea commit 9f54fe2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
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

0 comments on commit 9f54fe2

Please sign in to comment.