Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add init faro script and inject #1491

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions common/browser_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ func NewBrowserContext(
if err := b.AddInitScript(js.WebVitalInitScript); err != nil {
return nil, fmt.Errorf("adding web vital init script to new browser context: %w", err)
}
if err := b.AddInitScript(js.FaroInitScript); err != nil {
return nil, fmt.Errorf("adding faro init script to new browser context: %w", err)
}

return &b, nil
}
Expand Down
3 changes: 3 additions & 0 deletions common/js/embedded_scripts.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ var WebVitalIIFEScript string
//
//go:embed web_vital_init.js
var WebVitalInitScript string

//go:embed faro.js
var FaroInitScript string
28 changes: 28 additions & 0 deletions common/js/faro.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
function faroInit () {
// Create a script tag for loading the library
var script = document.createElement('script');

// Initialize the Web SDK at the onLoad event of the script element so it is called when the library is loaded.
script.onload = () => {
window.GrafanaFaroWebSdk.initializeFaro({
// Mandatory, the URL of the Grafana Cloud collector with embedded application key.
// Copy from the configuration page of your application in Grafana.
url: 'https://faro-collector-dev-us-central-0.grafana-dev.net/collect/f92eca480377a3a757f5189f4292ca74',
app: {
name: 'test',
version: '1.0.0',
environment: 'production'
},
});
};

// Set the source of the script tag to the CDN
script.src = 'https://unpkg.com/@grafana/faro-web-sdk@^1.0.0-beta/dist/bundle/faro-web-sdk.iife.js';

document.addEventListener("DOMContentLoaded", function() {
// Append the script tag to the head of the HTML document
document.head.appendChild(script);
});
}

faroInit();
Loading