Skip to content

Add tracking_token to Device request object#249

Merged
horgh merged 3 commits intomainfrom
greg/eng-4050
Feb 25, 2026
Merged

Add tracking_token to Device request object#249
horgh merged 3 commits intomainfrom
greg/eng-4050

Conversation

@oschwald
Copy link
Member

Summary

  • Add optional tracking_token field to withDevice() for explicit device linking via the Device Tracking Add-on

ENG-4050

Test plan

  • Unit tests pass (245 tests)
  • New field works with both array and named argument styles
  • Backward compatible (field is optional, defaults to null)
  • PHPUnit passes

🤖 Generated with Claude Code

@gemini-code-assist
Copy link

Summary of Changes

Hello @oschwald, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the MinFraud library by integrating support for the Device Tracking Add-on. It allows users to provide a tracking_token within the device request object, facilitating explicit device linking for fraud detection. The change is backward compatible as the new field is optional.

Highlights

  • New Feature: Device Tracking Token: Introduced an optional tracking_token field to the withDevice() method, enabling explicit device linking via the Device Tracking Add-on.
Changelog
  • CHANGELOG.md
    • Added a new entry for version 3.7.0, detailing the addition of tracking_token to the /device request object for explicit device linking.
Activity
  • Unit tests passed (245 tests).
  • Verified that the new tracking_token field functions correctly with both array and named argument styles.
  • Confirmed backward compatibility, as the field is optional and defaults to null.
  • PHPUnit tests passed successfully.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The pull request successfully adds the tracking_token field to the withDevice method, enabling explicit device linking via the Device Tracking Add-on. The changes are consistent with the existing codebase's structure and include necessary updates to documentation and tests. I have provided a few suggestions to improve input validation and maintain consistency with other token-like fields in the library.

$sessionId = (string) $v;
}

$trackingToken = $this->remove($values, 'tracking_token');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For consistency with other token-like fields such as session_id, it is recommended to validate the type when extracting tracking_token from the $values array and cast the result to a string. This ensures that the internal state remains consistent regardless of whether the method was called with named arguments or an associative array.

            $v = $this->remove($values, 'tracking_token', ['integer', 'string']);
            if ($v !== null) {
                $trackingToken = (string) $v;
            }

Comment on lines +269 to +271
if ($trackingToken !== null) {
$values['tracking_token'] = $trackingToken;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The tracking_token field has a length constraint of 1 to 255 characters according to the MaxMind minFraud API documentation. Adding client-side validation here ensures consistency with other fields like session_id and prevents invalid requests from being sent to the web service.

        if ($trackingToken !== null) {
            if ($trackingToken === '' || \strlen($trackingToken) > 255) {
                $this->maybeThrowInvalidInputException(
                    "Tracking token ($trackingToken) must be a string with length between 1 and 255",
                );
            }
            $values['tracking_token'] = $trackingToken;
        }

This adds the optional tracking_token field to the Device request
object for explicit device linking via the Device Tracking Add-on.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Remove assertEmpty() wrappers around void report() calls. Since
report() returns void, asserting on its return value is meaningless
and the @phpstan-ignore-next-line comments targeted the wrong lines.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
src/MinFraud.php Outdated
* time since the start of the first visit.
* @param string|null $sessionId An ID that uniquely identifies a visitor's
* session on the site
* @param string|null $trackingToken the tracking token generated by the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"The" perhaps?

@horgh horgh merged commit 6e9650e into main Feb 25, 2026
36 checks passed
@horgh horgh deleted the greg/eng-4050 branch February 25, 2026 21:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants