Skip to content

Commit

Permalink
feat(www): add performance metrics plugin (#13472)
Browse files Browse the repository at this point in the history
* feat(www): add firebase-perf to www

* chore: use createElement instead of JSX

* chore: fix issue

* chore: rename plugin
  • Loading branch information
DSchau authored Apr 18, 2019
1 parent b0cdba5 commit 6150722
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
6 changes: 6 additions & 0 deletions www/gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,12 @@ module.exports = {
},
},
`gatsby-plugin-offline`,
{
resolve: `gatsby-plugin-perf-metrics`,
options: {
appId: `1:216044356421:web:92185d5e24b3a2a1`,
},
},
`gatsby-transformer-csv`,
`gatsby-plugin-twitter`,
`gatsby-plugin-react-helmet`,
Expand Down
27 changes: 27 additions & 0 deletions www/plugins/gatsby-plugin-perf-metrics/gatsby-ssr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const React = require(`react`)

exports.onRenderBody = function onRenderBody(
{ setPostBodyComponents, reporter },
{ appId }
) {
if (!appId) {
reporter.warn(`An appId is required to use gatsby-plugin-perf-metrics`)
return
}

setPostBodyComponents([
React.createElement(`script`, {
key: `gatsby-plugin-perf-metrics`,
dangerouslySetInnerHTML: {
__html: `
(function(sa,gai){function load(f,c){var a=document.createElement('script');
a.async=1;a.src=f;a.onload=c;var s=document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(a,s);}load(sa);window.onload = function() {firebase.initializeApp({appId:gai}).performance();};
})('https://earlymonitoring.firebaseapp.com/index.min.js', ${JSON.stringify(
appId
)});
`,
},
}),
])
}
1 change: 1 addition & 0 deletions www/plugins/gatsby-plugin-perf-metrics/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// noop
3 changes: 3 additions & 0 deletions www/plugins/gatsby-plugin-perf-metrics/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "gatsby-plugin-perf-metrics"
}

0 comments on commit 6150722

Please sign in to comment.