-
Notifications
You must be signed in to change notification settings - Fork 3.9k
/
Copy pathamp-ad-exit.amp.html
149 lines (141 loc) · 4.29 KB
/
amp-ad-exit.amp.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<!doctype html>
<html amp4ads lang="en">
<head>
<title>amp-ad-exit example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,minimum-scale=1">
<style amp4ads-boilerplate>body{visibility:hidden}</style>
<script async src="https://cdn.ampproject.org/amp4ads-v0.js"></script>
<style amp-custom>
.ad {
border: 1px solid black;
width: 280px;
height: 230px;
background: #fff;
}
h1, .product {
cursor: pointer;
}
h1 {
font-size: 150%;
margin: 0;
color: #4285f4;
text-decoration: underline;
}
.product {
width: 100px;
height: 100px;
margin: 10px;
padding: 10px;
background: #0f9d58;
float: left;
}
amp-carousel .content {
width: 80%;
height: 80%;
margin: 10% 10%;
text-align: center;
}
.content pre { display: inline; }
#exit-selector option {
display: none;
}
#exit-selector option[selected] {
display: initial;
}
#cta {
width: 100px;
}
</style>
<script async custom-element="amp-ad-exit" src="https://cdn.ampproject.org/v0/amp-ad-exit-0.1.js"></script>
<script async custom-element="amp-carousel" src="https://cdn.ampproject.org/v0/amp-carousel-0.1.js"></script>
<script async custom-element="amp-selector" src="https://cdn.ampproject.org/v0/amp-selector-0.1.js"></script>
</head>
<body>
<amp-ad-exit id="exit-api" layout="nodisplay">
<script type="application/json">
{
"targets": {
"target1": {
"finalUrl": "http://localhost:8000/?product1&x=CLICK_X&y=CLICK_Y&e=_elem&shouldNotBeReplaced=AMP_VERSION",
"vars": {
"_elem": {"defaultValue": "headline"}
}
},
"target2": {
"finalUrl": "http://localhost:8000/?product2&x=CLICK_X&y=CLICK_Y&e=_elem&shouldNotBeReplaced=AMP_VERSION",
"vars": {
"_elem": {"defaultValue": "headline"}
}
},
"target2_filtered": {
"finalUrl": "http://localhost:8000/?product2&r=RANDOM",
"trackingUrls": [
"http://localhost:8000/?tracking-url&clicked=_elem"
],
"vars": {
"_elem": {"defaultValue": "headline"}
},
"filters": ["longDelay", "borderProtection"]
}
},
"filters": {
"longDelay": {
"type": "clickDelay",
"delay": 10000
},
"borderProtection": {
"type": "clickLocation",
"bottom": 10,
"left": 10,
"right": 10,
"relativeTo": "#product2"
}
},
"transport": {
"beacon": true,
"image": true
}
}
</script>
</amp-ad-exit>
<div class="ad">
<h1 on="tap:exit-api.exit(target='target1')" role="button" tabindex="1">amp-ad-exit example</h1>
<div class="product" id="product1" on="tap:exit-api.exit(target='target1', _elem='Product 1')" role="button" tabindex="1">
<p>product 1</p>
</div>
<div class="product" id="product2" on="tap:exit-api.exit(target='target2_filtered', _elem='Product 2')" role="button" tabindex="1">
<p>product 2</p>
</div>
<p><a href="https://www.google.com/" on="tap:exit-api.exit(target='target1', _elem='anchor')"><A> tags don't work well (try middle-clicking)</a>
</div>
<div class="ad" on="tap:exit-api.exit(target='target1')" role="button" tabindex="1">
<amp-carousel height="230" layout="fixed-height" type="slides">
<div class="content">amp-carousel example</div>
<div class="content">The exit event is on the parent <div></div>
<div class="content">
But the buttons don't trigger an exit because of a default InactiveElement
filter that matches their <pre>amp-carousel-button</pre> class.
</div>
</amp-carousel>
</div>
<div class="ad">
<amp-carousel height="150" layout="fixed-height" type="slides"
on="slideChange:exit-selector.toggle(index=event.index, value=true)">
<div class="content" role="link" tabindex="1" on="tap:exit-api.exit(target='target1', _elem='slide1')">product 1</div>
<div class="content" role="link" tabindex="1" on="tap:exit-api.exit(target='target2', _elem='slide2')">product 2</div>
</amp-carousel>
<button id="cta" tabindex="1"
on="tap:exit-api.exit(variable='current', default='target1', _elem='cta')">
Buy
<span>
<amp-selector id="exit-selector"
on="select:exit-api.setVariable(name='current', target=event.targetOption)">
<option option="target1" selected>product 1</option>
<option option="target2">product 2</option>
</amp-selector>
</span>
</button>
</div>
</body>
</html>