@@ -155,17 +155,88 @@ private function get_activation_notice() {
155
155
ob_start ();
156
156
?>
157
157
<script type="text/javascript">
158
- if( 'undefined' !== typeof sendAnalyticsTrackingEvent ) {
159
- sendAnalyticsTrackingEvent( 'plugin_setup', 'plugin_activated' );
160
- }
158
+ document.addEventListener( 'DOMContentLoaded' , function() {
159
+ if ( 'undefined' !== typeof sendAnalyticsTrackingEvent ) {
160
+ sendAnalyticsTrackingEvent( 'plugin_setup', 'plugin_activated' );
161
+ }
162
+
163
+ var trackingScriptPresent = !! googlesitekit.admin.trackingOptIn;
164
+
165
+ var optInCheckbox = document.getElementById( 'googlesitekit-opt-in' );
166
+ var startSetupLink = document.getElementById( 'start-setup-link' );
167
+
168
+ if ( ! optInCheckbox ) {
169
+ console.error( "Expected element #googlesitekit-opt-in to be found on page, but it wasn't. Tracking may not work." );
170
+ return;
171
+ }
172
+
173
+ if ( ! startSetupLink ) {
174
+ console.error( "Expected element #start-setup-link to be found on page, but it wasn't. Tracking may not work." );
175
+ return;
176
+ }
177
+
178
+ if ( googlesitekit.admin.trackingOptIn ) {
179
+ optInCheckbox.checked = googlesitekit.admin.trackingOptIn;
180
+ }
181
+ if ( googlesitekit.admin.proxySetupURL ) {
182
+ startSetupLink.href = googlesitekit.admin.proxySetupURL;
183
+ }
184
+
185
+ startSetupLink.addEventListener( 'click' , function() {
186
+ if ( 'undefined' !== typeof sendAnalyticsTrackingEvent ) {
187
+ sendAnalyticsTrackingEvent( 'plugin_setup', googlesitekit.admin.proxySetupURL ? 'proxy_start_setup_banner' : 'goto_sitekit' );
188
+ }
189
+ } );
190
+
191
+ optInCheckbox.addEventListener( 'change' , function( event ) {
192
+ if ( event.target.disabled ) {
193
+ event.preventDefault();
194
+ return;
195
+ }
196
+
197
+ var checked = event.target.checked;
198
+
199
+ var body = {
200
+ googlesitekit_tracking_optin: checked,
201
+ };
202
+ var self = this;
203
+
204
+ event.target.disabled = true;
205
+
206
+ wp.apiFetch( {
207
+ path: '/wp/v2/settings',
208
+ headers: {
209
+ 'Content-Type': 'application/json; charset=UTF-8',
210
+ },
211
+ body: JSON.stringify( body ),
212
+ method: 'POST',
213
+ } )
214
+ .then( function() {
215
+ event.target.disabled = null;
216
+ window.googlesitekitTrackingEnabled = !! checked;
217
+
218
+ var trackingId = googlesitekit.admin.trackingID;
219
+ var trackingScriptPresent = document.querySelector( 'script[src="https://www.googletagmanager.com/gtag/js?id=' + trackingId + '"]' );
220
+
221
+ if ( ! trackingScriptPresent ) {
222
+ document.body.insertAdjacentHTML( 'beforeend', '\<script async src="https://www.googletagmanager.com/gtag/js?id=' + trackingId + '"\>\</script\>' );<?php // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript ?>
223
+ document.body.insertAdjacentHTML( 'beforeend', "\<script\>window.dataLayer = window.dataLayer || [];function gtag(){dataLayer.push(arguments);}gtag('js', new Date());gtag('config', '" + trackingId + "');\</script\>" );
224
+ }
225
+ } )
226
+ .catch( function( err ) {
227
+ event.target.checked = ! checked;
228
+ event.target.disabled = false;
229
+ } );
230
+ } );
231
+ } );
161
232
</script>
162
233
<div class="googlesitekit-plugin">
163
234
<div class="googlesitekit-activation">
164
235
<div class="mdc-layout-grid">
165
236
<div class="mdc-layout-grid__inner">
166
237
<div class="
167
238
mdc-layout-grid__cell
168
- mdc-layout-grid__cell--span-7
239
+ mdc-layout-grid__cell--span-12
169
240
">
170
241
<div class="googlesitekit-logo">
171
242
<?php
@@ -186,20 +257,49 @@ private function get_activation_notice() {
186
257
); // phpcs:ignore WordPress.XSS.EscapeOutput.OutputNotEscaped
187
258
?>
188
259
</div>
189
- <h3 class="googlesitekit-heading-1 googlesitekit-activation__title">
260
+ <h3 class="googlesitekit-heading-3 googlesitekit-activation__title">
190
261
<?php esc_html_e ( 'Congratulations, the Site Kit plugin is now activated. ' , 'google-site-kit ' ); ?>
191
262
</h3>
192
- </div>
193
- <div class="
194
- mdc-layout-grid__cell
195
- mdc-layout-grid__cell--start-8-desktop
196
- mdc-layout-grid__cell--offset-1-desktop
197
- mdc-layout-grid__cell--align-middle
198
- ">
199
- <a href="#" onClick="javascript:if( 'undefined' !== typeof sendAnalyticsTrackingEvent ) { sendAnalyticsTrackingEvent( 'plugin_setup', 'goto_sitekit' ) };document.location='<?php echo esc_url ( $ sitekit_splash_url ); ?> ';"
200
- class="googlesitekit-activation__button mdc-button mdc-button--raised">
263
+
264
+ <a id="start-setup-link" href="<?php echo esc_url ( $ sitekit_splash_url ); ?> " class="googlesitekit-activation__button googlesitekit-activation__start-setup mdc-button mdc-button--raised">
201
265
<?php esc_html_e ( 'Start Setup ' , 'google-site-kit ' ); ?>
202
266
</a>
267
+
268
+ <div class="googlesitekit-opt-in googlesitekit-activation__opt-in">
269
+ <div class="mdc-form-field">
270
+ <div class="mdc-checkbox mdc-checkbox--upgraded mdc-ripple-upgraded mdc-ripple-upgraded--unbounded">
271
+ <input class="mdc-checkbox__native-control" type="checkbox" id="googlesitekit-opt-in" value="1" />
272
+ <div class="mdc-checkbox__background">
273
+ <svg class="mdc-checkbox__checkmark" viewBox="0 0 24 24">
274
+ <path class="mdc-checkbox__checkmark-path" fill="none" d="M1.73,12.91 8.1,19.28 22.79,4.59"></path>
275
+ </svg>
276
+ <div class="mdc-checkbox__mixedmark">
277
+ </div>
278
+ </div>
279
+ </div>
280
+ <label for="googlesitekit-opt-in">
281
+ <?php
282
+ $ locale = str_replace ( '_ ' , '- ' , get_locale () );
283
+ echo wp_kses (
284
+ sprintf (
285
+ // translators: %s: https://policies.google.com/privacy?hl=LOCALE (where LOCALE is the current WordPress locale, translating the privacy policy if a translation exists).
286
+ __ (
287
+ 'Help us improve the Site Kit plugin by allowing tracking of anonymous usage stats. All data are treated in accordance with <a href="%s" rel="noopener noreferrer">Google Privacy Policy</a>. ' ,
288
+ 'google-site-kit '
289
+ ),
290
+ "https://policies.google.com/privacy?hl= $ {locale}"
291
+ ),
292
+ array (
293
+ 'a ' => array (
294
+ 'href ' => array (),
295
+ 'rel ' => array (),
296
+ ),
297
+ )
298
+ )
299
+ ?>
300
+ </label>
301
+ </div>
302
+ </div>
203
303
</div>
204
304
</div>
205
305
</div>
0 commit comments