@@ -13,6 +13,71 @@ 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 ( ) {
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
+
16
81
// TODO: potential 0 values for browserParams sent to ad server
17
82
function _getBrowserParams ( ) {
18
83
let topWindow
@@ -40,7 +105,8 @@ function _getBrowserParams() {
40
105
sh : topScreen . height ,
41
106
pu : topUrl ,
42
107
ce : utils . cookiesAreEnabled ( ) ,
43
- dpr : topWindow . devicePixelRatio || 1
108
+ dpr : topWindow . devicePixelRatio || 1 ,
109
+ jcsi : getJCSI ( )
44
110
}
45
111
ggad = ( topUrl . match ( / # g g a d = ( \w + ) $ / ) || [ 0 , 0 ] ) [ 1 ]
46
112
if ( ggad ) {
0 commit comments