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 Filter hook to gtag config parameters #225

Closed
PaulSchiretz opened this issue Aug 18, 2022 · 1 comment
Closed

Add Filter hook to gtag config parameters #225

PaulSchiretz opened this issue Aug 18, 2022 · 1 comment
Labels
type: enhancement The issue is a request for an enhancement.

Comments

@PaulSchiretz
Copy link

Is your feature request related to a problem?

It would be very handy to have a filter for the parameters that are passed to the gtag config call.
Currently the gtag config call is build by the settings of the ui and plainly appended to a string.

GoogleAnalytics configurations can differ a lot, specially in times if gpdr, google signals and so on.
Currently i would like to append the cookie_flags option with a value of samesite=none;secure to my analytics config and have no possibilities to do that easily.

Describe the solution you'd like

A simple filter call with an array of the parameters that are passed to gtag config in the function public static function load_analytics( $order = false ) of the class-wc-google-gtag-js.php file.

Current Code:

gtag('config', '" . esc_js( $gtag_id ) . "', { 'allow_google_signals': " . ( 'yes' === self::get( 'ga_support_display_advertising' ) ? 'true' : 'false' ) . ", 'link_attribution': " . ( 'yes' === self::get( 'ga_support_enhanced_link_attribution' ) ? 'true' : 'false' ) . ", 'anonymize_ip': " . ( 'yes' === self::get( 'ga_anonymize_enabled' ) ? 'true' : 'false' ) . ", 'linker':{ 'domains': " . wp_json_encode( $gtag_cross_domains ) . ", 'allow_incoming': " . ( 'yes' === self::get( 'ga_linker_allow_incoming_enabled' ) ? 'true' : 'false' ) . ", }, 'custom_map': { 'dimension1': 'logged_in' }, 'logged_in': '$logged_in' } );

It would be really nice if we could build the config call from a key-value array and filter it before converting it to the config json string.
I believe this is a simple and backward compatible solution that can be useful in many situations, like adding params, editing params and so on....

Something like:
woocommerce_gtag_config_params($arrayofparams)

Describe alternatives you've considered

I know there is a filter woocommerce_gtag_snippet where i could preg_replace parameters into the script output but this feels very hacky and is prone to errors.

@PaulSchiretz PaulSchiretz added the type: enhancement The issue is a request for an enhancement. label Aug 18, 2022
@martynmjones
Copy link
Contributor

As part of the upcoming version 2.0.0 release, we have implemented Consent mode and a filter for the default configuration.

Additional calls can be included by adding an inline script using the woocommerce-google-analytics-integration handle so I'm marking this issue as closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement The issue is a request for an enhancement.
Projects
None yet
Development

No branches or pull requests

2 participants