Last active
October 25, 2018 01:37
-
-
Save ayakix/a77f532a632b0cdb0993eb47ce92d708 to your computer and use it in GitHub Desktop.
AWS GWのモック機能とGoogle Analyticsを使って任意のWebページのアクセスログを簡単に取るやつ
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
<!-- | |
Ex.) | |
Target url: https://google.co.jp?hoge=abc&fuga=def | |
Campaign url: https://xxxxx.execute-api.xxxx.amazonaws.com/xxx?url=https%3A%2F%2Fwww.google.co.jp%3Fhoge%3Dabc%26fuga%3Ddef&ua=UA-xxxxxx-x&utm_source=source&utm_medium=medium&utm_campaign=campaign&utm_term=term&utm_content=content | |
--> | |
<!DOCTYPE html> | |
<head> | |
<meta charset="utf-8"> | |
</head> | |
<!-- Global site tag (gtag.js) - Google Analytics --> | |
<script async src="https://www.googletagmanager.com/gtag/js?id=$input.params('ua')"></script> | |
<script> | |
window.dataLayer = window.dataLayer || []; | |
function gtag(){dataLayer.push(arguments);} | |
gtag('js', new Date()); | |
gtag('config', "$input.params('ua')"); | |
// リダイレクト(リファラの持ち越しとかには対応してない) | |
location.href = decodeURIComponent("$input.params('url')"); | |
</script> | |
</html> |
Author
ayakix
commented
Aug 29, 2018
<!DOCTYPE html>
<head>
<meta charset="utf-8">
</head>
<script>
window.query = location.search.replace(/^\?/, '').split('&').reduce(function (acc, p) {
var p = p.split('=');
acc[p[0]] = p[1];
return acc;
}, {})
</script>
<script>
var script = document.createElement('script');
script.setAttribute('src', 'https://www.googletagmanager.com/gtag/js?id=' + query.ua);
document.head.appendChild(script);
window.dataLayer = window.dataLayer || [];
function gtag(){ dataLayer.push(arguments); }
gtag('js', new Date());
gtag('config', query.ua);
var i = setInterval(function() {
if (window.dataLayer.filter(function(e) { return e.event === 'gtm.load' }).length > 0) {
clearInterval(i);
location.href = decodeURIComponent(query.url);
}
}, 500)
</script>
</html>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment