Created
November 26, 2018 08:57
-
-
Save columnistdc/b9b3a0b3c27bbdb4f6affaec5a594293 to your computer and use it in GitHub Desktop.
Matomo example
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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge" /> | |
<title>Document</title> | |
<!-- Matomo --> | |
<script type="text/javascript"> | |
(function() { | |
var info = { | |
platform: "PC", | |
}; | |
var obj = {}; | |
// Парсит урл и записывает в переменную obj инфо, полученную в урле | |
function parseUrl() { | |
var queryString = window.location.search.slice(1); | |
if (queryString) { | |
queryString = queryString.split("#")[0]; | |
var arr = queryString.split("&"); | |
for (var i = 0; i < arr.length; i++) { | |
var a = arr[i].split("="); | |
var paramNum = undefined; | |
var paramName = a[0].replace(/\[\d*\]/, function(v) { | |
paramNum = v.slice(1, -1); | |
return ""; | |
}); | |
var paramValue = typeof a[1] === "undefined" ? true : a[1]; | |
// paramName = paramName.toLowerCase(); | |
paramValue = paramValue.toLowerCase(); | |
if (obj[paramName]) { | |
if (typeof obj[paramName] === "string") { | |
obj[paramName] = [obj[paramName]]; | |
} | |
if (typeof paramNum === "undefined") { | |
obj[paramName].push(paramValue); | |
} else { | |
obj[paramName][paramNum] = paramValue; | |
} | |
} else { | |
obj[paramName] = paramValue; | |
} | |
} | |
} | |
} | |
parseUrl(); | |
// Отсылает статистику в matomo | |
function sensdStats() { | |
var _paq = _paq || []; | |
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */ | |
// _paq.push(["setCustomDimension", "1", obj[0]]); | |
// _paq.push(["setCustomDimension", "2", obj[1]]); | |
// _paq.push(["setCustomDimension", "3", obj[2]]); | |
_paq.push(["trackPageView"]); | |
_paq.push(["enableLinkTracking"]); | |
(function() { | |
var u = //some url | |
_paq.push(["setTrackerUrl", u + "piwik.php"]); | |
_paq.push(["setSiteId", "an id"]); | |
var d = document, | |
g = d.createElement("script"), | |
s = d.getElementsByTagName("script")[0]; | |
g.type = "text/javascript"; | |
g.async = true; | |
g.defer = true; | |
g.src = u + "piwik.js"; | |
s.parentNode.insertBefore(g, s); | |
})(); | |
} | |
sensdStats(); | |
function setFallbackLinkForAnfroid() { | |
return obj.appType ? androidLinks[obj.appType] : androidLinks.premier; | |
} | |
function setFallbackLinkForIos() { | |
return obj.appType ? appleLinks[obj.appType] : appleLinks.premier; | |
} | |
// DEBUG PART | |
if (obj.appType) alert("Тип приложения:" + obj.appType); | |
if (obj.adviceId) alert("Номер совета:" + obj.adviceId); | |
if (obj.channelName) alert("Название канала:" + obj.channelName); | |
// END OF DEBUG PART | |
// Проверяет тип устройства, с которого был вход | |
function checkForDeviceType() { | |
var device = navigator.platform; | |
if (navigator.platform === "iPhone") { | |
info.platform = "iPhone"; | |
} | |
if (navigator.platform === "iPad") { | |
info.platform = "iPad"; | |
} | |
if (navigator.platform === "iPod") { | |
info.platform = "iPod"; | |
} | |
if (navigator.platform === "Android") { | |
info.platform = "Android"; | |
} | |
} | |
var fallbackLink = | |
info.platform === "Android" | |
? setFallbackLinkForAnfroid() | |
: setFallbackLinkForIos(); | |
// Смотрит, установлено ли приложение и пытается в него редиректнуть | |
function checkForInstalledApps() { | |
if ( | |
info.platform === "iPhone" || | |
info.platform === "iPad" || | |
info.platform === "iPod" || | |
info.platform === "Android" | |
) { | |
redirectToApp(); | |
} else { | |
// some code | |
} | |
} | |
checkForDeviceType(); | |
checkForInstalledApps(); | |
})(); | |
</script> | |
<!-- End Matomo Code --> | |
</head> | |
<body> | |
<iframe style="display:none" height="0" width="0" id="loader"></iframe> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment