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

Google Analytics ecommerce tracking + Yoast's plugin is broken #1736

Closed
ablears opened this Issue Jan 19, 2015 · 8 comments

Comments

Projects
None yet
4 participants
@ablears

ablears commented Jan 19, 2015

Not sure if you can do anything about this. Thanks to this commit Yoast's Google Analytics for Wordpress now uses '__gaTracker' not 'ga'.

That means ecommerce transactions will error with 'Uncaught ReferenceError: ga is not defined'

@JustinSainton

This comment has been minimized.

Show comment
Hide comment
@JustinSainton

JustinSainton Jan 26, 2015

Member

To clarify, it seems this would only fail when using universal analytics, is that right?

I wonder if something like this, added here, would do the trick?

var ga = typeof ga === 'undefined' && typeof __gaTracker !== 'undefined' ? __gaTracker : ga;

Member

JustinSainton commented Jan 26, 2015

To clarify, it seems this would only fail when using universal analytics, is that right?

I wonder if something like this, added here, would do the trick?

var ga = typeof ga === 'undefined' && typeof __gaTracker !== 'undefined' ? __gaTracker : ga;

@JustinSainton JustinSainton added this to the 4.1 milestone Jan 26, 2015

@ablears

This comment has been minimized.

Show comment
Hide comment
@ablears

ablears Jan 27, 2015

That looks like it would work. The other thing I was thinking, to be as flexible as possible, is to provide a free text box as an advanced setting. That way we could set whatever handler we needed.

ablears commented Jan 27, 2015

That looks like it would work. The other thing I was thinking, to be as flexible as possible, is to provide a free text box as an advanced setting. That way we could set whatever handler we needed.

@JustinSainton JustinSainton modified the milestones: 4.0, 4.1 Jan 27, 2015

@JustinSainton

This comment has been minimized.

Show comment
Hide comment
@JustinSainton

JustinSainton Jan 27, 2015

Member

@ablears Sure, I could see the value in that. Though, at the point that we're just passing through a text box, we could basically just set the Tracking Code Present box and allow users to set the code in their header.php. I have a particularly bad allergic reaction to new settings.

Member

JustinSainton commented Jan 27, 2015

@ablears Sure, I could see the value in that. Though, at the point that we're just passing through a text box, we could basically just set the Tracking Code Present box and allow users to set the code in their header.php. I have a particularly bad allergic reaction to new settings.

@galbaras

This comment has been minimized.

Show comment
Hide comment
@galbaras

galbaras Jun 16, 2015

@JustinSainton and @ablears, I think it would be much simpler to change the code from using "ga", which is outdated and doesn't work, to using "__gaTracker", which works.

In the meantime, I've placed the following code at the top of the wpsc-transaction_results.php within my theme:

<script type="text/javascript"> var ga = typeof ga === "undefined" && typeof __gaTracker !== "undefined" ? __gaTracker : ga; </script>

galbaras commented Jun 16, 2015

@JustinSainton and @ablears, I think it would be much simpler to change the code from using "ga", which is outdated and doesn't work, to using "__gaTracker", which works.

In the meantime, I've placed the following code at the top of the wpsc-transaction_results.php within my theme:

<script type="text/javascript"> var ga = typeof ga === "undefined" && typeof __gaTracker !== "undefined" ? __gaTracker : ga; </script>
@benhuson

This comment has been minimized.

Show comment
Hide comment
@benhuson

benhuson Jun 16, 2015

Member

I prefer the @JustinSainton way of handling fallback for older tracking code if possible. Updating tracking codes tends to be one of those things that often gets missed and there could be a lot of people not using the latest tracking code.

I recently saw some JavaScript code in a project I was working on with fallbacks all the way to urchinTracker() for tracking page views ;)

Not sure that it's the best structured if statement in the world but back-compatibility is good.

if (typeof urchinTracker == FUNCTION) 
    urchinTracker(value);
if (typeof pageTracker != UNDEFINED && typeof pageTracker._trackPageview == FUNCTION)
    pageTracker._trackPageview(value);
if (typeof _gaq != UNDEFINED && typeof _gaq.push == FUNCTION)
    _gaq.push(['_trackPageview', value]);
if (typeof ga == FUNCTION) 
    ga('send', 'pageview', value);
Member

benhuson commented Jun 16, 2015

I prefer the @JustinSainton way of handling fallback for older tracking code if possible. Updating tracking codes tends to be one of those things that often gets missed and there could be a lot of people not using the latest tracking code.

I recently saw some JavaScript code in a project I was working on with fallbacks all the way to urchinTracker() for tracking page views ;)

Not sure that it's the best structured if statement in the world but back-compatibility is good.

if (typeof urchinTracker == FUNCTION) 
    urchinTracker(value);
if (typeof pageTracker != UNDEFINED && typeof pageTracker._trackPageview == FUNCTION)
    pageTracker._trackPageview(value);
if (typeof _gaq != UNDEFINED && typeof _gaq.push == FUNCTION)
    _gaq.push(['_trackPageview', value]);
if (typeof ga == FUNCTION) 
    ga('send', 'pageview', value);
@galbaras

This comment has been minimized.

Show comment
Hide comment
@galbaras

galbaras Jun 17, 2015

@benhuson, your code seems to miss the most important function: __gaTracker. That's the correct one to use. Still, you point about backward compatibility is valid.

I've actually used the code proposed by @JustinSainton, which ensures backward compatibility with "ga". I've just placed it in a theme file, instead of the plugin, to protect it from being overwritten by plugin updates.

galbaras commented Jun 17, 2015

@benhuson, your code seems to miss the most important function: __gaTracker. That's the correct one to use. Still, you point about backward compatibility is valid.

I've actually used the code proposed by @JustinSainton, which ensures backward compatibility with "ga". I've just placed it in a theme file, instead of the plugin, to protect it from being overwritten by plugin updates.

@galbaras

This comment has been minimized.

Show comment
Hide comment
@galbaras

galbaras Jun 17, 2015

I can confirm that the following works:

If needed, copy the file wpsc-transaction_results.php to the active theme directory. Then, edit it and add the following code between the closing PHP tag (?>) and the DIV tag:

<script type="text/javascript"> var ga = typeof ga === "undefined" && typeof __gaTracker !== "undefined" ? __gaTracker : ga; </script>

galbaras commented Jun 17, 2015

I can confirm that the following works:

If needed, copy the file wpsc-transaction_results.php to the active theme directory. Then, edit it and add the following code between the closing PHP tag (?>) and the DIV tag:

<script type="text/javascript"> var ga = typeof ga === "undefined" && typeof __gaTracker !== "undefined" ? __gaTracker : ga; </script>

@benhuson

This comment has been minimized.

Show comment
Hide comment
@benhuson

benhuson Jun 17, 2015

Member

@galbaras Yep, was aware it wasn't fully up-to-date, but just interesting to see fallbacks all the way back to urchin :)

Member

benhuson commented Jun 17, 2015

@galbaras Yep, was aware it wasn't fully up-to-date, but just interesting to see fallbacks all the way back to urchin :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment