Title: [Plugin: Google Analytics for WordPress] cross domain tracking
Last modified: August 20, 2016

---

# [Plugin: Google Analytics for WordPress] cross domain tracking

 *  [vzaguski](https://wordpress.org/support/users/vzaguski/)
 * (@vzaguski)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/plugin-google-analytics-for-wordpress-cross-domain-tracking/)
 * Couldn’t enable cross domain tracking – “_link” event is not set for specified
   domains and they just tracked as outbound articles.
 * After looking through code I’ve found the line that could couse problem.
 * Here’s the code snippet:
    —–
 *     ```
       } else if ( $target["domain"] != $origin["domain"] ){
       					$crossdomains = explode(',',str_replace(' ','',$options['othercrossdomains']));
       					if ( $options['trackcrossdomain'] && in_array($target["host"],$crossdomains) ) {
       						$trackBit = '_gaq.push([\'_link\', \'' . $matches[2] . '//' . $matches[3] . '\']); return false;"';
       					} else if ( $options['trackoutbound'] && in_array($options['domainorurl'], array('domain','url')) ) {
       						$url = $options['domainorurl'] == 'domain' ? $target["host"] : $matches[3];
       						$trackBit = GA_Filter::ga_get_tracking_link($category, $url,'');
       					}
       					$trackBit = GA_Filter::ga_get_tracking_link($category, $url,'');
       				}
       ```
   
 * ——
    _[Code moderated: please ensure that your code is enclosed in backticks (`)
   or use the code button.]_
 * Actually, the last line in the code is the problem. If I delete it, it seems 
   to work as expected.
 * [http://wordpress.org/extend/plugins/google-analytics-for-wordpress/](http://wordpress.org/extend/plugins/google-analytics-for-wordpress/)

Viewing 15 replies - 1 through 15 (of 18 total)

1 [2](https://wordpress.org/support/topic/plugin-google-analytics-for-wordpress-cross-domain-tracking/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/plugin-google-analytics-for-wordpress-cross-domain-tracking/page/2/?output_format=md)

 *  [pblickiss](https://wordpress.org/support/users/pblickiss/)
 * (@pblickiss)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/plugin-google-analytics-for-wordpress-cross-domain-tracking/#post-2394677)
 * I’m having the same issue, even when disabling outgoing link tracking and commenting
   out the offending line of code from above. Does anyone have a fix for this in
   version 4.2.4? All links appear as outgoing whether they are listed in the specified
   domain list or not. Thanks!
 *  [pblickiss](https://wordpress.org/support/users/pblickiss/)
 * (@pblickiss)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/plugin-google-analytics-for-wordpress-cross-domain-tracking/#post-2394678)
 * Has anyone figured this out? Yoast doesn’t appear to frequent this board often.
   Thanks!
 *  [SocialBizzle](https://wordpress.org/support/users/socialbizzle/)
 * (@socialbizzle)
 * [13 years, 11 months ago](https://wordpress.org/support/topic/plugin-google-analytics-for-wordpress-cross-domain-tracking/#post-2394686)
 * We have a similar issue. Basically our conversion paths are not being tracked
   correctly between our site – socialbizzle.com and our payment processor – Fastspring.
 * All conversions appear as a ‘direct source’ even though they are occurring through
   adwords and other marketing channels.
 * I thought the problem would be solved now I have removed the ‘track clicks and
   downloads option’.
 * Are you saying that you have done that and it still doesn’t work correctly?
 *  [ThE_ED](https://wordpress.org/support/users/the_ed/)
 * (@the_ed)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/plugin-google-analytics-for-wordpress-cross-domain-tracking/#post-2394693)
 * Had the exact same thing, as a quick fix, commenting out the line worked for 
   me in the latest version (comment out the right line, there are multiple lines
   having the same code), but I’ll try to find out as to why this behaviour occurs.
 *  [wpaholic](https://wordpress.org/support/users/wordpressaholic/)
 * (@wordpressaholic)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/plugin-google-analytics-for-wordpress-cross-domain-tracking/#post-2394696)
 * +1
 *  [Paul](https://wordpress.org/support/users/paultgoodchild/)
 * (@paultgoodchild)
 * [13 years, 9 months ago](https://wordpress.org/support/topic/plugin-google-analytics-for-wordpress-cross-domain-tracking/#post-2394702)
 * +1
    This is a real problem… thanks for finding the quick fix.
 * If you’re out there Yoast, can ya take a look at this little bug – it’s quite
   important for all cross-domain tracking.
 * Thanks! 🙂
 *  [worldwisewebs](https://wordpress.org/support/users/worldwisewebs/)
 * (@worldwisewebs)
 * [13 years, 9 months ago](https://wordpress.org/support/topic/plugin-google-analytics-for-wordpress-cross-domain-tracking/#post-2394703)
 * Seems to be working fine for me. I thought it was broken but realized I was logged
   in as admin. Doublecheck that’s not the case for you!
 *  [worldwisewebs](https://wordpress.org/support/users/worldwisewebs/)
 * (@worldwisewebs)
 * [13 years, 9 months ago](https://wordpress.org/support/topic/plugin-google-analytics-for-wordpress-cross-domain-tracking/#post-2394704)
 * erm actually I’ve got that wrong. What I am seeing is this:
 * `<a target="_blank" onclick="javascript:_gaq.push(['_trackEvent','outbound-article','']);"
   href="http://my-out-bound-domain.org/">Outbound link</a>`
 * I tried checking and unchecking the option “Track outbound clicks & downloads:”
   and the onclick event stays either way. Strange?
 *  [worldwisewebs](https://wordpress.org/support/users/worldwisewebs/)
 * (@worldwisewebs)
 * [13 years, 9 months ago](https://wordpress.org/support/topic/plugin-google-analytics-for-wordpress-cross-domain-tracking/#post-2394705)
 * It looks like the checkbox for “Enable Cross Domain Tracking:” is actually adding
   the _trackEvent instead of _link as expected. Checking this box also generates
   a notice:
 * `Notice: Undefined variable: url in {MY PATH}/httpdocs/wp-content/plugins/google-
   analytics-for-wordpress/googleanalytics.php on line 1161`
 * This notice appears whether or not the field “Cross-Domain Tracking, Other Domains:”
   is filled in.
 * After a bit of playing around I did find that the original poster’s fix does 
   indeed work. The line at 1161 `$trackBit = GA_Filter::ga_get_tracking_link($category,
   $url,'');` overwrites the $trackBit variable that was set in the blocks just 
   above it, so commenting out this line seems to resolve the issue for me.
 *  [worldwisewebs](https://wordpress.org/support/users/worldwisewebs/)
 * (@worldwisewebs)
 * [13 years, 9 months ago](https://wordpress.org/support/topic/plugin-google-analytics-for-wordpress-cross-domain-tracking/#post-2394707)
 * Found another bug .. on line 1156, there is an extra double quote ta the end 
   of this line, after the semi colon, before the closing single quote. `$trackBit
   = '_gaq.push([\'_link\', \'' . $matches[2] . '//' . $matches[3] . '\']); return
   false;"';`
 * The double quote is closed again below when the $trackBit variable gets added
   into the $matches array, so this creates an extra quote that makes the link code
   a little screwy.
 *  [magnusrf](https://wordpress.org/support/users/magnusrf/)
 * (@magnusrf)
 * [13 years, 9 months ago](https://wordpress.org/support/topic/plugin-google-analytics-for-wordpress-cross-domain-tracking/#post-2394708)
 * Man, I’ve been looking for a plug-in that could handle cross domain tracking 
   for my websites for a LONG TIME. This plug-in is awesome.
 * But just like vzaguski and worldwisewebs have indicated, line 1161 needs to be
   commented out and line 1156 needs to be updated to remove that last double quote.
 * Works like a charm now!
 *  [dDon](https://wordpress.org/support/users/ddon/)
 * (@ddon)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/plugin-google-analytics-for-wordpress-cross-domain-tracking/#post-2394709)
 * I have been looking for a way to solve this as well, but I gave up after a few
   hours. I really hope this does the trick, I’ll give it try tomorrow. Fingers 
   crossed.
 * Hope this gets solved in future updates though. Good work vzaguski and wisewebs.
 *  [dDon](https://wordpress.org/support/users/ddon/)
 * (@ddon)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/plugin-google-analytics-for-wordpress-cross-domain-tracking/#post-2394710)
 * It still doesn’t seem to work.
 * Even removing the last line vzaguski mentioned, it is still inserting ‘_trackEvent’
   instead of ‘_link’?
 * Anyone got a fix for this?
 *  [worldwisewebs](https://wordpress.org/support/users/worldwisewebs/)
 * (@worldwisewebs)
 * [13 years, 8 months ago](https://wordpress.org/support/topic/plugin-google-analytics-for-wordpress-cross-domain-tracking/#post-2394711)
 * Looks like these bugs made it to 3.4.5 – now it’s line 1218 that needs to be 
   commented out and the extra quote is on line 1213
 *  [m.r.green](https://wordpress.org/support/users/mrgreen-2/)
 * (@mrgreen-2)
 * [13 years, 7 months ago](https://wordpress.org/support/topic/plugin-google-analytics-for-wordpress-cross-domain-tracking/#post-2394714)
 * Hi worldwisewebs,
 * Yoast has now upgraded to version 4.2.7 but still has this issue. Would greatly
   appreciate if you could highlight the code again?
 * Thanks,
    Mart

Viewing 15 replies - 1 through 15 (of 18 total)

1 [2](https://wordpress.org/support/topic/plugin-google-analytics-for-wordpress-cross-domain-tracking/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/plugin-google-analytics-for-wordpress-cross-domain-tracking/page/2/?output_format=md)

The topic ‘[Plugin: Google Analytics for WordPress] cross domain tracking’ is closed
to new replies.

 * ![](https://ps.w.org/google-analytics-for-wordpress/assets/icon.svg?rev=2976619)
 * [MonsterInsights - Google Analytics Dashboard for WordPress (Website Stats Made Easy)](https://wordpress.org/plugins/google-analytics-for-wordpress/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/google-analytics-for-wordpress/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/google-analytics-for-wordpress/)
 * [Active Topics](https://wordpress.org/support/plugin/google-analytics-for-wordpress/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/google-analytics-for-wordpress/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/google-analytics-for-wordpress/reviews/)

 * 18 replies
 * 12 participants
 * Last reply from: [jalancast](https://wordpress.org/support/users/jalancast/)
 * Last activity: [13 years, 6 months ago](https://wordpress.org/support/topic/plugin-google-analytics-for-wordpress-cross-domain-tracking/page/2/#post-2394717)
 * Status: not resolved