Skip to content

Commit 146d33b

Browse files
susytidettman
authored andcommitted
Adds an id parameter (#3107)
* adds jcsi param * adds try catch
1 parent 0e180e3 commit 146d33b

File tree

1 file changed

+72
-1
lines changed

1 file changed

+72
-1
lines changed

modules/gumgumBidAdapter.js

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,76 @@ const TIME_TO_LIVE = 60
1313
let browserParams = {};
1414
let pageViewId = null
1515

16+
function hasTopAccess () {
17+
var hasTopAccess = false
18+
try { hasTopAccess = !!top.document } catch (e) {}
19+
return hasTopAccess
20+
}
21+
22+
function isInSafeFrame (windowRef) {
23+
const w = windowRef || window
24+
if (w.$sf) return w.$sf
25+
else if (hasTopAccess() && w !== top) return isInSafeFrame(w.parent)
26+
return null
27+
}
28+
29+
function getGoogleTag (windowRef) {
30+
try {
31+
const w = windowRef || window
32+
var GOOGLETAG = null
33+
if ('googletag' in w) {
34+
GOOGLETAG = w.googletag
35+
} else if (w !== top) {
36+
GOOGLETAG = getGoogleTag(w.parent)
37+
}
38+
return GOOGLETAG
39+
} catch (error) {
40+
utils.logError('Error getting googletag ', error)
41+
return null
42+
}
43+
}
44+
45+
function getAMPContext (windowRef) {
46+
const w = windowRef || window
47+
var context = null
48+
var nameJSON = null
49+
if (utils.isPlainObject(w.context)) {
50+
context = w.context
51+
} else {
52+
try {
53+
nameJSON = JSON.parse(w.name || null)
54+
} catch (error) {
55+
utils.logError('Error getting w.name', error)
56+
}
57+
if (utils.isPlainObject(nameJSON)) {
58+
context = nameJSON._context || (nameJSON.attributes ? nameJSON.attributes._context : null)
59+
}
60+
if (utils.isPlainObject(w.AMP_CONTEXT_DATA)) {
61+
context = w.AMP_CONTEXT_DATA
62+
}
63+
}
64+
return context
65+
}
66+
67+
function getJCSI () {
68+
const entrypointOffset = 7
69+
const inFrame = (window.top && window.top !== window)
70+
const frameType = (!inFrame ? 1 : (isInSafeFrame() ? 2 : (hasTopAccess() ? 3 : 4)))
71+
const context = []
72+
if (getAMPContext()) {
73+
context.push(1)
74+
}
75+
if (getGoogleTag()) {
76+
context.push(2)
77+
}
78+
const jcsi = {
79+
ep: entrypointOffset,
80+
fc: frameType,
81+
ctx: context
82+
}
83+
return JSON.stringify(jcsi)
84+
}
85+
1686
// TODO: potential 0 values for browserParams sent to ad server
1787
function _getBrowserParams() {
1888
let topWindow
@@ -40,7 +110,8 @@ function _getBrowserParams() {
40110
sh: topScreen.height,
41111
pu: topUrl,
42112
ce: utils.cookiesAreEnabled(),
43-
dpr: topWindow.devicePixelRatio || 1
113+
dpr: topWindow.devicePixelRatio || 1,
114+
jcsi: getJCSI()
44115
}
45116
ggad = (topUrl.match(/#ggad=(\w+)$/) || [0, 0])[1]
46117
if (ggad) {

0 commit comments

Comments
 (0)