Skip to content

Commit 5440d3d

Browse files
committed
referrer-change
1 parent 562b78b commit 5440d3d

File tree

1 file changed

+34
-9
lines changed

1 file changed

+34
-9
lines changed

index_iframe.html

+34-9
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,47 @@
3131
<body>
3232
<iframe id="container" frameborder="0" allow="autoplay" allowfullscreen seamless="seamless" scrolling="no"></iframe>
3333
<script type="application/javascript">
34-
function getParentUrl() {
35-
var url = (window.location !== window.parent.location)
36-
? (document.referrer && document.referrer !== '')
37-
? document.referrer
38-
: document.location.href
39-
: document.location.href;
34+
35+
function getRequestParameters(url) {
36+
var res = {};
37+
var index = url.indexOf("?");
38+
if (index !== -1) {
39+
var query = url.substr(index + 1); // Drop the leading '?' / '#'
40+
var nameValues = query.split("&");
41+
42+
for (var i = 0; i < nameValues.length; i++) {
43+
var nameValue = nameValues[i].split("=");
44+
var name = nameValue[0];
45+
var value = nameValue[1];
46+
value = decodeURIComponent(value.replace(/\+/g, " "));
47+
res[name] = value;
48+
}
49+
}
50+
return res;
51+
}
52+
53+
function getReferrerUrl() {
54+
var parentUrl = document.location.href;
55+
56+
if (window.location !== window.parent.location && document.referrer) {
57+
parentUrl = document.referrer;
58+
}
59+
4060
if (document.referrer.indexOf('localhost') !== -1) {
41-
url = 'https://gamedistribution.com/';
61+
parentUrl = 'https://gamedistribution.com/';
4262
}
43-
return url;
63+
64+
var params = getRequestParameters(parentUrl);
65+
return params.gd_sdk_referrer_url || parentUrl;
4466
}
67+
4568
// Add the self-hosted game url as value of gameUrl.
4669
var gameUrl = 'http://example.io';
70+
4771
document
4872
.getElementById('container')
49-
.src = gameUrl + '?gd_sdk_referrer_url=' + getParentUrl();
73+
.src = gameUrl + '?gd_sdk_referrer_url=' + getReferrerUrl();
74+
5075
</script>
5176
</body>
5277
</html>

0 commit comments

Comments
 (0)