-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add Grafana Faro setup and made it configurable.
Release-As: 1.0.0
- Loading branch information
Showing
2 changed files
with
76 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,47 @@ | ||
<!-- place holder for code --> | ||
{{- if default true .Params.faro_analytics.analyze }} | ||
{{- $endpoint := site.Params.faro_analytics.endpoint }} | ||
{{- $name := site.Params.faro_analytics.name }} | ||
{{- $version := site.Params.faro_analytics.version }} | ||
{{- $environment := site.Params.faro_analytics.environment }} | ||
|
||
<script> | ||
console.info("Hugo Faro analytics module loaded") | ||
</script> | ||
(function () { | ||
var webSdkScript = document.createElement("script"); | ||
|
||
webSdkScript.src = | ||
"https://unpkg.com/@grafana/faro-web-sdk@^1.0.0/dist/bundle/faro-web-sdk.iife.js"; | ||
|
||
webSdkScript.onload = () => { | ||
window.GrafanaFaroWebSdk.initializeFaro({ | ||
url: "{{ $endpoint }}", | ||
app: { | ||
name: "{{ $name }}", | ||
version: "{{ $version }}", | ||
environment: "{{ $environment }}", | ||
}, | ||
}); | ||
|
||
|
||
// Load instrumentations at the onLoad event of the web-SDK and after the above configuration. | ||
// This is important because we need to ensure that the Web-SDK has been loaded and initialized before we add further instruments! | ||
var webTracingScript = document.createElement("script"); | ||
|
||
webTracingScript.src = | ||
"https://unpkg.com/@grafana/faro-web-tracing@^1.0.0/dist/bundle/faro-web-tracing.iife.js"; | ||
|
||
// Initialize, configure (if necessary) and add the the new instrumentation to the already loaded and configured Web-SDK. | ||
webTracingScript.onload = () => { | ||
window.GrafanaFaroWebSdk.faro.instrumentations.add( | ||
new window.GrafanaFaroWebTracing.TracingInstrumentation() | ||
); | ||
}; | ||
|
||
// Append the Web Tracing script script tag to the HTML page | ||
document.head.appendChild(webTracingScript); | ||
}; | ||
|
||
// Append the Web-SDK script script tag to the HTML page | ||
document.head.appendChild(webSdkScript); | ||
})(); | ||
</script> | ||
{{- end }} |