-
Notifications
You must be signed in to change notification settings - Fork 36
Instrument connection, sync, settings, media, cache, features, and deactivation analytics events #1226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gabrielcld2
wants to merge
19
commits into
develop
Choose a base branch
from
feature/custom-events-tracking
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Instrument connection, sync, settings, media, cache, features, and deactivation analytics events #1226
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
e6e4774
Merge branch 'master' into uat
gabriel-detassigny 111318f
Merge pull request #1205 from cloudinary/develop
gabrielcld2 48286c1
Merge pull request #1206 from cloudinary/uat
gabrielcld2 018fcc1
Pass version explicitly to the release GH action
gabriel-detassigny 603fe2f
Instrument connection, sync, settings, media, cache, features, and de…
gabriel-detassigny 9593d81
Rebuild JS bundles for the new analytics call sites
gabriel-detassigny 385d11b
Merge remote-tracking branch 'origin/develop' into feature/custom-eve…
gabriel-detassigny 330e67b
Add Analytics to get_component()'s return type for phpstan level 5
gabriel-detassigny 0a787d2
Fix Image_Preview's placeholder src causing a self-fetch on every pag…
gabriel-detassigny ba269c6
Merge remote-tracking branch 'origin/develop' into feature/custom-eve…
gabriel-detassigny 55fb9f3
Rebuild JS bundles for the new analytics call sites
gabriel-detassigny 1531459
Continue analytics implementation
gabriel-detassigny c98e6d7
Automate sync category e2e coverage
gabriel-detassigny da72772
Automate media category e2e coverage
gabriel-detassigny 1e1dd5a
Automate cache category e2e coverage
gabriel-detassigny 72fd7ec
Automate features category e2e coverage
gabriel-detassigny f2db431
Add e2e coverage for connection_disconnected, deactivation_submitted,…
gabriel-detassigny 5d0f0ac
Preempt real analytics/deactivation-feedback traffic from test runs; …
gabriel-detassigny cac149e
Make asset_cache_purged test deterministic instead of relying on page…
gabriel-detassigny File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| <?php | ||
| /** | ||
| * Analytics egress capture — local/e2e dev helper mu-plugin. | ||
| * | ||
| * Intercepts outgoing requests to any Cloudinary analytics-api.cloudinary.com | ||
| * endpoint — the custom-events collector AND the older deactivation-reason | ||
| * collector, both on the same host — and appends each payload as a JSONL | ||
| * entry to a log file, so e2e tests and manual QA can assert on emitted | ||
| * events. The request is fully preempted with a synthetic response: earlier | ||
| * versions of this mu-plugin only logged the payload and let the request | ||
| * proceed, which meant every local/CI test run was quietly leaking synthetic | ||
| * events (and deactivation "feedback") into the real production collector. | ||
| * | ||
| * @package Cloudinary | ||
| */ | ||
|
|
||
| defined( 'ABSPATH' ) || exit; | ||
|
|
||
| /** | ||
| * Returns the path to the capture log file. | ||
| * | ||
| * @return string | ||
| */ | ||
| function cld_analytics_capture_log_path() { | ||
| $upload = wp_upload_dir(); | ||
|
|
||
| return $upload['basedir'] . '/analytics-capture.log'; | ||
| } | ||
|
|
||
| add_filter( 'pre_http_request', 'cld_analytics_capture_intercept', 10, 3 ); | ||
|
|
||
| /** | ||
| * Logs outgoing analytics/deactivation-reason requests and preempts them | ||
| * with a synthetic success response, so nothing actually reaches the real | ||
| * collector during local dev or CI runs. | ||
| * | ||
| * @param false|array|WP_Error $preempt Whether to preempt the request. | ||
| * @param array $parsed_args Parsed request arguments. | ||
| * @param string $url The request URL. | ||
| * | ||
| * @return false|array|WP_Error | ||
| */ | ||
| function cld_analytics_capture_intercept( $preempt, $parsed_args, $url ) { | ||
| if ( false === strpos( $url, 'analytics-api.cloudinary.com' ) ) { | ||
| return $preempt; | ||
| } | ||
|
|
||
| $body = isset( $parsed_args['body'] ) ? $parsed_args['body'] : ''; | ||
| $decoded = json_decode( $body, true ); | ||
|
|
||
| file_put_contents( // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_file_put_contents, WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_file_put_contents | ||
| cld_analytics_capture_log_path(), | ||
| wp_json_encode( null !== $decoded ? $decoded : $body ) . "\n", | ||
| FILE_APPEND | LOCK_EX | ||
| ); | ||
|
|
||
| return array( | ||
| 'headers' => array(), | ||
| 'body' => '', | ||
| 'response' => array( | ||
| 'code' => 200, | ||
| 'message' => 'OK', | ||
| ), | ||
| 'cookies' => array(), | ||
| 'filename' => null, | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Prints the captured analytics events, one JSON object per line. | ||
| * | ||
| * ## OPTIONS | ||
| * | ||
| * [--clear] | ||
| * : Empty the log after printing it. | ||
| * | ||
| * @param array $args Positional arguments. | ||
| * @param array $assoc_args Associative arguments. | ||
| */ | ||
| function cld_analytics_capture_wpcli_command( $args, $assoc_args ) { | ||
| $log_file = cld_analytics_capture_log_path(); | ||
|
|
||
| if ( file_exists( $log_file ) ) { | ||
| WP_CLI::line( file_get_contents( $log_file ) ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents, WordPressVIPMinimum.Performance.FetchingRemoteData.FileGetContentsUnknown | ||
| } | ||
|
|
||
| if ( isset( $assoc_args['clear'] ) ) { | ||
| file_put_contents( $log_file, '' ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_file_put_contents, WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_file_put_contents | ||
| } | ||
| } | ||
|
|
||
| if ( defined( 'WP_CLI' ) && WP_CLI ) { | ||
| WP_CLI::add_command( 'cloudinary analytics-events', 'cld_analytics_capture_wpcli_command' ); | ||
| } |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| <?php return array('dependencies' => array(), 'version' => '41ae783fa52f94bc2630'); | ||
| <?php return array('dependencies' => array('wp-api-fetch'), 'version' => 'e3528eb2e86ccc7789df'); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cache_items_viewedovercounts. This fires on everyrest_get_caches()call, including each pagination step and each search keystroke-triggered request. If the spec intends "user viewed a cache point", consider tracking only page 1 / no-search requests.