# About

A plugin for first-party analytics.

------

## PHP

### Filters

| Name                                       | Description                                    |
|--------------------------------------------|------------------------------------------------|
| `first_party_analytics_public_assets_data` | Before assets data print (wp_localize_script). |

### Actions

| Name                                                     | Description                                                      |
|----------------------------------------------------------|------------------------------------------------------------------|
| `first_party_analytics_admin_menu_settings_tabs_printed` | After setting tabs were printed. A good spot to add custom ones. |
| `first_party_analytics_main_page_after_header_print`     | After header print. A good spot to add custom one.               |
| `first_party_analytics_add_a_new_session`                | After a new session was added.                                   |

## Env variables

| Variable                                           | Description                                            |
|----------------------------------------------------|--------------------------------------------------------|
| `FIRST_PARTY_ANALYTICS_DATA_SHARING_SEND_TOKEN_TO` | URL to which to return the token after it was request. |
| `FIRST_PARTY_ANALYTICS_DATA_SHARING_DOMAIN`        | Domain for the data sharing.                           |

## JS

### Events

| Event                                            | Target     | Description                                           | event.data                                                      |
|--------------------------------------------------|------------|-------------------------------------------------------|-----------------------------------------------------------------|
| `first-party-analytics-in-page-url-changed`      | `document` | After in-page URL changed (e.g. on the anchor click). | `'url'` - New URL.                                              | 
| `first-party-analytics-link-clicked`             | `document` | When any of the links on the website are clicked.     | `'link'` - Clicked link.                                        | 
| `first-party-analytics-before-settings-save`     | `document` | Before settings save.                                 | `'settings'` - An object of settings to save.                   | 
| `first-party-analytics-before-tab-render-finish` | `document` | Before tab render finsihed.                           | `'tabName'` - The name of the tab the render of which finished. | 
| `first-party-analytics-before-send-request`      | `document` | Before tab render finsihed.                           | `'data'` - The data that will be sent.                          | 

### Debug methods

| Method                                         | Page         | Description                   |
|------------------------------------------------|--------------|-------------------------------|
| `firstPartyAnalytics.downloadWebVitalsDebugData` | Admin / Main | Returns web vitals debug data |

## Libs

### PHP

| Name                                                                    | Description                              |
|-------------------------------------------------------------------------|------------------------------------------|
| [Parser-PHP](https://github.com/WhichBrowser/Parser-PHP)                | Parser PHP for User-Agent parsing.       |
| [maxmind-db/reader](https://github.com/maxmind/MaxMind-DB-Reader-php)   | MaxMind DB reader - for GeoLocation.     |
| [ip-lib](https://github.com/mlocati/ip-lib)                             | IP Lib - for IP ranges exclusion.        |
| [php-domain-parser](https://github.com/jeremykendall/php-domain-parser) | Public Suffix List based domain parsing. |

### JS

| Name                                                                              | Description                                                                         |
|-----------------------------------------------------------------------------------|-------------------------------------------------------------------------------------|
| [TimeMe.js](https://github.com/jasonzissman/TimeMe.js/)                           | TimeMe.js - Measure the time the user has spent on the page.                        |
| [Chart.js](https://github.com/chartjs/Chart.js)                                   | Chart.js - For charts.                                                              |
| [chartjs-plugin-datalabels](https://github.com/chartjs/chartjs-plugin-datalabels) | Chart.js plugin to display labels on data elements.                                 |
| [chroma.js](https://github.com/gka/chroma.js)                                     | Chroma.js - For palette generation for pie chart.                                   |
| [d3](https://github.com/d3/d3)                                                    | d3 - For d3-cloud.                                                                  |
| [d3-cloud](https://github.com/jasondavies/d3-cloud)                               | d3-cloud - Word cloud for searches.                                                 |
| [world-atlas](https://atomiks.github.io/tippyjs/v6/getting-started/)              | Countries map data.                                                                 |
| [topojson](https://github.com/topojson/topojson)                                  | Countries map drawing.                                                              |
| [css-path](https://gist.github.com/asfaltboy/8aea7435b888164e8563)                | A script for the retrieval of CSS selector of the element.                          |
| [Popper.js](https://popper.js.org/)                                               | Popper.js - for tippy.js                                                            |
| [TippyJS](https://atomiks.github.io/tippyjs/v6/getting-started/)                  | Tippy.js - Tooltips                                                                 |
| [web-vitals](https://github.com/GoogleChrome/web-vitals)                          | Web vitals to measure: <br/>FID (First Input Delay) = Time to Interactive; CLS; LCP |
| [lh-scorecalc](https://github.com/paulirish/lh-scorecalc)                         | Lighthouse Score Calculator                                                         |
| tmm-fpa-get-speed-score                                                           | Speed score calculation. Based on lh-scorecalc.                                     |

### Misc

| Name                                                                                                      | Description                                                                                                                                                                                                                                    | Location                                   |
|-----------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------|
| [ISO-3166-Countries-with-Regional-Codes](https://github.com/lukes/ISO-3166-Countries-with-Regional-Codes) | List of countries with ISO codes. Used for topology maps for ISO convertion between different types of codes.                                                                                                                                  | ISO-3166-Countries-with-Regional-Codes-9.0 |
| [Public suffix list](https://publicsuffix.org/list/public_suffix_list.dat)                                | A list public suffixes for domains.                                                                                                                                                                                                            | public-suffix/public_suffix_list.dat.txt   |
| [stop-words](https://github.com/snowballstem/snowball)                                                    | Stop-words for various languages. <b><br><br>Extraction:</b><br><br>1. Move extractor.php to algorithms directory.<br>2. Rename all languages to ISO 639-1 codes (https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes).<br>3. Run extractor. | stop-words/stop-words.json                 |

### When increasing PHP min version

- Update "jeremykendall/php-domain-parser" composer package.
