Skip to content

Commit

Permalink
🔀 Prepare 0.6.0 Release (#19)
Browse files Browse the repository at this point in the history
* Start implementing event tracking

* Add option for comment tracking

* Improve Readmes
  • Loading branch information
Ancocodet authored Feb 5, 2024
1 parent 43bbb8c commit 1cde11c
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 59 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ jobs:
if: startsWith(github.ref, 'refs/tags/')
steps:
- uses: actions/checkout@v3

# Composer Dependencies
- name: Validate composer.json and composer.lock
run: composer validate --strict

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v3
Expand All @@ -23,10 +24,10 @@ jobs:
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-dev

# Upload and Package Plugin
- name: WordPress Plugin Deploy
uses: 10up/action-wordpress-plugin-deploy@stable
with:
Expand All @@ -35,8 +36,7 @@ jobs:
SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }}
SVN_USERNAME: ${{ secrets.SVN_USERNAME }}
SLUG: integrate-umami

- name: Package for Git Release
uses: softprops/action-gh-release@v1
with:
files: ${{ steps.deploy.outputs.zip-path }}/integrate-umami.zip
files: ${{ steps.deploy.outputs.zip-path }}/*.zip
4 changes: 2 additions & 2 deletions css/integrate-umami.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
}

.integrate-umami-collapsed .toggle-label::after {
display: block; content: "\2795";
display: block; content: "\2BC6";
position: absolute; right: 10px; top: 3px;
transition: all 0.4s;
}
Expand All @@ -29,7 +29,7 @@
}

.integrate-umami-collapsed .toggle:checked ~ .toggle-label:after {
content: "\2796";
content: "\2BC5";
}

.integrate-umami-collapsed .toggle-label {
Expand Down
22 changes: 20 additions & 2 deletions inc/class-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,18 @@ class Manager {
*
* @since 0.1.0
* @change 0.2.0 - Add deactivation hook.
* @change 0.6.0 - Add filter for comment form submit button.
*/
public function __construct() {
$options = Options::get_options();
if ( $options['enabled'] && isset( $options['script_url'] ) && isset( $options['website_id'] ) && ! is_admin() ) {
if ( ! empty( $options['website_id'] ) && ! empty( $options['script_url'] ) ) {
add_action( 'wp_footer', array( $this, 'render_script' ) );

if ( isset( $options['track_comments'] ) && $options['track_comments'] === 1 ) {
// Add filters to add event data attributes.
add_filter( 'comment_form_submit_button', array( $this, 'filter_comment_form_submit_button' ), 10, 2 );
}
}
}

Expand All @@ -37,6 +43,18 @@ public static function deactivate() {
Options::delete_options();
}

/**
* Filter comment submit button to add data attribute.
*
* @param string $submit_button The submit button.
* @param array $args The arguments.
*
* @since 0.6.0
*/
public function filter_comment_form_submit_button( string $submit_button, array $args ) {
return str_replace( '<button', '<button data-umami-event="comment"', $submit_button );
}

/**
* Callback for script rendering.
*
Expand Down Expand Up @@ -68,13 +86,13 @@ public function render_script() {
}

?>
<!-- WP-Umami -->
<!-- Integrate Umami -->
<script async defer
src="<?php echo esc_url( $options['script_url'] ); ?>"
data-website-id="<?php esc_attr_e( $options['website_id'] ); ?>"
<?php esc_attr_e( $umami_options ); ?>>
</script>
<!-- /WP-Umami -->
<!-- /Integrate Umami -->
<?php
}

Expand Down
28 changes: 12 additions & 16 deletions inc/class-options.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
<?php
/**
* Class for managing the options.
*
* @package Integrate Umami
*/

namespace Ancozockt\Umami;

if ( ! defined( 'ABSPATH' ) ) {
exit;
}

/**
* Class Options
* Class for managing the options.
*
* @since 0.1.0
*/
Expand All @@ -22,22 +16,24 @@ class Options {
*
* @since 0.1.0
* @change 0.2.0 - Added default for ignore_admin.
* @change 0.6.0 - Added default for track_comments.
*
* @return array
*/
public static function get_options(): array {
return wp_parse_args(
get_option( 'umami_options' ),
array(
'enabled' => 0,
'script_url' => '',
'host_url' => '',
'website_id' => '',
'use_host_url' => 0,
'ignore_admins' => 1,
'auto_track' => 1,
'do_not_track' => 1,
'cache' => 0,
'enabled' => 0,
'script_url' => '',
'host_url' => '',
'website_id' => '',
'use_host_url' => 0,
'ignore_admins' => 1,
'auto_track' => 1,
'do_not_track' => 1,
'cache' => 0,
'track_comments' => 0,
)
);
}
Expand Down
21 changes: 11 additions & 10 deletions inc/class-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function plugin_actions( array $links ): array {
)
);

$settings_link = "<a href='$url'>" . __( 'Settings' ) . '</a>';
$settings_link = "<a href='{$url}'>" . __( 'Settings' ) . '</a>';

$links[] = $settings_link;

Expand Down Expand Up @@ -135,15 +135,16 @@ public function validate_options( array $data ): array {
}

return array(
'enabled' => (int) ( $data['enabled'] ?? false ),
'script_url' => esc_url_raw( $data['script_url'] ),
'website_id' => sanitize_text_field( $data['website_id'] ),
'host_url' => esc_url_raw( $data['host_url'] ),
'use_host_url' => (int) ( $data['use_host_url'] ?? false ),
'ignore_admins' => (int) ( $data['ignore_admins'] ?? false ),
'auto_track' => (int) ( $data['auto_track'] ?? false ),
'do_not_track' => (int) ( $data['do_not_track'] ?? false ),
'cache' => (int) ( $data['cache'] ?? false ),
'enabled' => (int) ( $data['enabled'] ?? false ),
'script_url' => esc_url_raw( $data['script_url'] ),
'website_id' => sanitize_text_field( $data['website_id'] ),
'host_url' => esc_url_raw( $data['host_url'] ),
'use_host_url' => (int) ( $data['use_host_url'] ?? false ),
'ignore_admins' => (int) ( $data['ignore_admins'] ?? false ),
'auto_track' => (int) ( $data['auto_track'] ?? false ),
'do_not_track' => (int) ( $data['do_not_track'] ?? false ),
'cache' => (int) ( $data['cache'] ?? false ),
'track_comments' => (int) ( $data['track_comments'] ?? false ),
);
}

Expand Down
55 changes: 38 additions & 17 deletions inc/templates/settings-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@

?>
<form method="post" action="options.php" xmlns="http://www.w3.org/1999/html">
<?php settings_fields( 'integration_umami' ); ?>
<?php settings_fields( 'integrate_umami' ); ?>
<table class="form-table">
<tr>
<th scope="row">
<?php esc_html_e( 'Enabled', 'integrate-umami' ); ?>
</th>
<td>
<label for="integration_umami_enabled">
<input type="checkbox" name="umami_options[enabled]" id="integration_umami_enabled"
<label for="integrate_umami_enabled">
<input type="checkbox" name="umami_options[enabled]" id="integrate_umami_enabled"
value="1" <?php checked( $options['enabled'] ); ?> />
<?php esc_html_e( 'Enable umami analytics', 'integrate-umami' ); ?>
</label>
Expand All @@ -32,7 +32,7 @@
<?php esc_html_e( 'Script Url', 'integrate-umami' ); ?>
</th>
<td>
<input class="integrate-umami-url" type="url" name="umami_options[script_url]" id="integration_umami_script_url"
<input class="integrate-umami-url" type="url" name="umami_options[script_url]" id="integrate_umami_script_url"
value="<?php echo esc_attr( $options['script_url'] ); ?>"/>
<p class="description"><?php esc_html_e( 'The url to your umami tracking script', 'integrate-umami' ); ?></p>
</td>
Expand All @@ -43,7 +43,7 @@
<?php esc_html_e( 'Website ID', 'integrate-umami' ); ?>
</th>
<td>
<input class="integrate-umami-text" type="text" name="umami_options[website_id]" id="integration_umami_website_id"
<input class="integrate-umami-text" type="text" name="umami_options[website_id]" id="integrate_umami_website_id"
value="<?php echo esc_attr( $options['website_id'] ); ?>"/>
<p class="description"><?php esc_html_e( 'The umami websiteId generated by your installation', 'integrate-umami' ); ?></p>
</td>
Expand All @@ -60,7 +60,7 @@
<?php esc_html_e( 'Host Url', 'integrate-umami' ); ?>
</th>
<td>
<input class="integrate-umami-url" type="url" name="umami_options[host_url]" id="integration_umami_host_url"
<input class="integrate-umami-url" type="url" name="umami_options[host_url]" id="integrate_umami_host_url"
value="<?php echo esc_attr( $options['host_url'] ); ?>"/>
<p class="description">
<?php
Expand All @@ -80,8 +80,8 @@
<?php esc_html_e( 'Use Host Url', 'integrate-umami' ); ?>
</th>
<td>
<label for="integration_umami_use_host_url">
<input type="checkbox" name="umami_options[use_host_url]" id="integration_umami_use_host_url"
<label for="integrate_umami_use_host_url">
<input type="checkbox" name="umami_options[use_host_url]" id="integrate_umami_use_host_url"
value="1" <?php checked( $options['use_host_url'] ); ?> />
<?php
echo wp_kses(
Expand All @@ -102,8 +102,8 @@
<?php esc_html_e( 'Ignore Admins', 'integrate-umami' ); ?>
</th>
<td>
<label for="integration_umami_ignore_admins">
<input type="checkbox" name="umami_options[ignore_admins]" id="integration_umami_ignore_admins"
<label for="integrate_umami_ignore_admins">
<input type="checkbox" name="umami_options[ignore_admins]" id="integrate_umami_ignore_admins"
value="1" <?php checked( $options['ignore_admins'] ); ?> />
<?php esc_html_e( 'Disable tracking for admin users', 'integrate-umami' ); ?>
</label>
Expand All @@ -115,8 +115,8 @@
<?php esc_html_e( 'Auto Tracking', 'integrate-umami' ); ?>
</th>
<td>
<label for="integration_umami_auto_track">
<input type="checkbox" name="umami_options[auto_track]" id="integration_umami_auto_track"
<label for="integrate_umami_auto_track">
<input type="checkbox" name="umami_options[auto_track]" id="integrate_umami_auto_track"
value="1" <?php checked( $options['auto_track'] ); ?> />
<?php esc_html_e( 'Enable the automatic events and pageviews tracking', 'integrate-umami' ); ?>
<p class="description">
Expand All @@ -136,13 +136,34 @@
</td>
</tr>

<tr>
<th class="row">
<?php esc_html_e( 'Track Comment Submit', 'integrate-umami' ); ?>
</th>
<td>
<label for="integrate_umami_track_comments">
<input type="checkbox" name="umami_options[track_comments]" id="integrate_umami_track_comments" value="1" <?php checked( $options['track_comments'] ); ?> />
<?php
echo wp_kses(
__( 'Track Comment submits using <a href="https://umami.is/docs/track-events">events</a>', 'integrate-umami' ),
[
'a' => [
'href' => [],
],
]
);
?>
</label>
</td>
</tr>

<tr>
<th class="row">
<?php esc_html_e( 'Do Not Track', 'integrate-umami' ); ?>
</th>
<td>
<label for="integration_umami_do_not_track">
<input type="checkbox" name="umami_options[do_not_track]" id="integration_umami_do_not_track"
<label for="integrate_umami_do_not_track">
<input type="checkbox" name="umami_options[do_not_track]" id="integrate_umami_do_not_track"
value="1" <?php checked( $options['do_not_track'] ); ?> />
<?php
echo wp_kses(
Expand All @@ -161,14 +182,14 @@
<?php esc_html_e( 'Cache', 'integrate-umami' ); ?>
</th>
<td>
<label for="integration_umami_cache">
<input type="checkbox" name="umami_options[cache]" id="integration_umami_cache"
<label for="integrate_umami_cache">
<input type="checkbox" name="umami_options[cache]" id="integrate_umami_cache"
value="1" <?php checked( $options['cache'] ); ?> />
<?php esc_html_e( 'Enable caching of tracking data for better performance', 'integrate-umami' ); ?>
<p class="description">
<?php
echo wp_kses(
__( '<b>Note</b>: This will use session storage so you may need to inform your users.', 'integrate-umami' ),
__( '<b>Note</b>: This will use session storage, so you may need to inform your users.', 'integrate-umami' ),
[
'b' => [],
]
Expand Down
20 changes: 17 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
**Contributors:** [ancocodet](https://github.com/Ancocodet) <br>
**Tags:** analytics,umami <br>
**Requires at least:** 5.0 <br>
**Tested up to:** 6.3.1 <br>
**Stable tag:** 0.5.0 <br>
**Tested up to:** 6.4.2 <br>
**Stable tag:** 0.6.0 <br>
**Requires PHP:** 7.0 <br>
**License:** GPLv3 or later <br>
**License URI:** https://github.com/Ancocodet/wp-umami/blob/main/LICENSE.md <br>
Expand All @@ -19,8 +19,12 @@ Umami is a simple, fast, website analytics tool for those who care about privacy

* If you don’t know how to install a plugin for WordPress, here’s how.

1. Upload the plugin files to the `/wp-content/plugins/integrate-umami` directory, or install the plugin through the WordPress plugins screen directly.
2. Activate the plugin through the ‘Plugins’ screen in WordPress
3. Follow the Setup Tracking instructions

### Setup Tracking ###
1. [Add your wordpress to umami](https://umami.is/docs/add-a-website)
1. [Add your WordPress-Site to umami](https://umami.is/docs/add-a-website)
2. Go to the Plugin Settings
3. Fill in the websiteId and ScriptUrl
* websiteId can be found in the website settings
Expand All @@ -36,13 +40,23 @@ Umami is a simple, fast, website analytics tool for those who care about privacy
* Active Development of this plugin is handled [on Github](https://github.com/Ancocodet/wp-umami).
* Pull requests for documented [issues](https://github.com/Ancocodet/wp-umami/issues) are highly appreciated.

## Roadmap ##

* Add easier setup using the umami API
* Add dashboard widget for analytics
* Add filter for adding custom tracking data/events

## Upgrade Notice ##

- **0.4.1** - Host URL Issue <br>
Issues with the settings page were fixed and the overall feeling of the page was improved as well.

## Changelog ##

- **0.6.0** - Event Tracking<br>
<br>Added tracking data-attribute for comments
<br><br>

- **0.5.0** - Documentation and plugin action<br>
<br>Added link to Settings Page to Plugin actions
<br>Change Settings page slug to plugin slug (**integrate-umami**)
Expand Down
Loading

0 comments on commit 1cde11c

Please sign in to comment.