Skip to content

Commit 552f6fc

Browse files
Susan ThaiSusan Thai
Susan Thai
authored and
Susan Thai
committed
adds jcsi param
1 parent fa78634 commit 552f6fc

File tree

1 file changed

+67
-1
lines changed

1 file changed

+67
-1
lines changed

modules/gumgumBidAdapter.js

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,71 @@ 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 () {
23+
if (window.$sf) return window.$sf
24+
else if (hasTopAccess() && window !== top) return isInSafeFrame(window.parent)
25+
return null
26+
}
27+
28+
function getGoogleTag (windowRef) {
29+
try {
30+
const w = windowRef || window
31+
var GOOGLETAG = null
32+
if ('googletag' in w) {
33+
GOOGLETAG = w.googletag
34+
} else if (w !== top) {
35+
GOOGLETAG = getGoogleTag(w.parent)
36+
}
37+
return GOOGLETAG
38+
} catch (error) {
39+
utils.logError('Error getting googletag ', error)
40+
return null
41+
}
42+
}
43+
44+
function getAMPContext (windowRef) {
45+
const w = windowRef || window
46+
var context = null
47+
var nameJSON = null
48+
if (utils.isPlainObject(w.context)) {
49+
context = w.context
50+
} else {
51+
nameJSON = JSON.parse(w.name)
52+
if (utils.isPlainObject(nameJSON)) {
53+
context = nameJSON._context || (nameJSON.attributes ? nameJSON.attributes._context : null)
54+
}
55+
if (utils.isPlainObject(w.AMP_CONTEXT_DATA)) {
56+
context = w.AMP_CONTEXT_DATA
57+
}
58+
}
59+
return context
60+
}
61+
62+
function getJCSI () {
63+
const entrypointOffset = 7
64+
const inFrame = (window.top && window.top !== window)
65+
const frameType = (!inFrame ? 1 : (isInSafeFrame() ? 2 : (hasTopAccess() ? 3 : 4)))
66+
const context = []
67+
if (getAMPContext()) {
68+
context.push(1)
69+
}
70+
if (getGoogleTag()) {
71+
context.push(2)
72+
}
73+
const jcsi = {
74+
ep: entrypointOffset,
75+
fc: frameType,
76+
ctx: context
77+
}
78+
return JSON.stringify(jcsi)
79+
}
80+
1681
// TODO: potential 0 values for browserParams sent to ad server
1782
function _getBrowserParams() {
1883
let topWindow
@@ -40,7 +105,8 @@ function _getBrowserParams() {
40105
sh: topScreen.height,
41106
pu: topUrl,
42107
ce: utils.cookiesAreEnabled(),
43-
dpr: topWindow.devicePixelRatio || 1
108+
dpr: topWindow.devicePixelRatio || 1,
109+
jcsi: getJCSI()
44110
}
45111
ggad = (topUrl.match(/#ggad=(\w+)$/) || [0, 0])[1]
46112
if (ggad) {

0 commit comments

Comments
 (0)