Last active
June 19, 2024 02:31
-
-
Save Brontojoris/193f7d03e9db3b3129d007df63e5f4ed to your computer and use it in GitHub Desktop.
ProxyMan Script for Adobe Analytics
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* This ProxyMan script finds the PageName and ActionName fields | |
from an Adobe Analytics Beacon and adds it to a custom header | |
so it's visable in the request list. | |
*/ | |
function onRequest(context, url, request) { | |
var reportSuite, reportMethod, pageName, customLink, osVersion, platform, appId, contentIcon = "", | |
activeStore, browseSortMethod, searchContext, searchId, searchSessionId, searchTypedKeyword, trolleyContext, | |
trolleyOrderId, products, productListItems, jsonData, | |
req = request, | |
convertToJSON = function(content) { | |
const urlSearchParams = new URLSearchParams(content); | |
const jsonObject = {}; | |
for (const [key, value] of urlSearchParams) { | |
jsonObject[key] = value; | |
} | |
return JSON.stringify(jsonObject); | |
}, | |
platform = function(){ | |
if(/^iOS/.test(osVersion)){return "🔹"} | |
if(/^Android/.test(osVersion)){return "🔸"} | |
else return "" | |
}; | |
try { | |
reportSuite = decodeURIComponent(req.path.split('/')[3] || "") | |
reportMethod = decodeURIComponent(req.path.split('/')[5] || "") | |
// Get the analytics page name or custom link so we can show it in a column | |
switch (req.method) { | |
case 'POST': | |
pageName = decodeURIComponent(req.body.pageName || "") | |
customLink = decodeURIComponent(req.body.action || req.body.pev2 || req.body.linkName || "") | |
if (req.body.action == "ADBINTERNAL:Lifecycle") { | |
customLink = req.body.internalaction | |
} | |
osVersion = decodeURIComponent(req.body.OSVersion || "") | |
appId = decodeURIComponent(req.body.AppID || "") | |
searchId = decodeURIComponent(req.body.searchId || "") | |
searchTypedKeyword = decodeURIComponent(req.body.searchTypedKeyword || "") | |
searchSessionId = decodeURIComponent(req.body.searchSessionId || "") | |
trolleyContext = decodeURIComponent(req.body.trolleyContext || "") | |
trolleyOrderId = decodeURIComponent(req.body.orderId || "") | |
searchContext = decodeURIComponent(req.body.searchContext || "") | |
browseSortMethod = decodeURIComponent(req.body.browseSortMethod || "") | |
products = decodeURIComponent(req.body.products || "") | |
productListItems = decodeURIComponent(req.body.productListItems || "") | |
activeStore = decodeURIComponent(req.body.activeStore || "") | |
if(reportMethod==="JS-2.23.0-LDQM"){ | |
request.headers['Content-Type'] = "application/json" | |
jsonData = JSON.parse(convertToJSON(req.body)) | |
pageName = jsonData["pageName"]||"" | |
customLink = jsonData["action"]||jsonData["pev2"]||jsonData["linkName"]||"" | |
//console.log({'pageName':pageName,'customLink':customLink,'reportMethod':reportMethod,'jsonData':jsonData}) | |
} | |
break; | |
case 'GET': | |
pageName = decodeURIComponent(req.queries.pageName || "") | |
customLink = decodeURIComponent(req.queries.pev2 || "") | |
break; | |
default: | |
// do the default thing | |
} | |
// Set pretty icons for analytics requests | |
if (req.headers["Host"] === "assets.adobedtm.com") { | |
contentIcon = " 🅾️" | |
} else if (req.headers["Host"].indexOf('.tt.omtrdc.net') > 0) { | |
contentIcon = " 🆎" | |
} else if (req.headers["Host"].indexOf('.sc.omtrdc.net') > 0) { | |
contentIcon = " 🅰️" | |
}else if (req.body.internalaction == "AnalyticsForTarget") { | |
// Hide Adobe Target Analytics Requests | |
contentIcon = " 🆎" | |
//req.method = "GET" | |
request.headers['Content-Type'] = "application/json" | |
//delete req.body; | |
} | |
} catch (err) { | |
console.log(err) | |
} | |
request.headers["ReportSuite"] = reportSuite; | |
request.headers["Page"] = (pageName !== "") ? pageName : req.path; | |
request.headers["Action"] = customLink; | |
request.headers["OSVersion"] = osVersion; | |
request.headers["AppID"] = platform()+" "+appId; | |
request.headers["Icon"] = contentIcon; | |
request.headers["SearchID"] = searchId; | |
request.headers["SearchKeyword"] = searchTypedKeyword; | |
request.headers["SearchSessionID"] = searchSessionId; | |
request.headers["TrolleyContext"] = trolleyContext; | |
request.headers["TrolleyOrderID"] = trolleyOrderId; | |
request.headers["ActiveStore"] = activeStore; | |
request.headers["SearchContext"] = searchContext; | |
request.headers["BrowseSortMethod"] = browseSortMethod; | |
var shorten = false; | |
if(shorten){ | |
// Shorten productListItems | |
if (productListItems.length > 250) { | |
request.body.productListItems = "[MODDED] "+productListItems.substring(0,250) | |
} | |
// Shorten &&products | |
if (products.length > 250) { | |
request.body.products = "[MODDED] " + products.substring(0,250) | |
} | |
} | |
return request; | |
} | |
function onResponse(context, url, request, response) { | |
try { | |
if (request.headers["Icon"]) { | |
response.headers["Icon"] = request.headers["Icon"]; | |
} | |
}catch{ | |
// meh | |
} | |
return response; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment