Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track Outbound Links doesn't appear to be functioning #921

Closed
michaeltorbert opened this issue Jun 1, 2017 · 11 comments

Comments

Projects
None yet
3 participants
@michaeltorbert
Copy link
Member

commented Jun 1, 2017

This can be confirmed on our own sites where no outbound links show up since about April or May of 2014.

We should have an event category "Outbound Links" with the action being the URL in google analytics, but it's not there.

https://support.google.com/analytics/answer/1136920?hl=en

@wpsmort

This comment has been minimized.

Copy link
Member

commented Jun 6, 2017

The documentation provided by Google here https://support.google.com/analytics/answer/1136920?hl=en requires the onclick attribute is added to all links which we can't do. I believe that we came up with a different solution using JavaScript when this feature was implemented. It's possible that this JavaScript no longer does what we think it should.

However, theres code called Autotrack which we could use - see the note from Google (https://developers.google.com/analytics/devguides/collection/analyticsjs/events) below:

Developers wanting to track outbound links and forms can use autotrack, which includes the outboundLinkTracker and outboundFormTracker plugins that handle these complexities for you. See the autotrack documentation for usage and installation instructions.

Here's the link to autotrack - https://github.com/googleanalytics/autotrack

@wpsmort

This comment has been minimized.

Copy link
Member

commented Jun 6, 2017

Here's the current JavaScript we output for outbound link tracking. @amostajo is going to review this and see if there's something wrong with this and see if Autotrack will work instead.

<script type="text/javascript">
						function recordOutboundLink(link, category, action) {
														ga('send', 'event', category, action);
														if (link.target == '_blank') return true;
							setTimeout('document.location = "' + link.href + '"', 100);
							return false;
						}
						/* use regular Javascript for this */
						function getAttr(ele, attr) {
							var result = (ele.getAttribute && ele.getAttribute(attr)) || null;
							if (!result) {
								var attrs = ele.attributes;
								var length = attrs.length;
								for (var i = 0; i < length; i++)
									if (attr[i].nodeName === attr) result = attr[i].nodeValue;
							}
							return result;
						}

						function aiosp_addLoadEvent(func) {
							var oldonload = window.onload;
							if (typeof window.onload != 'function') {
								window.onload = func;
							} else {
								window.onload = function () {
									if (oldonload) {
										oldonload();
									}
									func();
								}
							}
						}

						function aiosp_addEvent(element, evnt, funct) {
							if (element.attachEvent)
								return element.attachEvent('on' + evnt, funct);
							else
								return element.addEventListener(evnt, funct, false);
						}

						aiosp_addLoadEvent(function () {
							var links = document.getElementsByTagName('a');
							for (var x = 0; x < links.length; x++) {
								if (typeof links[x] == 'undefined') continue;
								aiosp_addEvent(links[x], 'onclick', function () {
									var mydomain = new RegExp(document.domain, 'i');
									href = getAttr(this, 'href');
									if (href && href.toLowerCase().indexOf('http') === 0 && !mydomain.test(href)) {
										recordOutboundLink(this, 'Outbound Links', href);
									}
								});
							}
						});
					</script>

@wpsmort wpsmort added this to the 2.3.14 milestone Jun 6, 2017

@amostajo

This comment has been minimized.

Copy link
Contributor

commented Jun 7, 2017

@wpsmort that piece of code is enabled only if two settings are on.., aiosp_ga_advanced_options and aiosp_ga_track_outbound_links, I looked at the plugin settings and wasn't able to find them, do you know where I can activate them?

@wpsmort

This comment has been minimized.

Copy link
Member

commented Jun 7, 2017

@amostajo You can find both options under All in One SEO > General Settings > Google Settings. The first is Advanced Analytics Options which is a radial. Once this is set to Enabled you'll see the second which is Track Outbound Links.

https://semperplugins.com/documentation/advanced-google-analytics-settings/

amostajo added a commit to amostajo/all-in-one-seo-pack that referenced this issue Jun 9, 2017

semperfiwebdesign#921 Refactored to work with autotrack.js and more G…
…oogle Analytics features

Refactored to work with autotrack.js, more Google Analytics features and
code was optimized in some module methods.

@wpsmort wpsmort assigned michaeltorbert and unassigned amostajo Jun 13, 2017

@wpsmort

This comment has been minimized.

Copy link
Member

commented Jun 13, 2017

This PR #931 adds a number of new options to the Google Settings section. We discussed on Slack whether these should be included or be held back. I believe they should be held and just the option for Track Outbound Links should be included for now.

@michaeltorbert michaeltorbert removed their assignment Jun 27, 2017

@michaeltorbert

This comment has been minimized.

Copy link
Member Author

commented Jun 27, 2017

@wpsmort Should this still be assigned to me for code review or is it back to @amostajo?

@wpsmort

This comment has been minimized.

Copy link
Member

commented Jun 29, 2017

@amostajo I have updated PR #931 with some comments.

@wpsmort wpsmort modified the milestones: 2.3.14, 2.3.15 Jul 11, 2017

@wpsmort wpsmort removed this from the 2.3.16 milestone Aug 22, 2017

amostajo added a commit to amostajo/all-in-one-seo-pack that referenced this issue Aug 24, 2017

semperfiwebdesign#921 Removed unnecessary HTML spacing and fixed domain
Removed unnecessary spacing created for code indentation and fixed issue
with domain list.

amostajo added a commit to amostajo/all-in-one-seo-pack that referenced this issue Aug 24, 2017

semperfiwebdesign#921 Removes extra options from free
Extra `autotrack.js` options are removed from free and filters were
created so these are enabled for pro.
@amostajo

This comment has been minimized.

Copy link
Contributor

commented Aug 24, 2017

@wpsmort fixes and changes applied ready for testing.

I have created a pro PR for this as well. Please test.
semperfiwebdesign/aioseop-pro#340

@wpsmort wpsmort self-assigned this Aug 24, 2017

@wpsmort

This comment has been minimized.

Copy link
Member

commented Aug 31, 2017

@amostajo I have tested both PRs and they are both good.
I have one very minor change for you. The closing HTML comment for All in One SEO Pack should appear on it's own line in the source code but now it's appearing on the same line as the last script like so:

<script async src="https://cdnjs.cloudflare.com/ajax/libs/autotrack/2.4.0/autotrack.js"></script><!-- /all in one seo pack pro -->

Can you change this so it looks like this with the correct indenting as well:

        <script async src="https://cdnjs.cloudflare.com/ajax/libs/autotrack/2.4.0/autotrack.js"></script>
<!-- /all in one seo pack pro -->

@wpsmort wpsmort assigned amostajo and unassigned wpsmort Aug 31, 2017

amostajo added a commit to amostajo/all-in-one-seo-pack that referenced this issue Sep 4, 2017

semperfiwebdesign#921 EOF Indent fix
Fixed end of line for autotrack, so AIOSEOP comment is displayed below
and with the right indent.
@amostajo

This comment has been minimized.

Copy link
Contributor

commented Sep 4, 2017

@wpsmort Let me know if the indent pushed works

@wpsmort

This comment has been minimized.

Copy link
Member

commented Sep 5, 2017

@amostajo Thanks, this is tested and is good.

@wpsmort wpsmort assigned michaeltorbert and unassigned amostajo Sep 5, 2017

michaeltorbert added a commit that referenced this issue Sep 5, 2017

#921 Refactored to work with autotrack.js and more Google Analytics f… (
#931)

* #921 Refactored to work with autotrack.js and more Google Analytics features

Refactored to work with autotrack.js, more Google Analytics features and
code was optimized in some module methods.

* #921 Removed unnecessary HTML spacing and fixed domain

Removed unnecessary spacing created for code indentation and fixed issue
with domain list.

* #921 Removes extra options from free

Extra `autotrack.js` options are removed from free and filters were
created so these are enabled for pro.

* Update readme tags (#1114)

* update php requirement (#1115)

* #921 EOF Indent fix

Fixed end of line for autotrack, so AIOSEOP comment is displayed below
and with the right indent.

@michaeltorbert michaeltorbert removed their assignment Sep 5, 2017

@michaeltorbert michaeltorbert modified the milestones: 2.4, 2.3.17 Sep 5, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.