mirror of
https://github.com/jakejarvis/jarv.is.git
synced 2026-05-17 21:04:25 -04:00
fix AMP pixel (hopefully)
This commit is contained in:
@@ -181,7 +181,7 @@
|
|||||||
);
|
);
|
||||||
/** endif **/
|
/** endif **/
|
||||||
|
|
||||||
var sendBeaconText = "sendBeacon";
|
// var sendBeaconText = "sendBeacon";
|
||||||
|
|
||||||
var sendOnLeave = function (id, push) {
|
var sendOnLeave = function (id, push) {
|
||||||
var append = { type: "append", original_id: push ? id : lastPageId };
|
var append = { type: "append", original_id: push ? id : lastPageId };
|
||||||
|
|||||||
+15
-2
@@ -1,23 +1,35 @@
|
|||||||
const request = require("request");
|
const request = require("request");
|
||||||
|
|
||||||
exports.handler = function (event, context, callback) {
|
exports.handler = function (event, context, callback) {
|
||||||
|
// if triggered as an image without JS (i.e. from AMP pages) set `?noscript=true`
|
||||||
|
const noScript = event.queryStringParameters["noscript"] === "true";
|
||||||
|
|
||||||
|
// https://docs.simpleanalytics.com/without-javascript
|
||||||
|
const endpointPath = noScript ? "noscript.gif" : "simple.gif";
|
||||||
|
const endpointUrl = "https://queue.simpleanalyticscdn.com/" + endpointPath;
|
||||||
|
|
||||||
|
// pass these headers along to SA
|
||||||
const reqHeaders = {
|
const reqHeaders = {
|
||||||
referer: event.headers["referer"],
|
referer: event.headers["referer"],
|
||||||
"user-agent": event.headers["user-agent"],
|
"user-agent": event.headers["user-agent"],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// pass these URL parameters along to SA
|
||||||
const reqQuery = event.queryStringParameters;
|
const reqQuery = event.queryStringParameters;
|
||||||
reqQuery["ignore-dnt"] = true; // this isn't nefarious, we're not tracking in the first place!
|
reqQuery["ignore-dnt"] = "true"; // this isn't nefarious, we're not tracking in the first place!
|
||||||
|
|
||||||
const reqOptions = {
|
const reqOptions = {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
url: "https://queue.simpleanalyticscdn.com/simple.gif",
|
url: endpointUrl,
|
||||||
headers: reqHeaders,
|
headers: reqHeaders,
|
||||||
qs: reqQuery,
|
qs: reqQuery,
|
||||||
};
|
};
|
||||||
|
|
||||||
request(reqOptions, (error, response, body) => {
|
request(reqOptions, (error, response, body) => {
|
||||||
|
console.info(`Proxying ${event.queryStringParameters["type"]} to ${endpointPath} ...`);
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
|
// this indicates a function error, NOT an error returned from SA
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
|
||||||
callback(null, {
|
callback(null, {
|
||||||
@@ -26,6 +38,7 @@ exports.handler = function (event, context, callback) {
|
|||||||
} else {
|
} else {
|
||||||
console.info(response.statusCode, response.headers["simple-analytics-feedback"]);
|
console.info(response.statusCode, response.headers["simple-analytics-feedback"]);
|
||||||
|
|
||||||
|
// imitate the headers that would normally be sent back from SA's pixel
|
||||||
const resHeaders = {
|
const resHeaders = {
|
||||||
"content-type": response.headers["content-type"],
|
"content-type": response.headers["content-type"],
|
||||||
"cache-control": "no-cache, no-store, must-revalidate",
|
"cache-control": "no-cache, no-store, must-revalidate",
|
||||||
|
|||||||
@@ -257,7 +257,7 @@
|
|||||||
|
|
||||||
{{ if eq hugo.Environment "production" }}
|
{{ if eq hugo.Environment "production" }}
|
||||||
<!-- https://docs.simpleanalytics.com/without-javascript -->
|
<!-- https://docs.simpleanalytics.com/without-javascript -->
|
||||||
<amp-pixel src="{{ "api/send_view" | absURL }}?hostname=CANONICAL_HOSTNAME&path=CANONICAL_PATH&referrer=DOCUMENT_REFERRER&https=true&ua=USER_AGENT&width=VIEWPORT_WIDTH&type=pageview" layout="nodisplay"></amp-pixel>
|
<amp-pixel src="{{ "api/send_view" | absURL }}?noscript=true&type=pageview&hostname=CANONICAL_HOSTNAME&path=CANONICAL_PATH&referrer=DOCUMENT_REFERRER&https=true&ua=USER_AGENT&width=VIEWPORT_WIDTH" layout="nodisplay"></amp-pixel>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Reference in New Issue
Block a user