Community Plugin: This plugin is developed, tested, and maintained by a third-party contributor.
This plugin logs your Kong gateway transactions to Google Analytics. This plugin is a modification of the Kong HTTP Log plugin.
Installation & Usage
A tutorial, installation steps, and further information can be found at https://github.com/yesinteractive/kong-log-google.
Configuration Reference
This plugin is compatible with DB-less mode.
Fully compatible with DB and DB-less (K8s, Declarative) Kong implementations.
Example plugin configuration
Enable on a service
Enable on a route
Enable globally
The following examples provide some typical configurations for enabling
the kong-log-google
plugin on a
service.
Admin API
Kubernetes
Declarative (YAML)
Make the following request:
curl -X POST http://localhost:8001/services/SERVICE_NAME|SERVICE_ID/plugins \
--data "name=kong-log-google" \
--data "config.tid=UA-XXXX-Y" \
--data "config.cid=555"
Replace SERVICE_NAME|SERVICE_ID
with the id
or name
of the service that this plugin configuration will target.
First, create a KongPlugin
resource:
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
name: kong-log-google-example
config:
tid: UA-XXXX-Y
cid: 555
plugin: kong-log-google
Next, apply the KongPlugin resource to a
service by annotating the
service as follows:
apiVersion: v1
kind: Service
metadata:
name: SERVICE_NAME|SERVICE_ID
labels:
app: SERVICE_NAME|SERVICE_ID
annotations:
konghq.com/plugins: kong-log-google-example
spec:
ports:
- port: 80
targetPort: 80
protocol: TCP
name: SERVICE_NAME|SERVICE_ID
selector:
app: SERVICE_NAME|SERVICE_ID
Replace SERVICE_NAME|SERVICE_ID
with the id
or name
of the service that this plugin configuration will target.
Note: The KongPlugin resource only needs to be defined once
and can be applied to any service, consumer, or route in the namespace. If you
want the plugin to be available cluster-wide, create the resource as a
KongClusterPlugin
instead of KongPlugin
.
Add this section to your declarative configuration file:
plugins:
- name: kong-log-google
service: SERVICE_NAME|SERVICE_ID
config:
tid: UA-XXXX-Y
cid: 555
Replace SERVICE_NAME|SERVICE_ID
with the id
or name
of the service that this plugin configuration will target.
The following examples provide some typical configurations for enabling
the kong-log-google
plugin on a
route.
Admin API
Kubernetes
Declarative (YAML)
Make the following request:
curl -X POST http://localhost:8001/routes/ROUTE_NAME|ROUTE_ID/plugins \
--data "name=kong-log-google" \
--data "config.tid=UA-XXXX-Y" \
--data "config.cid=555"
Replace ROUTE_NAME|ROUTE_ID
with the id
or name
of the route that this plugin configuration will target.
First, create a KongPlugin
resource:
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
name: kong-log-google-example
config:
tid: UA-XXXX-Y
cid: 555
plugin: kong-log-google
Then, apply it to an ingress (route or routes)
by annotating the ingress as follows:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: ROUTE_NAME|ROUTE_ID
annotations:
kubernetes.io/ingress.class: kong
konghq.com/plugins: kong-log-google-example
spec:
rules:
- host: examplehostname.com
http:
paths:
- path: /bar
backend:
service:
name: echo
port:
number: 80
Replace ROUTE_NAME|ROUTE_ID
with the id
or name
of the route that this plugin configuration will target.
Note: The KongPlugin resource only needs to be defined once
and can be applied to any service, consumer, or route in the namespace. If you
want the plugin to be available cluster-wide, create the resource as a
KongClusterPlugin
instead of KongPlugin
.
Add this section to your declarative configuration file:
plugins:
- name: kong-log-google
route: ROUTE_NAME
config:
tid: UA-XXXX-Y
cid: 555
Replace ROUTE_NAME|ROUTE_ID
with the id
or name
of the route that this plugin configuration
will target.
A plugin which is not associated to any service, route, or consumer is
considered global, and will be run on every request. Read the
Plugin Reference and the Plugin Precedence
sections for more information.
The following examples provide some typical configurations for enabling
the kong-log-google
plugin globally.
Admin API
Kubernetes
Declarative (YAML)
Make the following request:
curl -X POST http://localhost:8001/plugins/ \
--data "name=kong-log-google" \
--data "config.tid=UA-XXXX-Y" \
--data "config.cid=555"
Create a KongClusterPlugin
resource and label it as global:
apiVersion: configuration.konghq.com/v1
kind: KongClusterPlugin
metadata:
name: <global-kong-log-google>
annotations:
kubernetes.io/ingress.class: kong
labels:
global: \"true\"
config:
tid: UA-XXXX-Y
cid: 555
plugin: kong-log-google
Add a plugins
entry in the declarative
configuration file:
plugins:
- name: kong-log-google
config:
tid: UA-XXXX-Y
cid: 555
Parameters
Here's a list of all the parameters which can be used in this plugin's configuration:
Form Parameter |
Description |
name
required
Type: string |
The name of the plugin, in this case kong-log-google . |
service.name or service.id
Type: string |
The name or ID of the service the plugin targets.
Set one of these parameters if adding the plugin to a service through the top-level /plugins endpoint.
Not required if using /services/SERVICE_NAME|SERVICE_ID/plugins . |
route.name or route.id
Type: string |
The name or ID of the route the plugin targets.
Set one of these parameters if adding the plugin to a route through the top-level /plugins endpoint.
Not required if using /routes/ROUTE_NAME|ROUTE_ID/plugins . |
enabled
Type: boolean
Default value: true |
Whether this plugin will be applied. |
config.tid
required
Default value: UA-XXXX-Y
|
The tracking ID / property ID. The format is UA-XXXX-Y. All collected data is associated by this ID.
|
config.cid
required
Default value: 555
|
Client ID. This allows you to set and identify metrics in Google Analytics by a custom client ID.
|