Plugin Author
Allen
(@amweiss98)
technically all the plugin does is put the title in the database and then wordpress does the rest (including any links). However, there is a function called ta_modified_post_title in the import_posts.php file that I created where you can modify some properties in the link….that’s where I suggest putting you tracking.
Thread Starter
James
(@drabello)
Thank you so much for the fast response. Awesome man.
Do you know if it is possible to override this with a function on my Child theme functions.php? That way I could keep the plugin updated in a safe way.
Plugin Author
Allen
(@amweiss98)
i imagine you could put that function anywhere, and your functions.php file should be fine.
Thread Starter
James
(@drabello)
Sry to disturb Allen,
I found the function you mentioned:
function ta_modified_post_title ($title) {
$post_options = get_option('rss_post_options');
$targetWindow=$post_options['targetWindow'];
if($targetWindow==0){
$openWindow='class="colorbox"';
}elseif ($targetWindow==1){
$openWindow='target=_self';
}else{
$openWindow='target=_blank';
}
if ( in_the_loop() && !is_page() ) {
global $wp_query;
$postID=$wp_query->post->ID;
$myLink = get_post_meta($postID, 'rssmi_source_link' , true);
if (!empty($myLink)){
$myTitle=$wp_query->post->post_title;
$myLinkTitle='<a href='.$myLink.' '.$openWindow.'>'.$myTitle.'</a>'; // change how the link opens here
return $myLinkTitle;
}
}
return $title;
}
However I have no ideia how to put this inside:
onclick="_gaq.push(['_trackEvent', 'ClickOut', 'ContenBlog']);"
Any tips? thank you
Plugin Author
Allen
(@amweiss98)
well, my first shot would be to change this line:
$myLinkTitle='<a href='.$myLink.' '.$openWindow.'>'.$myTitle.'</a>';
to this:
$myLinkTitle='<a href="#" onclick='_gaq.push(['_trackEvent', 'ClickOut', 'ContenBlog']);">'.$myTitle.'</a>';
Thread Starter
James
(@drabello)
Unfortunately I am getting this error with that code:
Parse error: syntax error, unexpected ‘_trackEvent’ (T_STRING) in /…/wp-content/plugins/wp-rss-multi-importer/inc/import_posts.php on line 209
Plugin Author
Allen
(@amweiss98)
Ok. Get replace double quotes with single quotes
Thread Starter
James
(@drabello)
Hi Allen, I am starting to think that is not possible to add a GA EventTracking through a wordpress function. 😉 It did not work.
The link keeps messy:
<a "contenblog"]);"="" "clickout",="" _trackevent",="" onclick="_gaq.push([" rel="nofollow" target="_blank" href="http://feedproxy.google.com/.../">Link Title</a>
So I am gonna change my question, I changed my code to add a nofollow rel Attribute to the link, now it´s like this:
function ta_modified_post_title ($title) {
$post_options = get_option('rss_post_options');
$targetWindow=$post_options['targetWindow'];
if($targetWindow==0){
$openWindow='class="colorbox"';
}elseif ($targetWindow==1){
$openWindow='target=_self';
}else{
$openWindow='target=_blank';
$relNofollow='rel="nofollow"';
}
if ( in_the_loop() && !is_page() ) {
global $wp_query;
$postID=$wp_query->post->ID;
$myLink = get_post_meta($postID, 'rssmi_source_link' , true);
if (!empty($myLink)){
$myTitle=$wp_query->post->post_title;
$myLinkTitle='<a href='.$myLink.' '.$openWindow.' '.$relNofollow.'>'.$myTitle.'</a>'; // change how the link opens here
return $myLinkTitle;
}
}
return $title;
}
As you can see I added a $relNofollow=’rel=”nofollow”‘; and then added ‘.$relNofollow.’ to the link format. Working perfect! Is this code ok?
I also tried to add the EventTracking this way but no success.
Sry to disturb man, keep the good work!
Plugin Author
Allen
(@amweiss98)
yes, that should work fine.