Skip to content
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

Add VIP_GO_APP_ID to telemetry event data #5922

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from
2 changes: 2 additions & 0 deletions telemetry/tracks/class-tracks-event-dto.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,7 @@ class Tracks_Event_DTO {

public int $vipgo_org;

public int $vip_env_id;

public bool $is_vip_user = false;
}
9 changes: 9 additions & 0 deletions telemetry/tracks/class-tracks-event.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,15 @@ protected function process_properties(
}
}

// Set VIP app ID if it exists.
sanmai marked this conversation as resolved.
Show resolved Hide resolved
if ( defined( 'VIP_GO_APP_ID' ) ) {
// APP_ID is incorrectly named; it actually references the environment ID
$env_id = constant( 'VIP_GO_APP_ID' );
if ( is_integer( $env_id ) && $env_id > 0 ) {
$event->vip_env_id = $env_id;
}
}

// Set VIP organization if it exists.
if ( defined( 'VIP_ORG_ID' ) ) {
$org_id = constant( 'VIP_ORG_ID' );
Expand Down
4 changes: 4 additions & 0 deletions tests/telemetry/tracks/test-class-tracks-event.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class Tracks_Event_Test extends WP_UnitTestCase {

protected const VIP_ORG_ID = 17;

protected const VIP_GO_APP_ID = 2000;

private WP_User $user;

public function setUp(): void {
Expand All @@ -40,6 +42,7 @@ public function test_should_create_event() {
public function test_should_return_event_data() {
Constant_Mocker::define( 'VIP_TELEMETRY_SALT', self::VIP_TELEMETRY_SALT );
Constant_Mocker::define( 'VIP_GO_APP_ENVIRONMENT', self::VIP_GO_APP_ENVIRONMENT );
Constant_Mocker::define( 'VIP_GO_APP_ID', self::VIP_GO_APP_ID );
Constant_Mocker::define( 'VIP_ORG_ID', self::VIP_ORG_ID );

$event = new Tracks_Event( 'prefix_', 'test_event', [
Expand All @@ -60,6 +63,7 @@ public function test_should_return_event_data() {
$this->assertSame( hash_hmac( 'sha256', $this->user->user_email, self::VIP_TELEMETRY_SALT ), $event->get_data()->_ui );
$this->assertSame( 'vip:user_email', $event->get_data()->_ut );
$this->assertSame( self::VIP_GO_APP_ENVIRONMENT, $event->get_data()->vipgo_env );
$this->assertSame( self::VIP_GO_APP_ID, $event->get_data()->vip_env_id );
$this->assertSame( self::VIP_ORG_ID, $event->get_data()->vipgo_org );
$this->assertFalse( $event->get_data()->is_vip_user );
$this->assertTrue( $event->is_recordable() );
Expand Down
Loading