@@ -13,6 +13,76 @@ const TIME_TO_LIVE = 60
13
13
let browserParams = { } ;
14
14
let pageViewId = null
15
15
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
+
16
86
// TODO: potential 0 values for browserParams sent to ad server
17
87
function _getBrowserParams ( ) {
18
88
let topWindow
@@ -40,7 +110,8 @@ function _getBrowserParams() {
40
110
sh : topScreen . height ,
41
111
pu : topUrl ,
42
112
ce : utils . cookiesAreEnabled ( ) ,
43
- dpr : topWindow . devicePixelRatio || 1
113
+ dpr : topWindow . devicePixelRatio || 1 ,
114
+ jcsi : getJCSI ( )
44
115
}
45
116
ggad = ( topUrl . match ( / # g g a d = ( \w + ) $ / ) || [ 0 , 0 ] ) [ 1 ]
46
117
if ( ggad ) {
0 commit comments