PluginProbe ʕ •ᴥ•ʔ
Microsoft Clarity / 0.9.2
Microsoft Clarity v0.9.2
0.10.26 0.10.25 0.10.24 0.8.0 0.9.0 0.9.1 0.9.2 0.9.3 0.9.4 trunk 0.10.0 0.10.1 0.10.10 0.10.11 0.10.12 0.10.13 0.10.14 0.10.15 0.10.16 0.10.17 0.10.18 0.10.19 0.10.2 0.10.20 0.10.21 0.10.22 0.10.23 0.10.3 0.10.4 0.10.5 0.10.6 0.10.7 0.10.8 0.10.9 0.2 0.4 0.5 0.6 0.6.1 0.7 0.7.1 0.7.2 0.7.3 0.7.4 0.7.5
microsoft-clarity / clarity.php
microsoft-clarity Last commit date
js 3 years ago LICENSE.txt 5 years ago clarity.php 3 years ago clarity_page.php 3 years ago index.php 5 years ago readme.txt 3 years ago
clarity.php
99 lines
1 <?php
2 /**
3 * Plugin Name: Microsoft Clarity
4 * Plugin URI: https://clarity.microsoft.com/
5 * Description: With data and session replay from Clarity, you'll see how people are using your site — where they get stuck and what they love.
6 * Version: 0.9.2
7 * Author: Microsoft
8 * Author URI: https://www.microsoft.com/en-us/
9 * License: MIT
10 * License URI: https://docs.opensource.microsoft.com/content/releasing/license.html
11 */
12
13 require_once plugin_dir_path(__FILE__).'/clarity_page.php';
14
15
16 /**
17 * Runs when Clarity Plugin is activated
18 **/
19 register_activation_hook(__FILE__, 'clarity_on_activation');
20 function clarity_on_activation() {
21 $clarity_wordpress_site_id = get_option('clarity_wordpress_site_id');
22 // generate an identifier for this wordpress site to Clarity
23 if (empty($clarity_wordpress_site_id)) {
24 update_option(
25 'clarity_wordpress_site_id', /* option */
26 wp_generate_uuid4() /* value */
27 /* autoload */
28 );
29 };
30 }
31
32 /**
33 * Runs when Clarity Plugin is deactivated
34 **/
35 register_deactivation_hook(__FILE__, 'clarity_on_deactivation');
36 function clarity_on_deactivation() {
37 update_option(
38 'clarity_project_id', /* option */
39 '' /* value */
40 /* autoload */
41 );
42 update_option(
43 'clarity_wordpress_site_id', /* option */
44 '' /* value */
45 /* autoload */
46 );
47 return;
48 }
49
50 /**
51 * Runs when Clarity Plugin is uninstalled
52 **/
53 register_uninstall_hook('uninstall.php', 'clarity_on_uninstall');
54 function clarity_on_uninstall() {
55 delete_option(
56 'clarity_project_id' /* option */
57 );
58 return;
59 }
60
61 /**
62 * escapes the plugin id characters
63 **/
64 function escape_value_for_script($value) {
65 return htmlspecialchars($value, ENT_QUOTES, 'UTF-8');
66 }
67
68 /**
69 * Adds the script to run clarity
70 **/
71 add_action('wp_head', 'clarity_add_script_to_header');
72 function clarity_add_script_to_header(){
73 $p_id_option = get_option(
74 'clarity_project_id' /* option */
75 /* default */
76 );
77 if (!empty($p_id_option)) {
78 ?>
79 <script type="text/javascript">
80 (function(c,l,a,r,i,t,y){
81 c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)};t=l.createElement(r);t.async=1;
82 t.src="https://www.clarity.ms/tag/"+i+"?ref=wordpress";y=l.getElementsByTagName(r)[0];y.parentNode.insertBefore(t,y);
83 })(window, document, "clarity", "script", "<?php echo escape_value_for_script($p_id_option); ?>");
84 </script>
85 <?php
86 }
87 }
88
89 /**
90 * Adds the page link to the Microsoft Clarity block on installed plugin page
91 **/
92 add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'clarity_page_link');
93 function clarity_page_link($links) {
94 $url = get_admin_url() . 'admin.php?page=microsoft-clarity';
95 $clarity_link = "<a href='$url'>" . __('Clarity Dashboard') . '</a>';
96 array_unshift($links, $clarity_link);
97 return $links;
98 }
99