feat: add internal traffic IP config to tag requests with TWN-Source header#395
Open
ahuininga-orisha wants to merge 7 commits into
Open
feat: add internal traffic IP config to tag requests with TWN-Source header#395ahuininga-orisha wants to merge 7 commits into
ahuininga-orisha wants to merge 7 commits into
Conversation
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Customers and merchants often want to filter out internal traffic — such as developers, testers, or office employees — from Tweakwise Analytics reports. Because all Tweakwise API requests are server-to-server, Tweakwise only sees the Magento server's IP address, making standard IP-based filtering impossible on their end. Tweakwise provides a
TWN-Sourceheader mechanism specifically for this purpose, but it previously required custom implementation by the merchant's development team.This change adds native support for internal traffic tagging directly in the plugin. A merchant can now enter a comma-separated list of IP addresses in the Magento admin, and any Tweakwise API request triggered by a visitor matching one of those IPs will automatically include the
TWN-Source: Internal-Trafficheader. This covers all request types: navigation, search, autocomplete, recommendations, and analytics events (which are proxied through the Magento controller, not sent directly from the browser).Changes
etc/adminhtml/system.xmltextareafieldinternal_ip_addressesadded to the General group (sortOrder 120)Model/Config.phpgetInternalIpAddresses()method reads and parses the comma-separated config valueModel/Client.phpRemoteAddress; addedbuildInternalTrafficHeader()helper; applied to bothcreateGetRequest()andcreatePostRequest()README.mdHow to test
Scenario 1 — Config field visible in admin
Scenario 2 — Header sent for matching IP
127.0.0.1).bin/magento cache:clean config.gateway.tweakwisenavigator.net./default/women/tops-women2/).TWN-Source: Internal-Traffic.Scenario 3 — Header not sent for non-matching IP
10.0.0.99) in the config and save.bin/magento cache:clean config.TWN-Sourceheader.Scenario 4 — Header not sent when config is empty
bin/magento cache:clean config.TWN-Sourceheader is present on the Tweakwise request.Scenario 5 — Multiple IPs and whitespace tolerance
127.0.0.1 , 10.0.0.1 , 192.168.1.1(with extra spaces) in the config and save.bin/magento cache:clean config.TWN-Source: Internal-Trafficis sent.var/log/exception.log.Scenario 6 — Analytics events also tagged
/tweakwise/ajax/analyticsand the subsequent server-side call tonavigator-analytics.tweakwise.com.TWN-Source: Internal-Traffic.