Skip to content

Commit

Permalink
Merge branch 'release/v1.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
octfx committed Dec 14, 2023
2 parents 0c97ebc + 35424f8 commit d36aa56
Show file tree
Hide file tree
Showing 33 changed files with 1,696 additions and 173 deletions.
74 changes: 74 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: CI

on:
push:
branches: [ master, develop ]
pull_request:
branches: [ "*" ]

jobs:
test:
name: "PHPUnit: MW ${{ matrix.mw }}, PHP ${{ matrix.php }}"
continue-on-error: ${{ matrix.experimental }}

strategy:
matrix:
include:
- mw: 'REL1_39'
php: 8.1
experimental: false
- mw: 'REL1_40'
php: 8.1
experimental: true
- mw: 'master'
php: 8.1
experimental: true

runs-on: ubuntu-latest

defaults:
run:
working-directory: mediawiki

steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: mbstring, intl
tools: composer

- name: Cache MediaWiki
id: cache-mediawiki
uses: actions/cache@v3
with:
path: |
mediawiki
!mediawiki/extensions/
!mediawiki/vendor/
key: mw_${{ matrix.mw }}-php${{ matrix.php }}-v20

- name: Cache Composer cache
uses: actions/cache@v3
with:
path: ~/.composer/cache
key: composer-php${{ matrix.php }}

- uses: actions/checkout@v3
with:
path: EarlyCopy

- name: Install MediaWiki
if: steps.cache-mediawiki.outputs.cache-hit != 'true'
working-directory: ~
run: bash EarlyCopy/.github/workflows/installWiki.sh ${{ matrix.mw }}

- uses: actions/checkout@v3
with:
path: mediawiki/extensions/Plausible

- name: Composer update
run: composer update

- name: Run PHPUnit
run: composer phpunit:entrypoint -- --group Plausible
36 changes: 36 additions & 0 deletions .github/workflows/installWiki.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#! /bin/bash

MW_BRANCH=$1
EXTENSION_NAME=$2

wget https://github.com/wikimedia/mediawiki/archive/$MW_BRANCH.tar.gz -nv

tar -zxf $MW_BRANCH.tar.gz
mv mediawiki-$MW_BRANCH mediawiki

cd mediawiki

composer install
php maintenance/install.php --dbtype sqlite --dbuser root --dbname mw --dbpath $(pwd) --pass AdminPassword WikiName AdminUser

# echo 'error_reporting(E_ALL| E_STRICT);' >> LocalSettings.php
# echo 'ini_set("display_errors", 1);' >> LocalSettings.php
echo '$wgShowExceptionDetails = true;' >> LocalSettings.php
echo '$wgShowDBErrorBacktrace = true;' >> LocalSettings.php
echo '$wgDevelopmentWarnings = true;' >> LocalSettings.php

echo 'wfLoadExtension( "Plausible" );' >> LocalSettings.php

cat <<EOT >> composer.local.json
{
"require": {
},
"extra": {
"merge-plugin": {
"merge-dev": true,
"include": []
}
}
}
EOT
38 changes: 38 additions & 0 deletions .github/workflows/lint-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Lint Tests
on:
push:
branches: [ master, develop, feature/** ]
pull_request:
branches: [ master ]
jobs:
lint-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Installing PHP
uses: shivammathur/setup-php@master
with:
php-version: '8.0'
- name: Get Composer Cache Directory 2
id: composer-cache
run: |
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- uses: actions/cache@v3
id: actions-cache
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- name: Cache PHP dependencies
uses: actions/cache@v3
id: vendor-cache
with:
path: vendor
key: ${{ runner.OS }}-build-${{ hashFiles('**/composer.lock') }}
- name: Composer install
if: steps.vendor-cache.outputs.cache-hit != 'true'
run: composer install --no-ansi --no-interaction --no-scripts --no-suggest --prefer-dist
- name: Run Test
run: composer run test
107 changes: 74 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,55 +17,75 @@ $wgPlausibleApikey = ''; // Only necessary when using Extension:PageViewInfo
* Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.

## Configuration
| Key | Description | Example | Default |
|-----------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------|---------|
| $wgPlausibleDomain | Plausible Domain. **Required** | https://plausible.io | null |
| $wgPlausibleDomainKey | Domain Key set on the plausible website. **Required** | plausible.io | null |
| $wgPlausibleHonorDNT | Honor the Do Not Track header and disable tracking. | false | true |
| $wgPlausibleTrackOutboundLinks | Enable Tracking of outbound link clicks. | true | false |
| $wgPlausibleTrackFileDownloads | Enable Tracking of link clicks that lead to files, sending a `File Download` event. See [the official docs](https://plausible.io/docs/file-downloads-tracking). | true | false |
| $wgPlausibleTrackFileDownloadExtensions | List of additional file extensions to track. See [the official docs](https://plausible.io/docs/file-downloads-tracking#which-file-types-are-tracked). | ['js', 'py'] | [] |
| $wgPlausibleTrackLoggedIn | Enable Tracking for logged in users. | true | false |
| $wgPlausibleEnableCustomEvents | Enable to add the global `window.plausible` function needed for custom event tracking. | true | false |
| $wgPlausibleIgnoredTitles | List of page titles that should not be tracked. [Examples](https://github.com/plausible/docs/blob/master/docs/excluding-pages.md#common-use-cases-and-examples). | ['/Page1', '/Special:*', ] | [] |
| $wgPlausibleEnableOptOutTag | Enables or disables the `<plausible-opt-out />` tag that allows users to opt-out from being tracked. | false | true |
| $wgPlausibleApiKey | Auth Bearer key for integration with [Extension:PageViewInfo](https://www.mediawiki.org/wiki/Extension:PageViewInfo) | | |
| Key | Description | Example | Default |
|-----------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------|---------|
| $wgPlausibleDomain | Plausible Domain. **Required** | https://plausible.io | null |
| $wgPlausibleDomainKey | Domain Key set on the plausible website. **Required** | plausible.io | null |
| $wgPlausibleApiKey | Auth Bearer key for integration with [Extension:PageViewInfo](https://www.mediawiki.org/wiki/Extension:PageViewInfo) | | |
| $wgPlausibleHonorDNT | Honor the Do Not Track header and disable tracking. | false | true |
| $wgPlausibleTrackOutboundLinks | Enable Tracking of outbound link clicks. | true | false |
| $wgPlausibleTrackFileDownloads | Enable Tracking of link clicks that lead to files, sending a `File Download` event. See [the official docs](https://plausible.io/docs/file-downloads-tracking). | true | false |
| $wgPlausibleTrackFileDownloadExtensions | List of additional file extensions to track. See [the official docs](https://plausible.io/docs/file-downloads-tracking#which-file-types-are-tracked). | ['js', 'py'] | [] |
| $wgPlausibleTrackLoggedIn | Enable Tracking for logged in users. | true | false |
| $wgPlausibleEnableTaggedEvents | Enable click tracking via css classes. See [the official docs](https://plausible.io/docs/custom-event-goals#2-add-a-css-class-name-to-the-element-you-want-to-track-on-your-site). | true | false |
| $wgPlausibleIgnoredTitles | List of page titles that should not be tracked. [Examples](https://github.com/plausible/docs/blob/master/docs/excluding-pages.md#common-use-cases-and-examples). | ['/Page1', '/Special:*', ] | [] |
| $wgPlausibleEnableOptOutTag | Enables or disables the `<plausible-opt-out />` tag that allows users to opt-out from being tracked. | false | true |


### Included tracking scripts
The following tracking modules can be activated by setting the provided configuration key in `LocalSettings.php` to true.

| Key | Description | EventName |
|-------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------|
| $wgPlausibleTrack404 | Sends a `404` event for unknown titles. | `404` |
| $wgPlausibleTrackSearchInput | Send inputs to `#searchInput` to plausible as a custom event named `SearchInput`. | `SearchInput` |
| $wgPlausibleTrackEditButtonClicks | Track clicks to `#ca-edit a` as a custom event named `EditButtonClick`. | `EditButtonClick` |
| $wgPlausibleTrackNavplateClicks | Track clicks to links inside `.navplate` elements. | `Navplate: Click` |
| $wgPlausibleTrackInfoboxClicks | Track clicks to links inside `.mw-capiunto-infobox` elements. | `Infobox: Click` |
| $wgPlausibleTrackCitizenSearchLinks | Only for [Skin:Citizen](https://github.com/StarCitizenTools/mediawiki-skins-Citizen). Track clicks to search result links found in `#typeahead-suggestions`. Event is named `CitizenSearchLinkClick`. | `CitizenSearchLinkClick` |
| $wgPlausibleTrackCitizenMenuLinks | Only for [Skin:Citizen](https://github.com/StarCitizenTools/mediawiki-skins-Citizen). Track clicks to links in the sidebar menu. Event is named `CitizenMenuLinkClick`. | `CitizenMenuLinkClick` |
| Key | Description | Event Name |
|-------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------|
| $wgPlausibleTrack404 | Sends a `404` event for unknown titles. | `404` |
| $wgPlausibleTrackSearchInput | Send inputs to `#searchInput` to plausible as a custom event named `Search: Input`. | `Search: Input` |
| $wgPlausibleTrackEditButtonClicks | Track clicks to `#ca-edit a` as a custom event named `Edit Button: Click`. | `Edit Button: Click` |
| $wgPlausibleTrackNavplateClicks | Track clicks to links inside `.navplate` elements. | `Navplate: Click` |
| $wgPlausibleTrackInfoboxClicks | Track clicks to links inside `.mw-capiunto-infobox` and `.infobox` elements. | `Infobox: Click` |
| $wgPlausibleTrackCitizenSearchLinks | Only for [Skin:Citizen](https://github.com/StarCitizenTools/mediawiki-skins-Citizen). Track clicks to search result links found in `#typeahead-suggestions`. Event is named `Citizen: Search Link Click`. | `Citizen: Search Link Click` |
| $wgPlausibleTrackCitizenMenuLinks | Only for [Skin:Citizen](https://github.com/StarCitizenTools/mediawiki-skins-Citizen). Track clicks to links in the sidebar menu. Event is named `Citizen: Menu Link Click`. | `Citizen: Menu Link Click` |

### Server Side Tracking
Some events can be sent serverside without having to rely on the included plausible client script.

The following custom events can be activated:
```php
# Default Configuration
$wgPlausibleServerSideTracking = [
// Event Name: pageview
'pageview' => false,
// Event Name: 404
'page404' => false,
'pageedit' => true,
'pagedelete' => true,
'pageundelete' => true,
'pagemove' => true,
'userregister' => true,
'userlogin' => true,
'userlogout' => true,
'fileupload' => true,
'filedelete' => true,
'fileundelete' => true,
// Event Name: Page: Edit
'pageedit' => true, // Page has been successfully edited
// Event Name: Page: Delete
'pagedelete' => true, // Page has been deleted
// Event Name: Page: Undelete
'pageundelete' => true, // Page has been undeleted
// Event Name: Page: Move
'pagemove' => true, // Page was moved
// Event Name: User: Register
'userregister' => false, // A new user registered
// Event Name: User: Login
'userlogin' => false, // A user logged in
// Event Name: User: Logout
'userlogout' => false, // A user logged out
// Event Name: File: Upload
'fileupload' => true, // A file was uploaded
// Event Name: File: Delete
'filedelete' => true, // A file was deleted
// Event Name: File: Undelete
'fileundelete' => true, // A file was undeleted
// Event Name: Search: Not found
'searchnotfound' => true, // A searched term was not found / has no title on the wiki
// Event Name: Search: Found
'searchfound' => true, // A searched term was found / has a corresponding title on the wiki
];
```

### Event / Goal Names
This extension chooses the following convention for naming events / goals: `Subject: Event/Action`.

## Tracking Custom Events
https://github.com/plausible/docs/blob/master/docs/custom-event-goals.md

Expand All @@ -80,10 +100,31 @@ if (typeof window.plausible === 'undefined') {
}

document.querySelector('#ca-edit a').addEventListener('click', function (event) {
plausible('Editbtn Clicked');
plausible('Edit Button: Click');
});
```

### Via css classes
With setting `$wgPlausibleEnableTaggedEvents = true;` click to elements can be tracked by setting css classes.
From [the official docs](https://plausible.io/docs/custom-event-goals):
> You can also add class names directly in HTML
> If you can edit the raw HTML code of the element you want to track, you can also add the classes directly in HTML. For example:
>
> ```<!-- before -->```
> ```<button>Click Me</button>```
> ```<!-- after -->```
> ```<button class="plausible-event-name=Button+Click">Click Me</button>```
>
> Or if your element already has a class attribute, just separate the new ones with a space:
>
> ```<!-- before -->```
> ```<button class="some-existing-class">Click Me</button>```
>
> ```<!-- after -->```
> ```<button class="some-existing-class plausible-event-name=Button+Click">Click Me</button>```
> When you send custom events to Plausible, they won't show up in your dashboard automatically. You'll have to configure the goal for the conversion numbers to show up.
## Ignoring Pages
https://github.com/plausible/docs/blob/master/docs/excluding-pages.md#common-use-cases-and-examples

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "octfx/plausible",
"version": "1.3.1",
"version": "1.4.0",
"type": "mediawiki-extension",
"description": "Integrates plausible analytics",
"homepage": "https://www.mediawiki.org/wiki/Extension:Plausible",
Expand All @@ -13,7 +13,7 @@
}
],
"require": {
"php": ">=7.2",
"php": ">=8.0",
"ext-json": "*",
"composer/installers": ">=1.0.1"
},
Expand Down
Loading

0 comments on commit d36aa56

Please sign in to comment.