Skip to content

Commit 82010a9

Browse files
committed
#000 | refactor: migrate from Google Analytics to gtag and optimize site performance
1 parent 693517c commit 82010a9

File tree

16 files changed

+194
-125
lines changed

16 files changed

+194
-125
lines changed

Makefile

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
1+
# Speedier defaults and robust targets
2+
.PHONY: start deps clean build serve
3+
4+
NPM_FLAGS ?= --prefer-offline --no-audit --no-fund
15

26
start:
37
npm run develop
48

59
deps:
6-
npm i
10+
@if [ -d node_modules ]; then \
11+
npm i $(NPM_FLAGS); \
12+
else \
13+
npm ci $(NPM_FLAGS); \
14+
fi
715

816
clean:
9-
rm -rf node_modules
17+
rm -rf node_modules
18+
19+
build:
20+
NODE_ENV=production npm run build
21+
22+
serve:
23+
npm run serve

_headers

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
[[headers]]
22
for = "/static/*"
33
[headers.values]
4-
Cache-Control = "public, max-age=360000"
4+
Cache-Control = "public, max-age=31536000, immutable"
5+
6+
[[headers]]
7+
for = "/page-data/*"
8+
[headers.values]
9+
Cache-Control = "public, max-age=31536000, immutable"

gatsby-config.js

Lines changed: 20 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,21 @@ module.exports = {
1111
},
1212
plugins: [
1313
{
14-
resolve: `gatsby-plugin-google-analytics`,
14+
resolve: `gatsby-plugin-google-gtag`,
1515
options: {
16-
trackingId: "UA-151665102-1",
17-
// Defines where to place the tracking script - `true` in the head and `false` in the body
18-
head: false,
19-
// Setting this parameter is optional
20-
anonymize: true,
21-
// Setting this parameter is also optional
22-
respectDNT: true,
23-
// Avoids sending pageview hits from custom paths
24-
exclude: ["/do-not-track/example/"],
25-
// Delays sending pageview hits on route update (in milliseconds)
26-
pageTransitionDelay: 0,
27-
defer: true,
28-
enableWebVitalsTracking: true,
29-
// Enables Google Optimize using your container Id
30-
// optimizeId: "YOUR_GOOGLE_OPTIMIZE_TRACKING_ID",
31-
// Enables Google Optimize Experiment ID
32-
// experimentId: "YOUR_GOOGLE_EXPERIMENT_ID",
33-
// Set Variation ID. 0 for original 1,2,3....
34-
// variationId: "YOUR_GOOGLE_OPTIMIZE_VARIATION_ID",
35-
// Any additional optional fields
36-
// sampleRate: 5,
37-
// siteSpeedSampleRate: 10,
38-
// cookieDomain: "example.com",
16+
trackingIds: [
17+
'G-Y3E7H5MDX8',
18+
'AW-17511540130'
19+
],
20+
gtagConfig: {
21+
anonymize_ip: true,
22+
},
23+
pluginConfig: {
24+
head: false,
25+
respectDNT: true,
26+
delayOnRouteUpdate: 0,
27+
exclude: ['/preview/**', '/do-not-track/**'],
28+
},
3929
},
4030
},
4131
'gatsby-plugin-react-helmet',
@@ -110,26 +100,20 @@ module.exports = {
110100
},
111101
},
112102
{
113-
resolve: 'gatsby-plugin-google-tagmanager',
103+
resolve: 'gatsby-plugin-webpack-bundle-analyser-v2',
114104
options: {
115-
id: 'AW-17511540130',
116-
// Optional: Include in development environment
117-
includeInDevelopment: false,
118-
// Optional: Default data layer values
119-
defaultDataLayer: {platform: 'gatsby'},
120-
// Optional: Respect Do Not Track (DNT) browser setting
121-
respectDNT: true,
122-
// Optional: Exclude certain paths from tracking
123-
exclude: ['/preview/**', '/do-not-track/'],
124-
// Optional: Delay pageview event on route updates (e.g., for page transitions)
125-
delayOnRouteUpdate: 0,
105+
analyzerMode: 'static',
106+
reportFilename: 'bundle-report.html',
107+
openAnalyzer: false,
108+
disable: !process.env.ANALYZE_BUNDLE,
126109
},
127110
},
128111
{
129112
resolve: 'gatsby-plugin-purgecss', // purges all unused/unreferenced css rules
130113
options: {
131114
develop: true, // Activates purging in npm run develop
132115
purgeOnly: ['/all.sass'], // applies purging only on the bulma css file
116+
printRejected: true,
133117
},
134118
}, // must be after other CSS plugins
135119
'gatsby-plugin-netlify', // make sure to keep it last in the array

gatsby-ssr.js

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,3 @@
11
import React from "react";
22

3-
export const onRenderBody = ({ setHeadComponents }) => {
4-
setHeadComponents([
5-
<script
6-
key="google-ads-tag"
7-
async
8-
src="https://www.googletagmanager.com/gtag/js?id=AW-17511540130"
9-
/>,
10-
<script
11-
key="google-ads-inline"
12-
dangerouslySetInnerHTML={{
13-
__html: `
14-
window.dataLayer = window.dataLayer || [];
15-
function gtag(){dataLayer.push(arguments);}
16-
gtag('js', new Date());
17-
gtag('config', 'AW-17511540130');
18-
`,
19-
}}
20-
/>,
21-
]);
22-
};
3+
export const onRenderBody = () => {};

optimize-hero.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
Optimizes the homepage hero image for better LCP.
3+
- Backs up src/img/cover.png to src/img/cover.original.png (if not already backed up)
4+
- Writes an optimized resized PNG back to src/img/cover.png (max width 2000)
5+
- Also generates src/img/cover.jpg and src/img/cover.webp for future use
6+
*/
7+
8+
const fs = require('fs');
9+
const path = require('path');
10+
const sharp = require('sharp');
11+
12+
(async () => {
13+
const imgDir = path.join(__dirname, '..', 'src', 'img');
14+
const srcPng = path.join(imgDir, 'cover.png');
15+
const backupPng = path.join(imgDir, 'cover.original.png');
16+
const outPng = path.join(imgDir, 'cover.png');
17+
const outJpg = path.join(imgDir, 'cover.jpg');
18+
const outWebp = path.join(imgDir, 'cover.webp');
19+
20+
if (!fs.existsSync(srcPng)) {
21+
console.error('Source image not found at', srcPng);
22+
process.exit(1);
23+
}
24+
25+
// Backup original once
26+
if (!fs.existsSync(backupPng)) {
27+
fs.copyFileSync(srcPng, backupPng);
28+
console.log('Backed up original to', backupPng);
29+
} else {
30+
console.log('Backup already exists at', backupPng);
31+
}
32+
33+
const pipeline = sharp(srcPng).resize({ width: 2000, withoutEnlargement: true });
34+
35+
// Optimized PNG overwrite
36+
await pipeline.clone().png({ quality: 70, compressionLevel: 9 }).toFile(outPng);
37+
console.log('Wrote optimized PNG to', outPng);
38+
39+
// Also create JPG and WebP variants
40+
await pipeline.clone().jpeg({ quality: 70 }).toFile(outJpg);
41+
console.log('Wrote optimized JPG to', outJpg);
42+
43+
await pipeline.clone().webp({ quality: 70 }).toFile(outWebp);
44+
console.log('Wrote optimized WebP to', outWebp);
45+
46+
console.log('Optimization complete.');
47+
})().catch((e) => {
48+
console.error(e);
49+
process.exit(1);
50+
});

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,20 @@
66
"dependencies": {
77
"bulma": "^0.9.1",
88
"fs-extra": "^8.1.0",
9+
"@loadable/component": "^5.15.2",
910
"gatsby": "^2.24.78",
1011
"gatsby-image": "^2.11.0",
1112
"gatsby-plugin-catch-links": "^5.14.0",
12-
"gatsby-plugin-google-analytics": "^2.3.18",
13-
"gatsby-plugin-google-tagmanager": "^2.0.15",
13+
"gatsby-plugin-google-gtag": "^1.2.0",
14+
"gatsby-plugin-loadable-components-ssr": "^2.1.0",
1415
"gatsby-plugin-netlify": "^2.3.19",
1516
"gatsby-plugin-netlify-cms": "^4.3.16",
1617
"gatsby-plugin-purgecss": "^5.0.0",
1718
"gatsby-plugin-react-helmet": "^3.3.14",
1819
"gatsby-plugin-sass": "^2.3.16",
1920
"gatsby-plugin-sharp": "^2.14.4",
2021
"gatsby-plugin-sitemap": "^2.4.17",
22+
"gatsby-plugin-webpack-bundle-analyser-v2": "^1.1.32",
2123
"gatsby-plugin-typography": "^2.5.13",
2224
"gatsby-remark-copy-linked-files": "^2.3.19",
2325
"gatsby-remark-embed-video": "^3.0.10",
@@ -36,12 +38,10 @@
3638
"parcel-bundler": "^1.12.4",
3739
"prop-types": "^15.7.2",
3840
"react": "^16.14.0",
39-
"react-calendly": "^1.1.3",
4041
"react-dom": "^16.14.0",
4142
"react-google-recaptcha": "^3.1.0",
4243
"react-helmet": "^6.1.0",
4344
"react-phone-number-input": "^3.4.12",
44-
"react-share": "^4.3.1",
4545
"react-typography": "^0.16.19",
4646
"rss": "^1.2.2",
4747
"sharp": "^0.26.2",
@@ -61,6 +61,7 @@
6161
"build:app": "npm run clean && gatsby build",
6262
"build:lambda": "netlify-lambda build src/lambda",
6363
"build": "run-p build:**",
64+
"analyze": "ANALYZE_BUNDLE=true gatsby build",
6465
"develop": "npm run clean && gatsby develop",
6566
"serve": "gatsby serve",
6667
"format": "prettier --trailing-comma es5 --no-semi --single-quote --write \"{gatsby-*.js,src/**/*.js}\"",

src/components/LandingPageHero.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import React from "react";
22
import Navbar from "./Navbar"
33
// import banner from '../img/cover.png'
44
// import DiwaliBanner from '../img/diwali-banner.jpg'
5-
import {PopupText} from "react-calendly";
65
import Constants from "../Constants";
76
import SecondaryCTAButton from "./SecondaryCTAButton";
87
import Img from "gatsby-image";
98
import {graphql, useStaticQuery} from 'gatsby';
9+
import { Helmet } from "react-helmet";
1010

1111
let subtitle = function (text) {
1212
return <p
@@ -24,15 +24,23 @@ export default function LandingPageHero() {
2424
query {
2525
file(relativePath: { eq: "cover.png" }) {
2626
childImageSharp {
27-
fluid {
28-
...GatsbyImageSharpFluid_withWebp_tracedSVG
27+
fluid(maxWidth: 2000, quality: 70, toFormat: JPG) {
28+
...GatsbyImageSharpFluid_withWebp
2929
}
3030
}
3131
}
3232
}
3333
`)
3434
return (
3535
<div>
36+
<Helmet>
37+
<link
38+
rel="preload"
39+
as="image"
40+
href={data.file.childImageSharp.fluid.src}
41+
imagesrcset={data.file.childImageSharp.fluid.srcSet}
42+
/>
43+
</Helmet>
3644
<div className="hero-head">
3745
<Navbar/>
3846
</div>
@@ -83,11 +91,12 @@ export default function LandingPageHero() {
8391
<div style={{paddingTop: '1rem', flexDirection: 'column', display: 'flex', alignItems: 'center'}}>
8492
<SecondaryCTAButton text="Try for free" link={`/signup?${Constants.ContactSource}=${Constants.Trial}`}/>
8593
<p className="button is-primary is-medium" style={{marginTop: 10}}>
86-
<PopupText
87-
text="Schedule a Demo"
88-
url="https://calendly.com/avnisupport-samanvayfoundation/product-demo-and-discussion"
89-
styles={{color: 'white', fontWeight: 'bold'}}
90-
/>
94+
<a
95+
href="https://calendly.com/avnisupport-samanvayfoundation/product-demo-and-discussion"
96+
style={{color: 'white', fontWeight: 'bold'}}
97+
>
98+
Schedule a Demo
99+
</a>
91100
</p>
92101
</div>
93102
</div>

src/components/Navbar.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {Link} from 'gatsby'
33
import logo from '../img/avni-logo-color.png'
44
import {Location} from '@reach/router'
55
import Constants from "../Constants";
6-
import {PopupText} from "react-calendly";
76

87

98
export default class Navbar extends React.Component {
@@ -50,7 +49,10 @@ export default class Navbar extends React.Component {
5049
src={logo}
5150
alt="avni"
5251
className="logo"
53-
style={{height: '50px'}}
52+
width="276"
53+
height="81"
54+
decoding="async"
55+
style={{height: '50px', width: 'auto'}}
5456
/>
5557
</Link>
5658
</div>
@@ -136,11 +138,12 @@ export default class Navbar extends React.Component {
136138
)
137139
}
138140
<p className="button is-primary" style={{marginRight: 12}}>
139-
<PopupText
140-
text="Schedule a Demo"
141-
url="https://calendly.com/avnisupport-samanvayfoundation/product-demo-and-discussion"
142-
styles={{color:'white', fontWeight:'bold'}}
143-
/>
141+
<a
142+
href="https://calendly.com/avnisupport-samanvayfoundation/product-demo-and-discussion"
143+
style={{color:'white', fontWeight:'bold'}}
144+
>
145+
Schedule a Demo
146+
</a>
144147
</p>
145148
</div>
146149
</div>

src/components/Plan.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React from 'react';
2-
import {PopupText} from "react-calendly";
32

43
let step = function (title, text) {
54
return <div className="columns">
@@ -24,11 +23,12 @@ const Plan = ({}) => (
2423
<div className="column is-one-third"/>
2524
<div className="column is-one-third has-text-centered">
2625
<p className="button is-primary is-medium">
27-
<PopupText
28-
text="Schedule a Demo"
29-
url="https://calendly.com/avnisupport-samanvayfoundation/product-demo-and-discussion"
30-
styles={{color: 'white', fontWeight: 'bold'}}
31-
/>
26+
<a
27+
href="https://calendly.com/avnisupport-samanvayfoundation/product-demo-and-discussion"
28+
style={{color: 'white', fontWeight: 'bold'}}
29+
>
30+
Schedule a Demo
31+
</a>
3232
</p>
3333
</div>
3434
<div className="column is-one-third"/>

0 commit comments

Comments
 (0)