-
Notifications
You must be signed in to change notification settings - Fork 286
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
Enhance/#7573 - Add create-custom-dimension
datapoint
#7622
Enhance/#7573 - Add create-custom-dimension
datapoint
#7622
Conversation
Build files for ecdb3a9 have been deleted. |
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.
Hi @hussain-t, nice work here so far. I have left a few comments, please take a look.
In addition, with regard to the QAB - which does go into a nice amount of detail in general - it could use a bit of clarification with regard to how to retrieve the Nonce value. Also, the point about replacing the [REPLACE_WITH_COOKIE]
placeholder is a little bit confusing, as it mentions including the wordpress_logged_in
cookie value, whereas in fact we'd want to include the full wordpress_logged_in
key/value pair here. That said, if running the snippet from the devtools of a browser which is logged in to Site Kit, this cookie property can be omitted entirely as the existing cookies will be sent by the browser...
includes/Modules/Analytics_4.php
Outdated
); | ||
} | ||
|
||
$custom_dimention_data = $data['customDimension']; |
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.
Typo (here and where the variable is used):
$custom_dimention_data = $data['customDimension']; | |
$custom_dimension_data = $data['customDimension']; |
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.
Updated ✅
includes/Modules/Analytics_4.php
Outdated
// If the scope is not set or is not `EVENT`, set it to `EVENT`. | ||
if ( empty( $custom_dimention_data['scope'] ) || 'EVENT' !== $custom_dimention_data['scope'] ) { | ||
$custom_dimention_data['scope'] = 'EVENT'; | ||
} |
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.
Hmm, I must say I'm not convinced this is the best way to approach the validation of this required property. Silently coercing the invalid value here could lead to unexpected behaviour from the front end perspective when using the endpoint.
Tbh I'd be more inclined to simply check that scope
exists and its value is valid for the DimensionScope
enum, making this a fairly transparent pass-through to the GA4 endpoint.
Then, we can enforce sending EVENT
in the front end, while still getting warned by the back end if we accidentally make a request for something else...
Alternatively, to save the front end having to send EVENT
every time, we could default to EVENT
in the case where the property is not supplied, but I'd still prefer to avoid coercing a non-EVENT
value, for the reasons above.
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.
That's a good point. However, we will be using only the EVENT
scope, at least for this phase. Anyways, I will validate against the available enum.
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.
Updated ✅
includes/Modules/Analytics_4.php
Outdated
$custom_dimension->setScope( $custom_dimention_data['scope'] ); | ||
$custom_dimension->setDisallowAdsPersonalization( $custom_dimention_data['disallowAdsPersonalization'] ); | ||
|
||
/* @var Google_Service_GoogleAnalyticsAdmin $analyticsadmin phpcs:ignore Squiz.PHP.CommentedOutCode.Found */ |
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.
Hmm, I think this has been copy/pasted from similar lines elsewhere in the file, but it doesn't look to me like phpcs:ignore Squiz.PHP.CommentedOutCode.Found
is needed here. Could you please confirm this, and if so could you also remove it elsewhere in the file where it's redundantly used in a similar context?
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.
Removed ✅
// Verify the custom dimension is returned by checking all field values. | ||
foreach ( $response_array as $key => $value ) { | ||
$this->assertEquals( $value, $response_array[ $key ] ); | ||
} |
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.
This assertion doesn't make sense - you're essentially just comparing $response
to itself. What you need to do is add support for the /v1beta/properties/$property_id/customDimensions
path to the fake HTTP handler returned by create_fake_http_handler()
, returning a mock CustomDimension
object from there, and then verify one or more of the expected values from the mock object here.
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.
That's a valid point 👍
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.
Updated ✅
Thanks, @techanvil. I'm unable to create a request without the Update: I have updated the QAB. |
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.
Hey @hussain-t, thanks for the update to the code and QAB. There's just one last point to address - and, sorry if I was a bit unclear in my previous review, we could have probably saved a round trip. Nearly there, though!
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.
LGTM, nice one @hussain-t!
Summary
Addresses issue:
Relevant technical choices
PR Author Checklist
Do not alter or remove anything below. The following sections will be managed by moderators only.
Code Reviewer Checklist
Merge Reviewer Checklist