Client-side v.s. Server-side tagging
Traditional client-side tracking executes tags and scripts within the user's browser,
whereas, SST shifts the data processing load to the server level.
Server-side tagging
web container -> server container
The server container accepts all HTTP requests from the web container.
In the server container,
you can set up processing rules before sending data to
your Google products or third-party endpoints.
* Reduces the client processing load, improving website and app performance
* mitigate issues caused by ad-blockers (google-analytics.com)
* Enables you to screen and modify incoming requests to ensure data privacy
* Enables you to validate and normalize data, improving data quality
Setup server-side tracking Step
1. creating a Google Tag Manager account
2. nginx proxy (SSL by Certbot)
3. a dedicated container
4. 修改頁面的 gtag.js
Step 1
到後台 https://tagmanager.google.com
"Create Account" # GTM Account
Target Platform: Select “Server” as the target platform. # Web 也須要有
選 "Manually provision tagging server"
獲得 CONTAINER_CONFIG
Set the Correct URL
Step 2
gtm.example.com.vhost
server { listen 80; server_name gtm.example.com; location / { log_not_found off; access_log off; return 301 https://tapi.chatslink.ai$request_uri; } } server { listen 443 ssl http2; server_name gtm.example.com; #### Lets Encrypt ACME Challenge location ^~ /.well-known/acme-challenge/ { allow all; root /var/lib/letsencrypt/; default_type "text/plain"; try_files $uri =404; } ssl_certificate /etc/letsencrypt/live/gtm.example.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/gtm.example.com/privkey.pem; #### Proxy to docker backend with GTM #### location / { proxy_pass http://localhost:8080; } }
Step 3
建立 gtm-live container. 它是一個 Node.js server
Version
- 2.3.0 (February 20, 2024)
行 Docker
IMG='gcr.io/cloud-tagging-10302018/gtm-cloud-image:stable' podman run -d --name gtm-live -p 8080:8080 \ -e CONTAINER_CONFIG='YOUR_CONTAINER_CONFIG_TOKEN' $IMG
Check
curl http://localhost:8080/healthz
ok
Step 4