Skip to content

Commit

Permalink
Merge pull request #32 from getmentor/faro
Browse files Browse the repository at this point in the history
Introduce Grafana Faro
  • Loading branch information
glamcoder authored Mar 14, 2024
2 parents 9484192 + bdcc046 commit db2065e
Show file tree
Hide file tree
Showing 8 changed files with 431 additions and 83 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
"@fortawesome/free-regular-svg-icons": "^6.1.1",
"@fortawesome/free-solid-svg-icons": "^6.1.1",
"@fortawesome/react-fontawesome": "^0.2.0",
"@grafana/faro-web-sdk": "^1.4.2",
"@grafana/faro-web-tracing": "^1.4.2",
"@headlessui/react": "^1.6.6",
"@microsoft/applicationinsights-react-js": "^3.4.0",
"@microsoft/applicationinsights-web": "^2.8.7",
Expand Down
22 changes: 22 additions & 0 deletions src/lib/faro.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { getWebInstrumentations, initializeFaro } from '@grafana/faro-web-sdk'
//import { TracingInstrumentation } from '@grafana/faro-web-tracing';

export const initFaro = () => {
var faro = initializeFaro({
url: process.env.NEXT_PUBLIC_FARO_ENDPOINT + process.env.NEXT_PUBLIC_FARO_INSTRUMENTATION_KEY,
app: {
name: 'getmentor_dev',
version: '1.0.0',
environment: 'production',
},

instrumentations: [
// Mandatory, overwriting the instrumentations array would cause the default instrumentations to be omitted
...getWebInstrumentations(),

// Initialization of the tracing package.
// This packages is optional because it increases the bundle size noticeably. Only add it if you want tracing data.
//new TracingInstrumentation(),
],
})
}
5 changes: 5 additions & 0 deletions src/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import analytics from '../lib/analytics'
import MetaHeader from '../components/MetaHeader'
import seo from '../config/seo'
import VisibilitySensor from 'react-visibility-sensor'
import { initFaro } from '../lib/faro'

export async function getServerSideProps(context) {
const pageMentors = await getAllMentors({ onlyVisible: true })
Expand Down Expand Up @@ -50,6 +51,10 @@ function onSponsorsShown(isVisible) {
}

export default function Home({ pageMentors }) {
useEffect(() => {
initFaro()
})

const [mentors, searchInput, hasMoreMentors, setSearchInput, showMoreMentors, appliedFilters] =
useMentors(pageMentors)

Expand Down
5 changes: 5 additions & 0 deletions src/pages/mentor/[slug]/contact.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import Image from 'next/image'
import { InlineWidget } from 'react-calendly'
import Koalendar from '../../../components/Koalendar'
import { imageLoader } from '../../../lib/azure-image-loader'
import { initFaro } from '../../../lib/faro'

export async function getServerSideProps(context) {
const mentor = await getOneMentorBySlug(context.params.slug)
Expand All @@ -31,6 +32,10 @@ export async function getServerSideProps(context) {
}

export default function OrderMentor({ mentor }) {
useEffect(() => {
initFaro()
})

const [readyStatus, setReadyStatus] = useState('')
const [formData, setFormData] = useState()

Expand Down
5 changes: 5 additions & 0 deletions src/pages/mentor/[slug]/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { htmlContent } from '../../../lib/html-content'
import { polyfill } from 'interweave-ssr'
import pluralize from '../../../lib/pluralize'
import { imageLoader } from '../../../lib/azure-image-loader'
import { initFaro } from '../../../lib/faro'

// This enables rendering profile HTML on server
polyfill()
Expand All @@ -39,6 +40,10 @@ export default function Mentor(props) {
const mentor = props.mentor
const title = mentor.name + ' | ' + seo.title

useEffect(() => {
initFaro()
})

useEffect(() => {
analytics.event('View Mentor Page', {
'Mentor Id': mentor.id,
Expand Down
5 changes: 5 additions & 0 deletions src/pages/ontico.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import MentorsSearch from '../components/MentorsSearch'
import MetaHeader from '../components/MetaHeader'
import analytics from '../lib/analytics'
import { useEffect } from 'react'
import { initFaro } from '../lib/faro'

export async function getServerSideProps(context) {
const allMentors = await getAllMentors({ onlyVisible: true })
Expand Down Expand Up @@ -66,6 +67,10 @@ function Feature({ title, text, imageUrl }) {
}

export default function Ontico({ pageMentors }) {
useEffect(() => {
initFaro()
})

const [mentors, searchInput, hasMoreMentors, setSearchInput, showMoreMentors, appliedFilters] =
useMentors(pageMentors)

Expand Down
5 changes: 5 additions & 0 deletions src/pages/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Notification from '../components/Notification'
import Error from 'next/error'
import analytics from '../lib/analytics'
import Link from 'next/link'
import { initFaro } from '../lib/faro'

export async function getServerSideProps(context) {
context.query.id = parseInt(context.query.id, 10)
Expand All @@ -37,6 +38,10 @@ export async function getServerSideProps(context) {
}

export default function Profile({ errorCode, mentor }) {
useEffect(() => {
initFaro()
})

useEffect(() => {
if (mentor) {
analytics.event('Open Profile', {
Expand Down
Loading

0 comments on commit db2065e

Please sign in to comment.