ampproject/amp-wp

Analytics Type lowercases on save

robertsky opened this issue · 3 comments

Issue: Upon saving, the Analytics Type indicated is saved with the string in lower case. This leads to the config for the type not detected.
Example: adobeanalytics_nativeConfig
On saving: adobeanalytics_nativeconfig

My current workaround is to use the amp_post_template_analytics filter instead. However, this issue might lead others to wonder why their analytics tag is not working properly.

Can you share the full config you are using?

Nevermind. I see it. The problem is that sanitize_key() normalizes by lower-casing.

https://github.com/Automattic/amp-wp/blob/d2b2c2dccc7a6d4ddd0a2e27bb5715c36dc33f45/includes/options/class-amp-options-manager.php#L127-L131

I suggest replacing the instances of sanitize_key( $x ) with preg_replace( '/[^a-z0-9_\-]/', '', $x ).

Apologies for not responding sooner. Glad that you have found the cause! I hope the fix would be in the codebase sometime for other users!