-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathexample-direct-input.html
More file actions
217 lines (162 loc) · 7.84 KB
/
example-direct-input.html
File metadata and controls
217 lines (162 loc) · 7.84 KB
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<!DOCTYPE html>
<html lang="en">
<head>
<title>ATS Direct Mode Example</title>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<meta name="description" content="" />
<link rel="stylesheet" type="text/css" href="css/style.css" />
<!-- In some cases (usually for only US based publishers), you won't need to use our launchpad tag manager if you only plan on leveraging our ATS.js offering -->
<script async defer src="https://ats-wrapper.privacymanager.io/ats-modules/73e3e8e3-19f2-4e11-8446-73106b3c7853/ats.js"></script>'
<!-- We RECOMMEND using a publicly auditable hashing implementation so you know what you're getting into! -->
<script src="https://cdn.rawgit.com/h2non/jsHashes/master/hashes.js"></script>
<!-- To make things look dapper.. -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
<!-- For the sake of building our example, we'll include this specific portion in-line here -->
<script>
// Here's an example of how you might quickly hash your identifiers.
function getHashedIdentifierTuple(rawIdentifier) {
// Please do additional sanitization/input checking prior..
let hashedIDTuple = {};
if (typeof (rawIdentifier) != "undefined" && rawIdentifier.length > 0) {
hashedIDTuple = {
md5: new Hashes.MD5().hex(rawIdentifier),
sha1: new Hashes.SHA1().hex(rawIdentifier),
sha256: new Hashes.SHA256().hex(rawIdentifier)
}
}
return hashedIDTuple;
}
// Here's an example of using "setAdditionalData" - this will in turn trigger
// a request to our identity API service for a RampID envelope.
function setHashedIdentifiersForATSDirect(identifierMD5, identifierSHA1, identifierSHA256) {
atsenvelopemodule.setAdditionalData({
'type': 'emailHashes',
'id': [identifierMD5, identifierSHA1, identifierSHA256]
});
}
// Example invocation call, we'll call this with our UI
function setATSDirectForIdentifier(cleartextEmail) {
let tuple = getHashedIdentifierTuple(cleartextEmail);
setHashedIdentifiersForATSDirect(tuple.md5, tuple.sha1, tuple.sha256);
}
</script>
</head>
<body>
<div class="container">
<h1>Hello, ATS! (direct mode)</h1>
<p>This example allows you to provide an identifier directly to ATS without any form / input detection.</p>
<p>You might use this in cases where you'd like finer control over when ATS.js requests an envelope, or if your
present web application is unable to leverage certain functions of our script.</p>
<p>Friendly note: When you have "direct" configured, the detection module in ATS is not returned in the global
ATS window object. </p>
<form id="example-form">
<div>
<p>MD5: <span id="md5hashedInput">md5</span></p>
<p>SHA1: <span id="sha1hashedInput">sha1</span></p>
<p>SHA256: <span id="sha256hashedInput">sha256</span></p>
</div>
<label for="email">Your Email</label>
<input type="text" id="emailInput" required>
<button id="directSubmit" onclick="onclick_doDirectATSCall()">Do ATS Direct Call</button>
</form>
<div>
<h3>General ATS info</h1>
<p>ATS Enabled: <span id="atsEnabled"></span></p>
<p>Envelope Available: <span id="atsEnvelopeValue"></span></p>
<button onclick="checkForEnvelope()">Check for Envelope</button>
</div>
<div>
<h3>Envelope module info</h1>
<table>
<thead>
<tr>
<th>Name</th>
<th>Value</th>
</tr>
</thead>
<tbody id="envelope-module-info"">
<!-- Dynamically generated -->
</tbody>
</table>
</div>
</div>
<script>
let emailInputRef;
async function checkForEnvelope() {
const envDisplay = document.getElementById("atsEnvelopeValue");
let displayVal = "";
if (typeof (ats) != 'undefined') {
var env = await ats.retrieveEnvelope();
if (typeof (env) != 'undefined') {
displayVal = env;
} else {
displayVal = "no envelope"
}
} else {
displayVal = "ats not defined"
}
envDisplay.textContent = displayVal;
}
document.addEventListener('DOMContentLoaded', () => {
console.log("Doc loaded");
emailInputRef = document.getElementById('emailInput');
emailInputRef.addEventListener('input', doLiveHashUIUpdate);
// Prevent submit button from redirecting
document.getElementById("directSubmit").addEventListener("click",
(e) => e.preventDefault());
});
// TODO: get rid of this hacky way.
setTimeout(() => {
var isEnabled = checkATSStatus();
if (isEnabled) {
let envInfoTableRef = document.getElementById("envelope-module-info");
envModuleInfo = getATSEnvelopeModuleInfo();
renderModuleInfoObjToTable(envModuleInfo, envInfoTableRef);
}
}, 1000);
let md5InputSpanRef = document.getElementById('md5hashedInput');
let sha1InputSpanRef = document.getElementById('sha1hashedInput');
let sha256InputSpanRef = document.getElementById('sha256hashedInput');
// Live update the UI for the sake of our example
function doLiveHashUIUpdate(event) {
var tuple = getHashedIdentifierTuple(emailInputRef.value);
md5InputSpanRef.textContent = tuple.md5;
sha1InputSpanRef.textContent = tuple.sha1;
sha256InputSpanRef.textContent = tuple.sha256;
}
function onclick_doDirectATSCall(){
setATSDirectForIdentifier(emailInputRef.value);
}
function checkATSStatus() {
let atsEnabled = document.getElementById('atsEnabled');
if (typeof (ats) == 'undefined') {
atsEnabled.textContent = "Not loaded"
return false
} else {
atsEnabled.textContent = "Loaded"
return true;
}
}
function getATSEnvelopeModuleInfo() {
let moduleInfoKVP = {};
let envInfo = ats.outputCurrentConfiguration().ENVELOPE_MODULE_INFO;
let envConfig = envInfo.ENVELOPE_MODULE_CONFIG;
// Populate the object here with a readable unique key and the value
moduleInfoKVP["PID"] = envConfig.placementID;
// TODO: do more
return moduleInfoKVP;
}
function renderModuleInfoObjToTable(infoObj, tableRef) {
var keyCollection = Object.keys(infoObj);
for (var i = 0; i < keyCollection.length; ++i) {
let tRow = document.createElement("tr"); let
tKey = document.createElement("td"); tKey.textContent = keyCollection[i]; let
tData = document.createElement("td"); tData.textContent = infoObj[keyCollection];
tRow.appendChild(tKey); tRow.appendChild(tData); tableRef.appendChild(tRow);
}
}
</script>
</body>
</html>