Skip to content

Commit b6adbbf

Browse files
committed
fix(api): Only call Google Tag Manager if hostname has influxdata.com - prevents undefined GTM object errors in dev
- Stub Google Tag Manager in the test
1 parent 0b7b73b commit b6adbbf

File tree

3 files changed

+147
-1
lines changed

3 files changed

+147
-1
lines changed

api-docs/template.hbs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
<head>
55
<!-- Google Tag Manager -->
6-
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
6+
<script>window.location.hostname.endsWith('influxdata.com') && (function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
77
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
88
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
99
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
@@ -30,6 +30,21 @@
3030
</head>
3131

3232
<body>
33+
{{!-- <script>
34+
document.addEventListener('DOMContentLoaded', function() {
35+
// Prevent throwing errors when the Google Tag Manager script is blocked
36+
if (!window.hasOwnProperty('fcdsc')) {
37+
window.fcdsc = (function() {
38+
// Return nothing for any function call chained off of fcdsc
39+
return new Proxy({}, {
40+
get: function(target, prop) {
41+
return function() {};
42+
}
43+
});
44+
})();
45+
}
46+
});
47+
</script> --}}
3348
<!-- Google Tag Manager (noscript) -->
3449
<noscript>
3550
<iframe src="https://www.googletagmanager.com/ns.html?id=GTM-WXRH9C" height="0" width="0" style="display:none;visibility:hidden"></iframe>
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/// <reference types="cypress" />
2+
const fakeGoogleTagManager = {
3+
trackingOptIn: () => {},
4+
trackingOptOut: () => {}
5+
}
6+
7+
describe('API reference content', () => {
8+
const subjects = [
9+
'/influxdb/cloud/api/',
10+
'/influxdb/cloud/api/v1/',
11+
'/influxdb/cloud/api/v1-compatibility/',
12+
'/influxdb/cloud/api/v2/',
13+
14+
'/influxdb/v2/api/',
15+
'/influxdb/v2/api/v1/',
16+
'/influxdb/v2/api/v1-compatibility/',
17+
'/influxdb/v2/api/v2/',
18+
19+
'/influxdb3/cloud-dedicated/api/',
20+
'/influxdb3/cloud-dedicated/api/management/',
21+
'/influxdb3/cloud-dedicated/api/v1/',
22+
'/influxdb3/cloud-dedicated/api/v1-compatibility/',
23+
'/influxdb3/cloud-dedicated/api/v2/',
24+
25+
'/influxdb3/cloud-serverless/api/',
26+
'/influxdb3/cloud-serverless/api/v1/',
27+
'/influxdb3/cloud-serverless/api/v1-compatibility/',
28+
'/influxdb3/cloud-serverless/api/v2/',
29+
30+
'/influxdb3/clustered/api/',
31+
// TODO '/influxdb3/clustered/api/management/',
32+
'/influxdb3/clustered/api/v1/',
33+
'/influxdb3/clustered/api/v1-compatibility/',
34+
'/influxdb3/clustered/api/v2/',
35+
'/influxdb3/core/api/',
36+
37+
'/influxdb3/enterprise/api/',
38+
];
39+
40+
subjects.forEach((subject) => {
41+
describe(subject, () => {
42+
it(`has API info`, function () {
43+
cy.visit(subject);
44+
window.fcdsc = fakeGoogleTagManager;
45+
cy.stub(window.fcdsc, 'trackingOptIn').as('trackingOptIn');
46+
cy.stub(window.fcdsc, 'trackingOptOut').as('trackingOptOut');
47+
cy.get('h1').first().should('have.length', 1);
48+
cy.get('[data-role$=description]').should('have.length', 1);
49+
});
50+
it('links back to the version home page', function () {
51+
cy.visit(`${subject}`);
52+
window.fcdsc = fakeGoogleTagManager;
53+
cy.stub(window.fcdsc, 'trackingOptIn').as('trackingOptIn');
54+
cy.stub(window.fcdsc, 'trackingOptOut').as('trackingOptOut');
55+
cy.get('a.back').contains('Docs')
56+
.should('have.length', 1)
57+
.click();
58+
// Path should be the first two segments and trailing slash in $subject
59+
cy.location('pathname')
60+
.should('eq', subject.replace(/^(\/[^/]+\/[^/]+\/).*/, '$1'));
61+
cy.get('h1').should('have.length', 1);
62+
});
63+
it('contains valid internal links', function () {
64+
cy.visit(subject);
65+
window.fcdsc = fakeGoogleTagManager;
66+
cy.stub(window.fcdsc, 'trackingOptIn').as('trackingOptIn');
67+
cy.stub(window.fcdsc, 'trackingOptOut').as('trackingOptOut');
68+
// The following conditional test isn't the cypress way, but the doc might not have internal links.
69+
cy.get('body').then(($body) => {
70+
if ($body.find('p a[href^="/"]').length === 0) {
71+
cy.log('No internal links found');
72+
return;
73+
}
74+
cy.get('p a[href^="/"]').as('internal-links');
75+
cy.get('@internal-links').each(($a) => {
76+
cy.log(`** Testing link ${$a.attr('href')} **`);
77+
// cy.request doesn't show in your browser's Developer Tools
78+
// because the request comes from Node, not from the browser.
79+
cy.request($a.attr('href')).its('status').should('eq', 200);
80+
});
81+
82+
});
83+
});
84+
it('contains valid external links', function () {
85+
cy.visit(subject);
86+
window.fcdsc = fakeGoogleTagManager;
87+
cy.stub(window.fcdsc, 'trackingOptIn').as('trackingOptIn');
88+
cy.stub(window.fcdsc, 'trackingOptOut').as('trackingOptOut');
89+
// The following conditional test isn't the cypress way, but the doc might not have external links.
90+
cy.get('body').then(($body) => {
91+
if ($body.find('p a[href^="http"]').length === 0) {
92+
cy.log('No external links found');
93+
return;
94+
}
95+
cy.get('p a[href^="http"]').as('external-links');
96+
cy.get('@external-links').each(($a) => {
97+
cy.log(`** Testing link ${$a.attr('href')} **`);
98+
cy.request($a.attr('href')).its('status').should('eq', 200);
99+
});
100+
});
101+
});
102+
});
103+
});
104+
});
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/// <reference types="cypress" />
2+
describe('Article links', () => {
3+
const subjects = Cypress.env('test_subjects').split(',');
4+
5+
subjects.forEach((subject) => {
6+
it('contains valid internal links', function () {
7+
cy.visit(`${subject}`);
8+
cy.get('article a[href^="/"]') //.filter('[href^="/"]')
9+
.each(($a) => {
10+
cy.log(`** Testing internal link ${$a.attr('href')} **`);
11+
// cy.request doesn't show in your browser's Developer Tools
12+
// because the request comes from Node, not from the browser.
13+
cy.request($a.attr('href')).its('status').should('eq', 200);
14+
});
15+
});
16+
it('contains valid external links', function () {
17+
cy.visit(`${subject}`);
18+
cy.get('article a[href^="http"]')
19+
.each(($a) => {
20+
// cy.request doesn't show in your browser's Developer Tools
21+
cy.log(`** Testing external link ${$a.attr('href')} **`);
22+
// because the request comes from Node, not from the browser.
23+
cy.request($a.attr('href')).its('status').should('eq', 200);
24+
});
25+
});
26+
});
27+
});

0 commit comments

Comments
 (0)