Skip to content

Commit 278fb11

Browse files
authored
Merge branch 'master' into master
2 parents 0c2d58f + 6393170 commit 278fb11

File tree

9 files changed

+141
-27
lines changed

9 files changed

+141
-27
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
Changelog
22
==========
33

4+
#### 2.0.0 - November 15, 2019
5+
6+
Well first of all, we are sorry for the long delay in updating this plugin! We've been busy at work on Fathom V2 all year. In this major update of the wordpress plugin, we've ensured backward compatability but have modified the guidelines to include some of the new changes we have made. Firstly, the concept of a "Dashboard URL" doesn't exist within V2, and you simply use the CDN URL! Nice and easy. But we have left the Dashboard URL in place for our V1 users who self-host. We've also added the ability for V2 users to embed their dashboard & create a new tab in the admin menu.
7+
48
#### 1.0.1 - October 10, 2018
59

610
Added support for tracking multiple sites in a single Fathom dashboard (requires Fathom v1.0.1).
711

812

913
#### 1.0.0 - September 10, 2018
1014

11-
Plugin release.
15+
Plugin release.

README.md

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,55 @@
1-
# Fathom WordPress Plugin
1+
# Fathom Analytics for WordPress
22

3-
A simple plugin to add the [Fathom Analytics](https://usefathom.com/) tracking snippet to your WordPress site.
3+
Fathom Analytics for WordPress is a simple way to view your dashboard inside WordPress, and add your Fathom Analytics tracking code to your WordPress site without editing any code. This plugin is for paying customers of Fathom Analytics.
4+
5+
![Screenshot of the Fathom Analytics for Wordpress Embedded Dashboard](https://raw.githubusercontent.com/usefathom/wordpress-plugin/master/screenshot-2.png)
6+
![Screenshot of the Fathom Analytics for Wordpress Settings](https://raw.githubusercontent.com/usefathom/wordpress-plugin/master/screenshot-1.png)
7+
8+
### What is Fathom Analytics?
9+
[Fathom Analytics](https://usefathom.com) is a simple, privacy-focused website analytics tool for bloggers and businesses.
10+
11+
Stop scrolling through pages of reports and collecting gobs of personal data about your visitors, both of which you probably don’t need. Fathom is a simple and private website analytics platform that lets you focus on what's important: your business.
12+
13+
Major features of Fathom Analytics include:
14+
15+
* One screen, all the real-time data you need
16+
* Cookie notices not required (we don’t use cookies or collect personal data)
17+
* Displays: top content, top referrers, top goals and more
18+
19+
To use use this plugin, you need have a paid Fathom Analytics account and your dashboard sharing set to [public or private with password](https://usefathom.com/support/sharing).
20+
21+
### FAQ
22+
23+
**Where can I find the plugin settings?**
24+
This plugin has just a single settings field, which can be found by going to WP Admin > Settings > Fathom Analytics.
25+
26+
**Where do I find my SiteID?**
27+
Your SiteID is the unique code in your tracking snippet. Go to your Dashboard, click Settings, then Sites. The SiteID is the second column, copy and paste it from there into the field on the settings page in WordPress.
28+
29+
**What’s the Fathom share password?**
30+
In order to use Fathom Analytics for WordPress your dashboard must be set to “Public” or “Viewable to anyone with the share password”. If your dashboard is public, skip the Fathom Share Password field. If your dashboard is set to have a share password, enter that password in this field.
31+
32+
**What’s the Fathom Fathom URL?**
33+
Leave this set to “cdn.usefathom.com” unless you are using Fathom Lite (the OS version), and in that case, enter the tracker URL you are using.
434

535
### Usage
636

7-
After installing and activating this plugin, go to **Settings > General** and enter the URL to your Fathom instance in the text field near the bottom.
37+
Log into Wordpress
38+
39+
1. [Download the Fathom Analytics plugin](https://github.com/usefathom/wordpress-plugin/releases/download/2.0/fathom-analytics.zip)
40+
2. Go to `Plugins`, `Add New`
41+
3. Upload this plugin, `fathom-analytics.zip`
42+
4. Click `Install Now`, then `Activate`
43+
5. Go to `Settings`, then `Fathom Analytics`
44+
6. Type in your `SiteID`. If you don’t know your `SiteId`, log into [Fathom Analytics](https://app.usefathom.com), go to `Settings`, `Sites`, then your `SiteID` will be beside the name of your site
45+
7. If your dashboard is public, leave `Fathom share password` blank. If your dashboard is privately shared, then type in the share password
46+
8. Leave `Fathom URL` set to cdn.usefathom.com
47+
48+
Taking the above steps automatically places the Fathom tracking code into the footer of every page of your WordPress site.
49+
50+
If you now want to see your Fathom dashboard from within Wordpress, make sure “Display Analytics Menu Item” is checked off. Hit Save Changes, and you’ll see Fathom on the menu in WordPress on the lefthand side.
51+
52+
Enjoy Fathom Analytics for WordPress!
853

954
### License
1055

fathom-analytics.php

Lines changed: 66 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
/*
33
Plugin Name: Fathom Analytics
44
Description: A simple plugin to add the Fathom tracking snippet to your WordPress site.
5-
Author: Fathom Team
6-
Version: 1.0.1
5+
Author: Conva Ventures Inc
6+
Note: Huge thanks to Danny Van Kooten for his hard work on Version 1 of this plugin
7+
Version: 2.0.0
78
89
Fathom Analytics for WordPress
9-
Copyright (C) 2018 Danny van Kooten
10+
Copyright (C) 2019 Conva Ventures Inc
1011
1112
This program is free software: you can redistribute it and/or modify
1213
it under the terms of the GNU General Public License as published by
@@ -25,16 +26,18 @@
2526
const FATHOM_URL_OPTION_NAME = 'fathom_url';
2627
const FATHOM_SITE_ID_OPTION_NAME = 'fathom_site_id';
2728
const FATHOM_ADMIN_TRACKING_OPTION_NAME = 'fathom_track_admin';
29+
const FATHOM_PRIVATE_SHARE_PASSWORD = 'fathom_share_password';
30+
const FATHOM_SHOW_ANALYTICS_MENU_ITEM = 'fathom_show_menu';
2831

2932
/**
3033
* @since 1.0.0
3134
*/
3235
function fathom_get_url() {
3336
$fathom_url = get_option( FATHOM_URL_OPTION_NAME, '' );
34-
37+
3538
// don't print snippet if fathom URL is empty
3639
if( empty( $fathom_url ) ) {
37-
return '';
40+
return 'cdn.usefathom.com';
3841
}
3942

4043
// trim trailing slash
@@ -48,7 +51,7 @@ function fathom_get_url() {
4851

4952
/**
5053
* @since 1.0.1
51-
*/
54+
*/
5255
function fathom_get_site_id() {
5356
return get_option( FATHOM_SITE_ID_OPTION_NAME, '' );
5457
}
@@ -78,6 +81,10 @@ function fathom_print_js_snippet() {
7881

7982
$site_id = fathom_get_site_id();
8083

84+
if (empty($site_id)) {
85+
return;
86+
}
87+
8188
?>
8289
<!-- Fathom - simple website analytics - https://usefathom.com/ -->
8390
<script>
@@ -90,35 +97,55 @@ function fathom_print_js_snippet() {
9097
m=f.getElementsByTagName('script')[0];
9198
o.async=1; o.src=t;
9299
m.parentNode.insertBefore(o,m)
93-
})(document, window, '//<?php echo esc_attr( $url ); ?>/tracker.js', 'fathom');
94-
fathom('set', 'siteId', '<?php echo esc_attr( $site_id ); ?>');
100+
})(document, window, 'https://<?php echo esc_attr( $url ); ?>/tracker.js', 'fathom');
101+
fathom('set', 'siteId', '<?php echo esc_attr( $site_id ); ?>');
95102
fathom('trackPageview');
96103
</script>
97104
<!-- / Fathom -->
98105
<?php
99106
}
100107

108+
/**
109+
* @since 2.0.0
110+
*/
111+
function fathom_stats_page() {
112+
add_menu_page( 'Fathom', 'Analytics', 'edit_pages', 'analytics', 'fathom_print_stats_page', 'dashicons-chart-bar', 6 );
113+
}
114+
115+
/**
116+
* @since 2.0.0
117+
*/
118+
function fathom_print_stats_page() {
119+
wp_enqueue_script('fathom-iframresize', plugins_url('iframeResizer.min.js', __FILE__));
120+
wp_enqueue_script('fathom-stats-iframe', plugins_url('fathom-stats-iframe.js', __FILE__));
121+
echo '<div class="wrap">';
122+
echo '<iframe id="fathom-stats-iframe" src="https://app.usefathom.com/share/' . get_option( FATHOM_SITE_ID_OPTION_NAME ) . '/wordpress?password=' . hash('sha256', get_option( FATHOM_PRIVATE_SHARE_PASSWORD )) . '" style="width: 1px;min-width: 100%; height:1000px; max-width:1100px" frameborder="0" onload=fathomResizeIframe();></iframe>';
123+
echo '</div>';
124+
}
125+
101126
/**
102127
* @since 1.0.0
103128
*/
104129
function fathom_register_settings() {
105-
$fathom_logo_html = sprintf( '<a href="https://usefathom.com/" style="margin-left: 6px;"><img src="%s" width=16 height=16 style="vertical-align: bottom;"></a>', plugins_url( 'fathom.svg', __FILE__ ) );
106-
130+
$fathom_logo_html = sprintf( '<a href="https://usefathom.com/" style="margin-left: 6px;"><img src="%s" width=20 height=20 style="vertical-align: bottom;"></a>', plugins_url( 'fathom.png', __FILE__ ) );
131+
107132
// register page + section
108133
add_options_page( 'Fathom Analytics', 'Fathom Analytics', 'manage_options', 'fathom-analytics', 'fathom_print_settings_page' );
109134
add_settings_section( 'default', "Fathom Analytics {$fathom_logo_html}", '__return_true', 'fathom-analytics' );
110135

111136
// register options
112-
register_setting( 'fathom', FATHOM_URL_OPTION_NAME, array( 'type' => 'string' ) );
113137
register_setting( 'fathom', FATHOM_SITE_ID_OPTION_NAME, array( 'type' => 'string' ) );
114138
register_setting( 'fathom', FATHOM_ADMIN_TRACKING_OPTION_NAME, array( 'type' => 'string') );
139+
register_setting( 'fathom', FATHOM_URL_OPTION_NAME, array( 'type' => 'string' ) );
140+
register_setting( 'fathom', FATHOM_PRIVATE_SHARE_PASSWORD, array( 'type' => 'string' ) );
141+
register_setting( 'fathom', FATHOM_SHOW_ANALYTICS_MENU_ITEM, array( 'type' => 'boolean' ) );
115142

116143
// register settings fields
117-
add_settings_field( FATHOM_URL_OPTION_NAME, __( 'Dashboard URL', 'fathom-analytics' ), 'fathom_print_url_setting_field', 'fathom-analytics', 'default' );
118-
119144
add_settings_field( FATHOM_SITE_ID_OPTION_NAME, __( 'Site ID', 'fathom-analytics' ), 'fathom_print_site_id_setting_field', 'fathom-analytics', 'default' );
120-
121145
add_settings_field( FATHOM_ADMIN_TRACKING_OPTION_NAME, __('Track Administrators', 'fathom-analytics'), 'fathom_print_admin_tracking_setting_field', 'fathom-analytics', 'default');
146+
add_settings_field( FATHOM_SHOW_ANALYTICS_MENU_ITEM, __( 'Display Analytics Menu Item', 'fathom-analytics' ), 'fathom_print_display_analytics_menu_setting_field', 'fathom-analytics', 'default' );
147+
add_settings_field( FATHOM_PRIVATE_SHARE_PASSWORD, __( 'Fathom Share Password', 'fathom-analytics' ), 'fathom_print_share_password_setting_field', 'fathom-analytics', 'default' );
148+
add_settings_field( FATHOM_URL_OPTION_NAME, __( 'Fathom URL', 'fathom-analytics' ), 'fathom_print_url_setting_field', 'fathom-analytics', 'default' );
122149
}
123150

124151
/**
@@ -134,14 +161,32 @@ function fathom_print_settings_page() {
134161
echo '</div>';
135162
}
136163

164+
/**
165+
* @since 2.0.0
166+
*/
167+
function fathom_print_display_analytics_menu_setting_field( $args = array() ) {
168+
$value = get_option( FATHOM_SHOW_ANALYTICS_MENU_ITEM );
169+
echo sprintf( '<input type="checkbox" name="%s" id="%s" class="regular-text" ' . (esc_attr($value) ? 'checked' : '') .' />', FATHOM_SHOW_ANALYTICS_MENU_ITEM, FATHOM_SHOW_ANALYTICS_MENU_ITEM);
170+
echo '<p class="description">' . __( 'Display the Fathom Tab', 'fathom-analytics' ) . '</p>';
171+
}
172+
173+
/**
174+
* @since 2.0.0
175+
*/
176+
function fathom_print_share_password_setting_field( $args = array() ) {
177+
$value = get_option( FATHOM_PRIVATE_SHARE_PASSWORD );
178+
echo sprintf( '<input type="text" name="%s" id="%s" class="regular-text" value="%s" placeholder="%s" />', FATHOM_PRIVATE_SHARE_PASSWORD, FATHOM_PRIVATE_SHARE_PASSWORD, esc_attr( $value ), esc_attr( $placeholder ) );
179+
echo '<p class="description">' . __( 'If you don\'t set a password here, the user will be prompted to enter one on the Analytics menu option', 'fathom-analytics' ) . '</p>';
180+
}
181+
137182
/**
138183
* @since 1.0.0
139184
*/
140185
function fathom_print_url_setting_field( $args = array() ) {
141186
$value = get_option( FATHOM_URL_OPTION_NAME );
142187
$placeholder = 'https://my-stats.usefathom.com/';
143-
echo sprintf( '<input type="text" name="%s" id="%s" class="regular-text" value="%s" placeholder="%s" />', FATHOM_URL_OPTION_NAME, FATHOM_URL_OPTION_NAME, esc_attr( $value ), esc_attr( $placeholder ) );
144-
echo '<p class="description">' . __( 'Enter the full URL to your Fathom instance here.', 'fathom-analytics' ) . '</p>';
188+
echo sprintf( '<input type="text" name="%s" id="%s" class="regular-text" value="%s" placeholder="%s" />', FATHOM_URL_OPTION_NAME, FATHOM_URL_OPTION_NAME, esc_attr( $value ) ?: 'cdn.usefathom.com', esc_attr( $placeholder ) );
189+
echo '<p class="description">' . __( 'Only edit this value if you are using Fathom Lite', 'fathom-analytics' ) . '</p>';
145190
}
146191

147192
/**
@@ -151,7 +196,7 @@ function fathom_print_site_id_setting_field( $args = array() ) {
151196
$value = get_option( FATHOM_SITE_ID_OPTION_NAME );
152197
$placeholder = 'ABCDEF';
153198
echo sprintf( '<input type="text" name="%s" id="%s" class="regular-text" value="%s" placeholder="%s" />', FATHOM_SITE_ID_OPTION_NAME, FATHOM_SITE_ID_OPTION_NAME, esc_attr( $value ), esc_attr( $placeholder ) );
154-
echo '<p class="description">' . __( 'Find your site ID by by clicking the gearwheel in your Fathom dashboard.', 'fathom-analytics' ) . '</p>';
199+
echo '<p class="description">' . __( 'This is the <a href="https://usefathom.com/support/wordpress" target="_blank">unique Tracking ID</a> for your site', 'fathom-analytics' ) . '</p>';
155200
}
156201

157202
/**
@@ -168,3 +213,7 @@ function fathom_print_admin_tracking_setting_field( $args = array() ) {
168213
if( is_admin() && ! wp_doing_ajax() ) {
169214
add_action( 'admin_menu', 'fathom_register_settings' );
170215
}
216+
217+
if (get_option( FATHOM_SHOW_ANALYTICS_MENU_ITEM )) {
218+
add_action( 'admin_menu', 'fathom_stats_page' );
219+
}

fathom-stats-iframe.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
function fathomResizeIframe() {
2+
iFrameResize({}, '#fathom-stats-iframe');
3+
}

fathom.png

3.7 KB
Loading

0 commit comments

Comments
 (0)