Go SDK
12. Dec, 2020The Go SDK can be found on GitHub.
Installation
|
|
Create a Client
To use the API, you need to create a client on the settings page first and use the client ID, the secret, and hostname to set up the SDK.
|
|
From here on we can make API calls through the client
. It will automatically update the access token using the credentials you provided. The last parameter is optional and can be set to nil.
Send a Page Hit
To monitor your website traffic, you need to send hits to Pirsch. This is done by calling the Hit
method from a handler function.
|
|
Hit
takes the http.Request
object as an input and sends all relevant data to Pirsch. This is done synchronously, so you might want to do it asynchronously by calling it using the go
command, like in the example above. Note that the handler above accepts all requests made by a client and will therefore lead to a lot of different paths being tracked. Usually you would make sure that only the page itself gets monitored by checking the requested path.
|
|
You can send a hit whenever you want. If you have a page with dynamic content for example, you can check if the content was found and send a hit in that case, or otherwise ignore it.