Skip to content

ServicePluginInterface

Defines an interface for analytics service plugins.

The 'track' access operation decides whether the service outputs on the current page. Check it through the service entity, with $service->access('track'), so entity access hooks apply too. The access result's cacheability is added to the page whether or not it's allowed.


  • Full name: \Drupal\analytics\Plugin\ServicePluginInterface
  • Parent interfaces: PluginInspectionInterface, DependentPluginInterface, ConfigurableInterface, PluginFormInterface, AccessibleInterface

Methods

setServiceId

Sets the current service config entity ID that is using this plugin.

public setServiceId(string $service_id): mixed

Parameters:

Parameter Type Description
$service_id string
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.


getLabel

Returns the label of the analytics service.

public getLabel(): string

Return Value:

The label of this analytics service.


hasMultipleInstances

Checks whether more than one analytics service uses this plugin.

public hasMultipleInstances(): bool

For example, to give each service's tracker its own name.

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[]>

List the hosts the service's script loads from and sends data to, as the service's CSP docs give them. They're added to the output wherever it's placed on the page, reduced to their origins (scheme, host and port), when the Content Security Policy module is installed.

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.