GAinWP Shortcode

Below, you’ll find a detailed guide on how to add the GAinWP Google Analytics Integration for WordPress Shortcode to your WordPress website, including its parameters, examples, and PHP function code. Additionally, we’ll assist you with common issues that might cause the GAinWP Google Analytics Integration for WordPress Plugin shortcode not to show or not to work correctly.

Before starting, here is an overview of the GAinWP Google Analytics Integration for WordPress Plugin and the shortcodes it provides:

Plugin Icon
GAinWP Google Analytics Integration for WordPress

"GAinWP Google Analytics Integration for WordPress is a powerful plugin that seamlessly integrates Google Analytics with your WordPress site. Track and analyze your website's performance effortlessly."

★★★★☆ (125) Active Installs: 10000+ Tested with: 5.5.13 PHP Version: 5.2.4
Included Shortcodes:
  • [gainwp_useroptout]

GAinWP [gainwp_useroptout] Shortcode

The ‘gainwp_useroptout’ shortcode is a function of the GA-in plugin. It allows users to opt-out of Google Analytics tracking. The shortcode checks the ‘html_tag’ attribute. If it’s ‘a’, it returns a hyperlink with the class ‘gainwp_useroptout’ and an ‘onclick’ event that triggers the ‘gaOptout()’ function. If the ‘html_tag’ attribute is ‘button’, it returns a button with the same class and event.

Shortcode: [gainwp_useroptout]

Parameters

Here is a list of all possible gainwp_useroptout shortcode parameters and attributes:

  • html_tag – determines the type of HTML element to use, either ‘a’ or ‘button’
  • content – the text to display within the HTML element

Examples and Usage

Basic Example – Displays a clickable link that allows users to opt out of Google Analytics tracking

[gainwp_useroptout html_tag="a"]Opt Out[/gainwp_useroptout]

Advanced Examples

Displays a button that allows users to opt out of Google Analytics tracking. This is useful if you want to make the opt-out option more prominent on your page.

[gainwp_useroptout html_tag="button"]Click to Opt Out[/gainwp_useroptout]

Displays a link with custom text that allows users to opt out of Google Analytics tracking. This is useful if you want to customize the text displayed to your users.

[gainwp_useroptout html_tag="a"]Click here to stop being tracked[/gainwp_useroptout]

PHP Function Code

In case you have difficulties debugging what causing issues with [gainwp_useroptout] shortcode, check below the related PHP functions code.

Shortcode line:

add_shortcode( 'gainwp_useroptout', array( $this, 'gainwp_user_optout' ) );

Shortcode PHP function:

function gainwp_user_optout( $atts, $content = "" ) {
			if ( ! isset( $atts['html_tag'] ) ) {
				$atts['html_tag'] = 'a';
			}
			if ( 'a' == $atts['html_tag'] ) {
				return '<a href="#" class="gainwp_useroptout" onclick="gaOptout()">' . esc_html( $content ) . '</a>';
			} else if ( 'button' == $atts['html_tag'] ) {
				return '<button class="gainwp_useroptout" onclick="gaOptout()">' . esc_html( $content ) . '</button>';
			}
		}

Code file location:

ga-in/ga-in/front/tracking.php

Conclusion

Now that you’ve learned how to embed the GAinWP Google Analytics Integration for WordPress Plugin shortcode, understood the parameters, and seen code examples, it’s easy to use and debug any issue that might cause it to ‘not work’. If you still have difficulties with it, don’t hesitate to leave a comment below.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *