PluginProbe ʕ •ᴥ•ʔ
Microsoft Clarity / 0.2
Microsoft Clarity v0.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
admin 5 years ago LICENSE.txt 5 years ago clarity.php 5 years ago index.php 5 years ago readme.txt 5 years ago
clarity.php
97 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.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 /**
14 * Require files only if is admin area
15 * @param void
16 * @return HTML
17 **/
18 if(is_admin()){
19 require_once plugin_dir_path(__FILE__).'/admin/settings_page.php';
20 require_once plugin_dir_path(__FILE__).'/admin/settings_callbacks.php';
21 }
22
23 function clarity_plugin_settings_link( $links ) {
24 $url = get_admin_url() . 'options-general.php?page=clarity_settings';
25 $settings_link = '<a href="' . $url . '">' . __('Settings', 'textdomain') . '</a>';
26 array_unshift( $links, $settings_link );
27 return $links;
28 }
29
30 function clarity_after_setup_theme() {
31 add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'clarity_plugin_settings_link');
32 }
33 add_action ('after_setup_theme', 'clarity_after_setup_theme');
34
35 /**
36 * Add origins for CORS
37 * @param void
38 * @return HTML
39 **/
40 add_filter('allowed_http_origins', 'clarity_add_origins');
41 function clarity_add_origins( $origins ) {
42 $origins[] = 'https://www.clarity.ms';
43 return $origins;
44 }
45
46 /**
47 * Runs when Clarity Plugin is activated
48 * @param void
49 * @return void
50 **/
51 register_activation_hook(__FILE__, 'clarity_on_activation');
52 function clarity_on_activation() {
53 add_option("display_clarity_notice", true);
54 update_option("display_clarity_notice", true);
55 }
56
57 /**
58 * Runs when Clarity Plugin is deactivated
59 * @param void
60 * @return void
61 **/
62 register_deactivation_hook( __FILE__, 'clarity_on_deactivation');
63 function clarity_on_deactivation() {
64 remove_menu_page( 'clarity_settings' );
65 update_option("display_clarity_notice", false);
66 update_option('clarity_project_id', clarity_project_id_default_value());
67
68 return;
69 }
70
71 register_uninstall_hook( 'uninstall.php', 'clarity_on_uninstallation');
72 function clarity_on_uninstallation() {
73 delete_option("display_clarity_notice");
74 delete_option('clarity_project_id');
75 return;
76 }
77
78 /**
79 * Adds the script to run clarity
80 * @param void
81 * @return void
82 **/
83 add_action('wp_head', 'clarity_add_script_to_header');
84 function clarity_add_script_to_header(){
85 $p_id_option = get_option('clarity_project_id');
86 if ($p_id_option) {
87 ?>
88 <script type="text/javascript">
89 (function(c,l,a,r,i,t,y){
90 c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)};t=l.createElement(r);t.async=1;
91 t.src="https://www.clarity.ms/tag/"+i;y=l.getElementsByTagName(r)[0];y.parentNode.insertBefore(t,y);
92 })(window, document, "clarity", "script", "<?=$p_id_option ?>");
93 </script>
94 <?php
95 }
96 }
97