• I’m trying to add Google Analytics link tagging variables to my URLs before Twitter Tools tweets them out. This is what I’m trying to achieve:

    http://example.com/?utm_source=twitter&utm_medium=twitter&utm_campaign=EXAMPLE-POST-SLUG

    So, I’ve got this bit of code:

    function ses_url_tagger($url) {
    
    	// get the post slug
    	$post_data = get_post($post->ID, ARRAY_A);
    	$slug = $post_data['post_name'];
    
    	if (stristr($url,'?')) {
    		// URL already has query args, tag on the end
    		$ses_url = $url . '&';
    	} else {
    		// URL doesn't have query args, tag on the end
    		$ses_url = $url . '?';
    	}
    	// append slug to URL
    	$ses_url = $ses_url . 'utm_source=twitter&utm_medium=twitter&utm_campaign=' . $slug;
    
            return $ses_url;
    }
    add_filter('tweet_blog_post_url', 'ses_url_tagger');

    This is not working and I guess it’s because the $post_data variable is not available. How do I fix this? Thanks!

  • The topic ‘Google Analytics tagging with post slug for Twitter Tools’ is closed to new replies.