Click Tracking [Google Analytics]

Event Tracking

<script>
/**
* Function that tracks a click on a link in Google Analytics.
* This function takes a valid URL string as an argument, and uses that URL string
* as the event label. Setting the transport method to 'beacon' lets the hit be sent
* using 'navigator.sendBeacon' in browser that support it.
*/
var trackLink = function(url) {
   ga('send', 'event', 'link', 'click', url, {
     'transport': 'beacon',
     'hitCallback': function(){document.location = url;}
   });
}
</script>

On Page Implementation

<a href="http://www.example.com" onclick="trackLink('http://www.example.com'); return false;">Visit example.com</a>

 

Custom Fields in bbPress Topic Form

Creating Fields

add_action ( 'bbp_theme_before_topic_form_content', 'bbp_extra_fields'); function bbp_extra_fields() { 

$value = get_post_meta( bbp_get_topic_id(), 'bbp_extra_field1', true); echo '<label for="bbp_extra_field1">Extra Field 1</label><br>'; echo "<input type='text' name='bbp_extra_field1' 

value='".$value."'>"; $value = get_post_meta( bbp_get_topic_id(), 'bbp_extra_field2', true); echo '<label for="bbp_extra_field1">Extra Field 2</label><br>'; echo "<input type='text' name='bbp_extra_field2' value='".$value."'>"; }

Saving Custom Fields

add_action ( 'bbp_new_topic', 'bbp_save_extra_fields', 10, 1 ); add_action ( 'bbp_edit_topic', 'bbp_save_extra_fields', 10, 1 );

function bbp_save_extra_fields($topic_id=0) {

if (isset($_POST) && $_POST['bbp_extra_field1']!='') update_post_meta( $topic_id, 'bbp_extra_field1', $_POST['bbp_extra_field1'] );

if (isset($_POST) && $_POST['bbp_extra_field1']!='') update_post_meta( $topic_id, 'bbp_extra_field1', $_POST['bbp_extra_field2'] );

}

Displaying Fields on the Topic Page

add_action('bbp_template_before_replies_loop', 'bbp_show_extra_fields');

function bbp_show_extra_fields() {

$topic_id = bbp_get_topic_id();

$value1 = get_post_meta( $topic_id, 'bbp_extra_field1', true); 
$value2 = get_post_meta( $topic_id, 'bbp_extra_field2', true);

echo "Field 1: ".$value1."<br>"; 
echo "Field 2: ".$value2."<br>";

}