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
Changes from 2 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
16 changes: 9 additions & 7 deletions src/Writers/HTMLWriter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -891,13 +891,15 @@ end
analytics_script(tracking_id::AbstractString) =
isempty(tracking_id) ? Tag(Symbol("#RAW#"))("") : Tag(:script)(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tag(:script) tag may be redundant with <script>

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay. But yes, you're right, this would be redundant. In fact, you'd end up with nested <script> tags, which means that I don't think this would work at all at the moment.

Instead, I'd recommend explicitly constructing both of the <script> tags in Julia. It should be fine if analytics_script returns an array of Tags.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the syntax for constructing tags in Julia documented? (e.g., how do you do <script async src="...">?)

Copy link
Member

@mortenpi mortenpi Apr 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep: https://juliadocs.github.io/Documenter.jl/stable/lib/internals/dom/

Also, heaps of usage examples in HTMLWriter.jl.

"""
(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});
<script async src="https://www.googletagmanager.com/gtag/js?id=$(tracking_id)"></script>
<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});

gtag('config', '$(tracking_id)');
mlubin marked this conversation as resolved.
Show resolved Hide resolved
mlubin marked this conversation as resolved.
Show resolved Hide resolved
</script>
"""
)

Expand Down