Skip to content

Commit

Permalink
doc: remove GA tracking
Browse files Browse the repository at this point in the history
The Google Analytics tracking wasn't wholly uncontroversial and hasn't
been used in practice. Remove it.

PR-URL: #23083
Fixes: #22652
Refs: #6601
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Roman Reiss <me@silverwind.io>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
  • Loading branch information
bnoordhuis authored and targos committed Oct 4, 2018
1 parent 748d9d2 commit 003d85d
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 56 deletions.
8 changes: 1 addition & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -597,11 +597,6 @@ test-v8 test-v8-intl test-v8-benchmarks test-v8-all:
"$ git clone https://github.com/nodejs/node.git"
endif

# Google Analytics ID used for tracking API docs page views, empty
# DOCS_ANALYTICS means no tracking scripts will be included in the
# generated .html files
DOCS_ANALYTICS ?=

apidoc_dirs = out/doc out/doc/api out/doc/api/assets
apidoc_sources = $(wildcard doc/api/*.md)
apidocs_html = $(addprefix out/,$(apidoc_sources:.md=.html))
Expand Down Expand Up @@ -646,8 +641,7 @@ out/doc/api/assets/%: doc/api_assets/% out/doc/api/assets
run-npm-ci = $(PWD)/$(NPM) ci

gen-api = tools/doc/generate.js --node-version=$(FULLVERSION) \
--apilinks=out/apilinks.json \
--analytics=$(DOCS_ANALYTICS) $< --output-directory=out/doc/api
--apilinks=out/apilinks.json $< --output-directory=out/doc/api
gen-apilink = tools/doc/apilinks.js $(wildcard lib/*.js) > $@

out/apilinks.json: $(wildcard lib/*.js) tools/doc/apilinks.js
Expand Down
1 change: 0 additions & 1 deletion doc/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,5 @@ <h2>Table of Contents</h2>
<script src="assets/sh_main.js"></script>
<script src="assets/sh_javascript.min.js"></script>
<script>highlight(undefined, undefined, 'pre');</script>
<!-- __TRACKING__ -->
</body>
</html>
21 changes: 3 additions & 18 deletions test/doctool/test-doctool-html.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const remark2rehype = require('remark-rehype');
const raw = require('rehype-raw');
const htmlStringify = require('rehype-stringify');

function toHTML({ input, filename, nodeVersion, analytics }, cb) {
function toHTML({ input, filename, nodeVersion }, cb) {
const content = unified()
.use(markdown)
.use(html.firstHeader)
Expand All @@ -35,7 +35,7 @@ function toHTML({ input, filename, nodeVersion, analytics }, cb) {
.processSync(input);

html.toHTML(
{ input, content, filename, nodeVersion, analytics },
{ input, content, filename, nodeVersion },
cb
);
}
Expand Down Expand Up @@ -94,16 +94,14 @@ const testData = [
file: fixtures.path('sample_document.md'),
html: '<ol><li>fish</li><li>fish</li></ol>' +
'<ul><li>Red fish</li><li>Blue fish</li></ul>',
analyticsId: 'UA-67020396-1'
},
];

const spaces = /\s/g;

testData.forEach(({ file, html, analyticsId }) => {
testData.forEach(({ file, html }) => {
// Normalize expected data by stripping whitespace.
const expected = html.replace(spaces, '');
const includeAnalytics = typeof analyticsId !== 'undefined';

readFile(file, 'utf8', common.mustCall((err, input) => {
assert.ifError(err);
Expand All @@ -112,7 +110,6 @@ testData.forEach(({ file, html, analyticsId }) => {
input: input,
filename: 'foo',
nodeVersion: process.version,
analytics: analyticsId,
},
common.mustCall((err, output) => {
assert.ifError(err);
Expand All @@ -121,18 +118,6 @@ testData.forEach(({ file, html, analyticsId }) => {
// Assert that the input stripped of all whitespace contains the
// expected markup.
assert(actual.includes(expected));

// Testing the insertion of Google Analytics script when
// an analytics id is provided. Should not be present by default.
const scriptDomain = 'google-analytics.com';
if (includeAnalytics) {
assert(actual.includes(scriptDomain),
`Google Analytics script was not present in "${actual}"`);
} else {
assert.strictEqual(actual.includes(scriptDomain), false,
'Google Analytics script was present in ' +
`"${actual}"`);
}
})
);
}));
Expand Down
5 changes: 1 addition & 4 deletions tools/doc/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ const json = require('./json');
const args = process.argv.slice(2);
let filename = null;
let nodeVersion = null;
let analytics = null;
let outputDir = null;
let apilinks = {};

Expand All @@ -47,8 +46,6 @@ args.forEach(function(arg) {
filename = arg;
} else if (arg.startsWith('--node-version=')) {
nodeVersion = arg.replace(/^--node-version=/, '');
} else if (arg.startsWith('--analytics=')) {
analytics = arg.replace(/^--analytics=/, '');
} else if (arg.startsWith('--output-directory=')) {
outputDir = arg.replace(/^--output-directory=/, '');
} else if (arg.startsWith('--apilinks=')) {
Expand Down Expand Up @@ -85,7 +82,7 @@ fs.readFile(filename, 'utf8', (er, input) => {
const basename = path.basename(filename, '.md');

html.toHTML(
{ input, content, filename, nodeVersion, analytics },
{ input, content, filename, nodeVersion },
(err, html) => {
const target = path.join(outputDir, `${basename}.html`);
if (err) throw err;
Expand Down
26 changes: 1 addition & 25 deletions tools/doc/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const gtocHTML = unified()
const templatePath = path.join(docPath, 'template.html');
const template = fs.readFileSync(templatePath, 'utf8');

function toHTML({ input, content, filename, nodeVersion, analytics }, cb) {
function toHTML({ input, content, filename, nodeVersion }, cb) {
filename = path.basename(filename, '.md');

const id = filename.replace(/\W+/g, '-');
Expand All @@ -77,30 +77,6 @@ function toHTML({ input, content, filename, nodeVersion, analytics }, cb) {
.replace('__EDIT_ON_GITHUB__', editOnGitHub(filename))
.replace('__CONTENT__', content.toString());

if (analytics) {
HTML = HTML.replace('<!-- __TRACKING__ -->', `
<script type="text/javascript">
// In all the browsers we'll get '1' or 'yes' (FF 32 or above) as a string
// value when enabling 'DO NOT TRACK'.
// For more:
// https://developer.mozilla.org/en-US/docs/Web/API/navigator/doNotTrack
function isDoNotTrack() {
var isDoNotTrackEnabled = navigator.doNotTrack || window.doNotTrack ||
navigator.msDoNotTrack;
return isDoNotTrackEnabled === '1' || isDoNotTrackEnabled === 'yes';
}
if (!isDoNotTrack()) {
(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','//www.google-analytics.com/analytics.js','ga');
ga('create', '${analytics}', 'auto');
ga('send', 'pageview');
}
</script>`);
}

const docCreated = input.match(
/<!--\s*introduced_in\s*=\s*v([0-9]+)\.([0-9]+)\.[0-9]+\s*-->/);
if (docCreated) {
Expand Down
2 changes: 1 addition & 1 deletion vcbuild.bat
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ robocopy /e doc\api %config%\doc\api
robocopy /e doc\api_assets %config%\doc\api\assets

for %%F in (%config%\doc\api\*.md) do (
%node_exe% tools\doc\generate.js --node-version=v%FULLVERSION% --analytics=%DOCS_ANALYTICS% %%F --output-directory=%%~dF%%~pF
%node_exe% tools\doc\generate.js --node-version=v%FULLVERSION% %%F --output-directory=%%~dF%%~pF
)

:run
Expand Down

0 comments on commit 003d85d

Please sign in to comment.