-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction.js
More file actions
29 lines (24 loc) · 816 Bytes
/
Copy pathfunction.js
File metadata and controls
29 lines (24 loc) · 816 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import cf from "cloudfront";
// Configuration - Replace with your Google Tag Gateway domain
const GOOGLE_TAG_GATEWAY_DOMAIN = "G-12345.fps.goog";
function handler(event) {
var request = event.request;
var uri = request.uri;
// Check if request is for /metrics/* path
if (uri.startsWith("/metrics/")) {
var country = request.headers["cloudfront-viewer-country"]
? request.headers["cloudfront-viewer-country"].value
: "US";
var region = request.headers["cloudfront-viewer-country-region"]
? request.headers["cloudfront-viewer-country-region"].value
: "CA";
cf.updateRequestOrigin({
domainName: GOOGLE_TAG_GATEWAY_DOMAIN,
customHeaders: {
"x-forwarded-country": country,
"x-forwarded-region": region,
},
});
}
return request;
}