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

Define analytics in the global context to guard against id="analytics". #65

Merged
merged 1 commit into from
Apr 13, 2018

Conversation

abernix
Copy link
Contributor

@abernix abernix commented Apr 13, 2018

This defines analytics in the global context to guard against HTML elements on the page potentially named "analytics". This is necessary because we now have some docs pages with elements using id="analytics". Unfortunately, due to a historical artifact in web-browser history it was once made possible to access HTML elements, from JavaScript, by their ID on the window object:

window["some-div-id"]

Unfortunately, Segment.io uses a JavaScript variable named analytics, and it's not possible to push stats into an HTML DIV which happens to also be named analytics and have those stats work. 😸

Of course, it's best to use the facilities that were actually designed for that, like document.getElementById, but historical reasons have caused this window access technique to still be the behavior for modern browsers.

Ref: https://github.com/apollographql/engine-docs/pull/135
Ref: https://github.com/apollographql/engine-docs/commit/acd4a8e5
Ref: https://github.com/apollographql/engine-docs/blame/ec045186/source/index.md#L21
https://w3c.github.io/html/browsers.html#named-access-on-the-window-object.

…ics"`.

This defines `analytics` in the global context to guard against HTML elements
on the page potentially named "analytics".  This is necessary because we now
have some docs pages with elements using `id="analytics"`.  Unfortunately,
due to a historical artifact in web-browser history it was once made possible
to access HTML elements, from JavaScript, by their ID on the `window` object:

   window["some-div-id"]

Unfortunately, Segment.io uses a JavaScript variable named `analytics`, and
it's not possible to `push` stats into an HTML DIV which happens to also be
named `analytics` and have those stats work. :)

Of course, it's best to use the facilities that were actually designed for
that, like `document.getElementById`, but historical reasons have caused
this `window` access technique to still be the behavior for modern browsers.

Ref: https://github.com/apollographql/engine-docs/pull/135
Ref: https://github.com/apollographql/engine-docs/commit/acd4a8e5
Ref: https://github.com/apollographql/engine-docs/blame/ec045186/source/index.md#L21
https://w3c.github.io/html/browsers.html#named-access-on-the-window-object.
abernix added a commit that referenced this pull request Apr 13, 2018
This is a drive-by update which seemed worth landing, but turned out not to
fix the solution to the problem I was trying to fix (see refs for what that
turned out to be).

Ref: 544f1f40
Ref: #65
abernix added a commit that referenced this pull request Apr 13, 2018
This is a drive-by update which seemed worth landing, but turned out not to
fix the solution to the problem I was trying to fix (see refs for what that
turned out to be).

Ref: 544f1f40
Ref: #65
abernix added a commit that referenced this pull request Apr 13, 2018
Unfortunately, a result of the problem reported in #65 is that all other
JavaScript, including search, was prevented from working because they all
lived in a shared `<script>` tag.  This change puts each concern in its own
`<script>` tag to isolate the damage by those script tags.

Of course, each of the script providers would have had this in their own
code-snippets they offer for copy-pasting, but I guess we decided to put
them all in a single `<script>` tag at one point. 😢
abernix added a commit that referenced this pull request Apr 13, 2018
Unfortunately, a result of the problem reported in #65 is that all other
JavaScript, including search, was prevented from working because they all
lived in a shared `<script>` tag.  This change puts each concern in its own
`<script>` tag to isolate the damage by those script tags.

Of course, each of the script providers would have had this in their own
code-snippets they offer for copy-pasting, but I guess we decided to put
them all in a single `<script>` tag at one point. 😢

Ref: https://github.com/meteor/meteor-theme-hexo/commits/544f1f4084
Ref: #65
@abernix abernix merged commit dff019a into master Apr 13, 2018
@abernix abernix deleted the abernix/guard-segment-io-against-html-analytics-id branch April 13, 2018 10:44
abernix added a commit that referenced this pull request Apr 13, 2018
This is a drive-by update which seemed worth landing, but turned out not to
fix the solution to the problem I was trying to fix (see refs for what that
turned out to be).

Ref: 544f1f40
Ref: #65
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant