• Resolved vaseo

    (@vaseo)


    Hi. I want to use this for track click to reveal contact number purposes. How do I track the click? would Monsterinsights/Yoast analytics do this automatically?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author buntegiraffe

    (@buntegiraffe)

    Hello @vaseo,

    Somehow WordPress failed to notify me about your question, although I’m definitely subscribed to plugin support threads.

    Anyways, thanks for contacting us!

    I have just tried to set up event tracking and it worked. For it to work, pls do the following:

    1. Access your site via ftp and locate our plugin’s folder (should be wp-content/plugins/show-hidecollapse-expand/). Open bg_show_hide.php with any text editor and locate the bg_show_hide_shortcode function. Replace it with the following:

    function bg_show_hide_shortcode($attr, $content = null) {
    	
    	$a = shortcode_atts( 
    			array( 	'view' => 'link',
    					'color' => 'inherit',
    					'expand_text' => 'Show More',
    					'collapse_text' => '',
    					'click' => '',
    					'icon' => ''), 	
    			$attr
    		);
    	
    	$bg_uniq_id = uniqid('',true);
    	$bg_uniq_id = str_replace(".","0",$bg_uniq_id);
    	$bg_list_start = "";
    	$bg_list_end = "";
    	$bg_hidden_content_start = "";
    	$bg_hidden_content_end = "";
    	$bg_showmore_content_tag = "div";
    	$bg_showmore_extra_attributes = "";
    	$bg_text_color = $a["color"];
    	$bg_expand_text = $a["expand_text"];
    	$bg_collapse_text = $a["collapse_text"];
    	$bg_custom_click_event = $a["click"];
    	$bg_btn_icon_class = "bg-" . $a["icon"];
    	
    	$bg_uniq_id_holder = "<input type='hidden' bg_collapse_expand='$bg_uniq_id' value=$bg_uniq_id>";
    	
    	$bg_showmore_text = "<input type='hidden' id='bg-show-more-text-$bg_uniq_id' value='" . $bg_expand_text . "'>";
    	$bg_showless_text = "<input type='hidden' id='bg-show-less-text-$bg_uniq_id' value='" . $bg_collapse_text . "'>";
    
    	$bg_hidden_data = $bg_uniq_id_holder . $bg_showmore_text . $bg_showless_text;
    	
    	
    	if ( $a["view"] == 'link') {
    		$showmore_btn = "<a id='bg-showmore-action-$bg_uniq_id' class='bg-showmore-plg-link $bg_btn_icon_class' onclick=\"$bg_custom_click_event\" style=\" color:" . $bg_text_color . " ;\" href='#'>" . $bg_expand_text . "</a>";
    		$bg_hidden_content_start = "<p>";
    		$bg_hidden_content_end = "</p>";
    		
    	}
    	elseif ( $a["view"] == 'link-inline') {
    		$showmore_btn = "<a id='bg-showmore-action-$bg_uniq_id' class='bg-showmore-plg-link $bg_btn_icon_class' onclick=\"$bg_custom_click_event\" style=\" color:" . $bg_text_color . " ;\" href='#'>" . $bg_expand_text . "</a>";	
    		$bg_hidden_content_start = "<span style='display:inline;'>";
    		$bg_hidden_content_end = "</span>";
    		$bg_showmore_content_tag = "span";
    	}
    	elseif ( $a["view"] == 'link-list') {
    		$showmore_btn = "<a id='bg-showmore-action-$bg_uniq_id' class='bg-showmore-plg-link $bg_btn_icon_class' onclick=\"$bg_custom_click_event\" style=\" color:" . $bg_text_color . " ;\" href='#'>" . $bg_expand_text . "</a>";	
    		$bg_list_start = "<ul style='margin-top:0;margin-bottom:0'>";
    		$bg_list_end = "</ul>";
    		$bg_showmore_content_tag = "ul";
    		$bg_showmore_extra_attributes = " class='bg-showmore-no-padding-no-margin'";
    	}
    	elseif ( $a["view"] == 'button-orange') {
    		$showmore_btn = "<button id='bg-showmore-action-$bg_uniq_id' class='bg-showmore-plg-button bg-orange-button " . $bg_btn_icon_class . "' onclick=\"$bg_custom_click_event\" style=\" color:" . $bg_text_color . " ;\">" . $bg_expand_text . "</button>";	
    	}	
    	elseif ( $a["view"] == 'button-blue') {
    		$showmore_btn = "<button id='bg-showmore-action-$bg_uniq_id' class='bg-showmore-plg-button bg-blue-button " . $bg_btn_icon_class . "' onclick=\"$bg_custom_click_event\" style=\" color:" . $bg_text_color . " ;\">" . $bg_expand_text . "</button>";	
    	}	
    	elseif ( $a["view"] == 'button-green') {
    		$showmore_btn = "<button id='bg-showmore-action-$bg_uniq_id' class='bg-showmore-plg-button bg-green-button " . $bg_btn_icon_class . "' onclick=\"$bg_custom_click_event\" style=\" color:" . $bg_text_color . " ;\">" . $bg_expand_text . "</button>";	
    	}	
    	elseif ( $a["view"] == 'button-red') {
    		$showmore_btn = "<button id='bg-showmore-action-$bg_uniq_id' class='bg-showmore-plg-button bg-red-button " . $bg_btn_icon_class . "' onclick=\"$bg_custom_click_event\" style=\" color:" . $bg_text_color . " ;\">" . $bg_expand_text . "</button>";	
    	}	
    			
    	$content = $bg_hidden_content_start . $bg_hidden_data . $showmore_btn . $bg_list_end . 
    			   "<" . $bg_showmore_content_tag . $bg_showmore_extra_attributes . " id='bg-showmore-hidden-$bg_uniq_id' >" . 
    			   $content . "</" . $bg_showmore_content_tag . ">" . 
    			   $bg_hidden_content_end . $bg_list_start;
    	$content = do_shortcode($content);
    	
    	wp_localize_script( "bg-show-hide-script", 'BG_SHCE_USE_EFFECTS', get_option('bg_shce_effectsEnabled','0'));
    	wp_localize_script( "bg-show-hide-script", 'BG_SHCE_TOGGLE_SPEED', get_option('bg_shce_animationSpeed','400'));
    	wp_localize_script( "bg-show-hide-script", 'BG_SHCE_TOGGLE_OPTIONS', 'none');
    	wp_localize_script( "bg-show-hide-script", 'BG_SHCE_TOGGLE_EFFECT', get_option('bg_shce_animationEffect','blind'));	
    
        return $content;
    }

    2. In your post/page where you use our plugin, add the click attribute to the shortcode with the tracking function from google analytics. For example:
    [bg_collapse view="button-blue" color="#ffffff" icon="eye" expand_text="Show More Questions" click="ga('send', 'event', 'buttons', 'click', 'contact-us');" collapse_text="Show Less Questions" ]

    Explanation of the GA event tracking can be found here.

    3. Go to your GA dashboard (Admin area) and create a new goal with the Goal type: Event and your specific Event conditions. In my example conditions are:

    Category Equals to buttons
    Action Equals to click
    Label Equals to contact-us
    Value Greater than

    A quick screencast is here: ga-tracking-screencast

    4. After that load your page/post and click on the button, then check your reports in Google Analytics > REAL-TIME > Events. The event should be recorded.

    If you have any difficulties, please let me know.

    • This reply was modified 7 years, 6 months ago by buntegiraffe.
    Plugin Author buntegiraffe

    (@buntegiraffe)

    duplicate

    • This reply was modified 7 years, 6 months ago by Jan Dembowski.
    • This reply was modified 7 years, 6 months ago by buntegiraffe. Reason: duplicate
    Plugin Author buntegiraffe

    (@buntegiraffe)

    duplicate

    • This reply was modified 7 years, 6 months ago by buntegiraffe. Reason: duplicate
    Plugin Author buntegiraffe

    (@buntegiraffe)

    Hello @vaseo,

    I haven’t received your answer in over 48 hours, so I assume your issue is solved. I am marking this thread as resolved, but if you have any questions, please let me know.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Google Analytics Tracking’ is closed to new replies.