GoatCounter
GoatCounter analytics service plugin.
Loads GoatCounter's count.js from inline JavaScript, so the Do Not Track setting applies to it.
A site can have only one GoatCounter service: count.js sends every pageview to the endpoint of the first script on the page with data-goatcounter.
The service's data is GoatCounter's window.goatcounter object, set before count.js loads. Other modules can add to it, such as a page's path or title, with hook_analytics_SERVICE_ID_data_alter() or hook_analytics_goatcounter_data_alter().
- Full name:
\Drupal\analytics\Plugin\AnalyticsService\GoatCounter - Parent class:
\Drupal\analytics\Plugin\ServicePluginBase
See Also:
- https://www.goatcounter.com/help/start
- https://www.goatcounter.com/help/js
Constants
| Constant | Visibility | Type | Value |
|---|---|---|---|
SETTINGS |
protected | array | ['no_events', 'allow_frame', 'allow_local'] |
Properties
requestStack
The request stack.
protected \Symfony\Component\HttpFoundation\RequestStack $requestStack
Methods
create
{@inheritdoc}
public static create(\Symfony\Component\DependencyInjection\ContainerInterface $container, array $configuration, mixed $plugin_id, mixed $plugin_definition): static
- This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$container |
\Symfony\Component\DependencyInjection\ContainerInterface | |
$configuration |
array | |
$plugin_id |
mixed | |
$plugin_definition |
mixed |
defaultConfiguration
{@inheritdoc}
public defaultConfiguration(): array
buildConfigurationForm
{@inheritdoc}
public buildConfigurationForm(array $form, \Drupal\Core\Form\FormStateInterface $form_state): array
Parameters:
| Parameter | Type | Description |
|---|---|---|
$form |
array | |
$form_state |
\Drupal\Core\Form\FormStateInterface |
defaultData
{@inheritdoc}
public defaultData(): array
The settings that are turned on, keyed as count.js expects them.
getOutput
Returns the output of the analytics service.
public getOutput(): array
Return Value:
A structured, renderable array.
getPixelPath
Gets the path the tracking pixel counts, as count.js would send it.
protected getPixelPath(): string
Return Value:
The request's path and query string, after the domain when the domain_in_path setting is on.
See Also:
- https://www.goatcounter.com/help/pixel
getCspSources
Gets the Content Security Policy sources the service's output needs.
public getCspSources(): array<string,string[]>
GoatCounter's count.js, and the pageviews it sends with navigator.sendBeacon() or the tracking pixel.
Return Value:
URLs keyed by directive, such as ['script-src' => ['https://gc.zgo.at']].
See Also:
- https://www.goatcounter.com/help/csp
- https://www.goatcounter.com/help/pixel
Inherited methods
setServiceId
Sets the current service config entity ID that is using this plugin.
public setServiceId(mixed $service_id): mixed
Parameters:
| Parameter | Type | Description |
|---|---|---|
$service_id |
mixed | |
| The service config entity ID. |
getServiceId
Gets the current service config entity ID that is using this plugin.
public getServiceId(): string
Return Value:
The service config entity ID.
__construct
{@inheritdoc}
public __construct(array $configuration, mixed $plugin_id, mixed $plugin_definition): mixed
Parameters:
| Parameter | Type | Description |
|---|---|---|
$configuration |
array | |
$plugin_id |
mixed | |
$plugin_definition |
mixed |
create
{@inheritdoc}
public static create(\Symfony\Component\DependencyInjection\ContainerInterface $container, array $configuration, mixed $plugin_id, mixed $plugin_definition): static
- This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$container |
\Symfony\Component\DependencyInjection\ContainerInterface | |
$configuration |
array | |
$plugin_id |
mixed | |
$plugin_definition |
mixed |
getLabel
Returns the label of the analytics service.
public getLabel(): string
Return Value:
The label of this analytics service.
access
{@inheritdoc}
public access(mixed $operation, ?\Drupal\Core\Session\AccountInterface $account = null, mixed $return_as_object = false): mixed
Parameters:
| Parameter | Type | Description |
|---|---|---|
$operation |
mixed | |
$account |
?\Drupal\Core\Session\AccountInterface | |
$return_as_object |
mixed |
hasMultipleInstances
Checks whether more than one analytics service uses this plugin.
public hasMultipleInstances(): bool
Return Value:
TRUE if two or more analytics services use this plugin.
getOutput
Returns the output of the analytics service.
public getOutput(): array
Return Value:
A structured, renderable array.
getCspSources
Gets the Content Security Policy sources the service's output needs.
public getCspSources(): array<string,string[]>
Return Value:
URLs keyed by directive, such as ['script-src' => ['https://gc.zgo.at']].
getCacheableUrls
Gets the URLs of the service's external files to cache locally.
public getCacheableUrls(): array
Return Value:
A list of URLs.
getCacheContexts
{@inheritdoc}
public getCacheContexts(): array
The output's cacheability. Plugins that vary their output by something other than their configuration add it here.
getCacheTags
{@inheritdoc}
public getCacheTags(): array
getCacheMaxAge
{@inheritdoc}
public getCacheMaxAge(): int
setConfiguration
{@inheritdoc}
public setConfiguration(array $configuration): mixed
Parameters:
| Parameter | Type | Description |
|---|---|---|
$configuration |
array |
getConfiguration
{@inheritdoc}
public getConfiguration(): array
defaultConfiguration
{@inheritdoc}
public defaultConfiguration(): array
buildConfigurationForm
{@inheritdoc}
public buildConfigurationForm(array $form, \Drupal\Core\Form\FormStateInterface $form_state): array
Parameters:
| Parameter | Type | Description |
|---|---|---|
$form |
array | |
$form_state |
\Drupal\Core\Form\FormStateInterface |
validateConfigurationForm
{@inheritdoc}
public validateConfigurationForm(array& $form, \Drupal\Core\Form\FormStateInterface $form_state): mixed
Parameters:
| Parameter | Type | Description |
|---|---|---|
$form |
array | |
$form_state |
\Drupal\Core\Form\FormStateInterface |
submitConfigurationForm
{@inheritdoc}
public submitConfigurationForm(array& $form, \Drupal\Core\Form\FormStateInterface $form_state): mixed
Parameters:
| Parameter | Type | Description |
|---|---|---|
$form |
array | |
$form_state |
\Drupal\Core\Form\FormStateInterface |
calculateDependencies
{@inheritdoc}
public calculateDependencies(): array
defaultData
Gets the service's default data, before it's altered.
public defaultData(): array
- This method is abstract. Return Value:
The default data.
getData
Gets the service's data, altered by other modules.
public getData(\Drupal\Core\Cache\RefinableCacheableDependencyInterface|null $cacheability = null): array
Invokes hook_analytics_SERVICE_ID_data_alter(), and also hook_analytics_PLUGIN_ID_data_alter() when the plugin ID differs.
Parameters:
| Parameter | Type | Description |
|---|---|---|
$cacheability |
\Drupal\Core\Cache\RefinableCacheableDependencyInterface|null | |
| (optional) Collects the cacheability the alter hooks add, for the caller | ||
| to apply to the output. |
Return Value:
The altered data.
moduleHandler
Wraps the module handler.
protected moduleHandler(): \Drupal\Core\Extension\ModuleHandlerInterface
- This method is abstract. Return Value:
The module handler.