Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions .github/actions/owa-server/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ runs:
# a name rather than an address, as screenshots and docs show it
echo "127.0.0.1 owa.test" | sudo tee -a /etc/hosts > /dev/null
mysql -h 127.0.0.1 -uroot -proot -e 'CREATE DATABASE IF NOT EXISTS owa'
(cd "$OWA_DIR" && php cli.php cmd=install user_id=admin email_address=admin@example.test domain="${{ inputs.domain }}")
# 2.0 renamed cmd=install to cmd=core-install
INSTALL=install
if grep -q "'core-install'" "$OWA_DIR/modules/Base/config/cli_commands.php" 2>/dev/null; then INSTALL=core-install; fi
(cd "$OWA_DIR" && php cli.php cmd=$INSTALL user_id=admin email_address=admin@example.test domain="${{ inputs.domain }}")
q() { mysql -h 127.0.0.1 -uroot -proot owa -N -B -e "$1"; }
{
echo "OWA_URL=http://owa.test:8080/"
Expand All @@ -91,9 +94,10 @@ runs:
shell: bash
working-directory: ${{ runner.temp }}/owa
run: |
# php -S is plain http, and v2 refuses application passwords over http by default
php -r '$f = $argv[1]; file_put_contents( $f, preg_replace( "/\?>\s*$/", "\$this->set( \"base\", \"app_passwords_require_https\", false );\n?>\n", file_get_contents( $f ) ) );' owa-config.php
TOKEN=$(php cli.php cmd=app-password-create user=admin name=wp-plugin-ci scope=read | grep -oE '\b[0-9A-Za-z]{44}\b' | tail -n 1)
# php -S is plain http, and 2.x refuses application passwords over http by
# default. The setting is stored (owa-config.php may not use $this in 2.0).
php -r 'define( "OWA_CLI", true ); require "owa.php"; new owa( [ "request_type" => "cli" ] ); exit( \OWA\Core\CoreAPI::persistSetting( "base", "app_passwords_require_https", false ) ? 0 : 1 );'
TOKEN=$(php cli.php cmd=app-password-create user=admin name=wp-plugin-ci | grep -oE '\b[0-9A-Za-z]{44}\b' | tail -n 1)
[ -n "$TOKEN" ] || { echo "no application password minted"; exit 1; }
echo "::add-mask::$TOKEN"
echo "OWA_APP_PASSWORD=$TOKEN" >> "$GITHUB_ENV"
Expand Down
13 changes: 7 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ jobs:
run: bin/check-package.sh

# The plugin against a real OWA server: the tracker is served where the tag
# loads it, and the signed GET /base/v1/sites answers the Website ID picker.
# loads it, GET /base/v1/sites answers the Website ID picker, and the version
# probe identifies the server.
integration:
name: OWA ${{ matrix.owa }}
runs-on: ubuntu-latest
Expand All @@ -76,10 +77,10 @@ jobs:
- owa: '1.14.0'
release: '1.14.0'
groups: 'owa1'
- owa: 'v2'
branch: 'v2'
# v2 still takes the 1.x keys; owa2 is the bundle tag and app passwords
groups: 'owa1,owa2'
- owa: 'master'
branch: 'master'
# 2.x refuses the 1.x keys: the bundle tag and app passwords
groups: 'owa2'
services:
mysql:
image: mysql:8.0
Expand Down Expand Up @@ -142,7 +143,7 @@ jobs:
run: composer install --no-interaction --no-progress
- uses: ./.github/actions/owa-server
with:
branch: v2
branch: master
app-passwords: 'true'
domain: https://wp.test
profiles: |
Expand Down
Binary file modified .wordpress-org/screenshot-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .wordpress-org/screenshot-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .wordpress-org/screenshot-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .wordpress-org/screenshot-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .wordpress-org/screenshot-5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Adds Open Web Analytics (OWA) tracking to WordPress sites and multisite networks.

- OWA 1.x (API key) and 2.x (application password and tracking bundle, beta)
- OWA 1.x (API key) and 2.x (application password and tracking bundle, beta), detected from the server; the settings page shows only the detected version's settings
- Multisite network mode for OWA 2.x: one server and password for the network, an Observation Profile and tracking switch per site
- Fires `owa_wp_tag_changed` when a site's tag changes, so page caches can purge; Proxy Cache Purge does

Expand Down
30 changes: 22 additions & 8 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ Adds the Open Web Analytics (OWA) tracking tag to your site's public pages. Requ

= OWA 1.x and 2.x =

Choose the server version under OWA > Settings.
The plugin detects which version the OWA server at the OWA Server Endpoint runs and shows only the settings for that version.

* **1.x** authenticates with an OWA user's API key and the server's Secret Auth Key. Tracker options are set in WordPress.
* **2.x (beta)** authenticates with an OWA application password and loads the Observation Profile's tracking bundle. Tracker options are set on the OWA server; the settings page links to them.
* **2.x (beta)** authenticates with an OWA application password and loads the Observation Profile's tracking bundle. Click tracking and Domstreams are set on the OWA server; the settings page links to them.

To set up, enter the OWA Server Endpoint and click Check. That version's settings appear, and Save Changes appears once its credentials are entered. The version is checked again when the endpoint is saved, once a day when an administrator opens an admin page, and with Check again. When a 1.x server is upgraded to 2.x, the dashboard, Plugins screen and settings page ask for an application password. Tracking continues meanwhile.

= What is tracked =

Expand All @@ -46,19 +48,23 @@ A cached page keeps the tracking tag it was rendered with. When a site's tag cha

1. Install and activate the plugin.
2. Go to OWA > Settings.
3. Enter your OWA server's URL as the OWA Endpoint. Saving checks that OWA answers there and stores the URL it answers at, after any redirect. Without `https://` or `http://`, https is tried first, then http.
4. Enter the credentials:
3. Enter your OWA server's URL as the OWA Server Endpoint and click Check. Check finds OWA there, uses the URL it answers at (after any redirect), and detects the OWA version. Without `https://` or `http://`, https is tried first, then http.
4. Enter the credentials the page now asks for:
* 1.x: the API Key (OWA: Settings > Users > Edit) and the Secret Auth Key (`OWA_AUTH_KEY` in the server's `owa-config.php`).
* 2.x: select 2.x and enter an Application Password (OWA: My Preferences > Application Passwords). A read-only password is enough.
* 2.x: an Application Password (OWA: My Preferences > Application Passwords). A read-only password is enough.
5. Save. Once OWA accepts the credentials, the Observation Profile list appears: select the one to track and save again. The plugin stores its site ID; in 1.x the field is labeled Website ID.

On a multisite network, set up OWA 2.x once under Network Admin > OWA.
On a multisite network, set up OWA 2.x once under Network Admin > OWA. A 1.x server is refused there.

== Frequently Asked Questions ==

= The settings page shows only the OWA Server Endpoint =

The URL has not been checked yet, or the OWA server did not answer. The page shows why. The plugin requests `api/index.php` under the OWA Server Endpoint, so OWA's REST API has to answer there.

= No tracking tag appears =

The tag is added once Enable OWA is on and the OWA Endpoint and Observation Profile are saved. Your theme must call `wp_head()`.
The tag is added once Enable OWA is on and the OWA Server Endpoint and Observation Profile are saved. Your theme must call `wp_head()`.

= The Observation Profiles do not load over http =

Expand All @@ -68,14 +74,22 @@ Application passwords are sent only over https. To use an http OWA server, turn

== Screenshots ==

1. Settings for OWA 1.x.
1. Setup starts with the OWA server's URL and Check.
2. Settings for OWA 2.x.
3. Network Admin > OWA: each site's Observation Profile and tracking switch.
4. A site whose Observation Profile the network sets.
5. A site choosing from the Observation Profiles that share its domain.

== Changelog ==

= 2.5.0 =

* The OWA Server Version setting is gone. The plugin detects the version at the OWA Server Endpoint and shows only that version's settings; until a version is detected, only the OWA Server Endpoint and Check. It checks with Check, when the endpoint is saved, and once a day on admin page loads. If the server does not answer, the version found there before is kept and the page says so.
* After updating, the first admin page load checks the server and replaces the version chosen before. If the server does not answer, the version chosen before is kept.
* A 1.x server upgraded to 2.x: the dashboard, Plugins screen and settings page ask for an application password (dismissible). The 1.x keys stay stored, and tracking continues with the 2.x tag.
* The Application Password field links to OWA's documentation.
* Network Admin > OWA refuses an OWA Server Endpoint that identifies as 1.x.

= 2.4.1 =

* Don't Track Logged-in Users: a logged-in user now gets the tracker paused instead of no tracker, so OWA's heatmap and Domstream player open on the site. Nothing is sent to OWA for them, but their browser still loads the tracker from the OWA server. Admin pages still get no tracker.
Expand Down
2 changes: 1 addition & 1 deletion bin/check-package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ rsync -rc --exclude-from="$root/.distignore" "$root/" "$out/"

fail=0

for path in owa-plugin.php README.txt src/module.php src/rest.php src/admin.php src/network.php \
for path in owa-plugin.php README.txt src/module.php src/rest.php src/admin.php src/network.php src/server.php \
vendor/autoload.php vendor/open-web-analytics/owa-php-sdk/src/sdk.php \
build/settings.js build/settings.asset.php build/network.js build/network.asset.php build/style-settings.css; do
[ -e "$out/$path" ] || { echo "missing from package: $path"; fail=1; }
Expand Down
89 changes: 80 additions & 9 deletions js/lib/fields.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,107 @@
/**
* Which fields and tabs the site settings page shows.
*
* A field tagged with a server version ("1" or "2") shows only while that
* version is chosen. A field the network manages is hidden, unless it is shown
* read-only (the Website ID the network assigned).
* The version is the one the server detected at the saved endpoint ("1" or
* "2"), or "" while none is known: then only the endpoint shows. A field
* tagged with a version shows only for that version. A field the network
* manages is hidden, unless it is shown read-only (the Website ID the network
* assigned).
*/
export function isVisible( field, version ) {
if ( field.managed && ! field.readonly ) {
return false;
}
if ( ! version ) {
return field.type === 'url';
}
return ! field.version || field.version === version;
}

export function visibleFields( fields, version, section ) {
return fields.filter( ( field ) => isVisible( field, version ) && ( ! section || field.section === section ) );
}

/** A field's title and description for the chosen version: 2.x has its own wording for some. */
/** A field's title and description for the detected version: 2.x has its own wording for some. */
export function fieldText( field, version ) {
const v2 = version === '2' ? field.v2 || {} : {};
return { title: v2.title || field.title, description: v2.description || field.description };
}

/**
* What is left to set up, as the server found it in the saved settings,
* worded for the version chosen on the page; none while tracking is off.
* What is left to set up, as the server found it in the saved settings; none
* while tracking is off.
*/
export function setupNotices( payload, values ) {
if ( ! Number( values.enable ) ) {
return [];
}
return ( payload.notices || {} )[ values.owaVersion === '2' ? '2' : '1' ] || [];
return payload.notices || [];
}

/**
* The server the page shows: the saved endpoint's (payload.server) while the
* field holds the saved URL; else the result of checking what the field
* holds ($checked), while it still holds that; else one not checked yet.
*/
export function shownServer( payload, values, checked ) {
const url = values.owaEndpoint || '';
if ( payload.server.network || url === payload.server.url ) {
return payload.server;
}
if ( checked && checked.url === url ) {
return checked;
}
return { version: '', url, identified: false, reason: '', checkedAt: 0, network: false, unchecked: true };
}

/**
* What the page says about the shown server:
* - "network": the network administrator manages it; nothing is said.
* - "none": no URL in the field.
* - "unchecked": a URL that is not the saved one and was not checked.
* - "unidentified": a URL, and no version was ever found there.
* - "stale": the last check found no version; the one found before is used.
* - "identified": the last check found the version shown.
*/
export function serverState( server ) {
if ( server.network ) {
return 'network';
}
if ( ! server.url ) {
return 'none';
}
if ( server.unchecked ) {
return 'unchecked';
}
if ( ! server.version ) {
return 'unidentified';
}
return server.identified ? 'identified' : 'stale';
}

/**
* Whether Save Changes shows. Emptying a saved endpoint can always be saved.
* Otherwise the server has to be identified, and for a URL that is not the
* saved one (a new setup, or another server) its version's credentials have
* to be there, saved or typed.
*/
export function canSave( payload, values, secrets, server ) {
const url = values.owaEndpoint || '';
if ( url === '' ) {
return Boolean( payload.server.url );
}
if ( ! server.version ) {
return false;
}
if ( server.network || url === payload.server.url ) {
return true;
}
return visibleFields( payload.fields, server.version )
.filter( ( field ) => field.type === 'secret' || field.type === 'app_password' )
.every( ( field ) => {
const edit = secrets[ field.key ] || {};
return Boolean( edit.value ) || ( Boolean( payload.secrets[ field.key ] ) && ! edit.clear );
} );
}

/** The tabs that have something to show. */
Expand All @@ -41,11 +112,11 @@ export function visibleSections( sections, fields, version ) {
/**
* The link to the Website ID's tracking tag screen in OWA shows only for what
* is saved: the server builds it from the saved settings, so it is hidden
* while the version, the endpoint or the Website ID differs from them.
* while the endpoint or the Website ID differs from them.
*/
export function showTagSettingsLink( payload, values ) {
return Boolean( payload.tagSettingsUrl ) &&
[ 'owaVersion', 'owaEndpoint', 'siteId' ].every( ( key ) => values[ key ] === payload.values[ key ] );
[ 'owaEndpoint', 'siteId' ].every( ( key ) => values[ key ] === payload.values[ key ] );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion js/network/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ function NetworkPage() {
<TextControl
__next40pxDefaultSize
__nextHasNoMarginBottom
label="OWA Endpoint"
label="OWA Server Endpoint"
help="The URL of your OWA 2.x server (e.g. https://owa.example.com/). Without https:// or http://, https is tried first."
type="url"
value={ endpoint }
Expand Down
Loading
Loading