Mobile app version of vmapp.org
Login or Join
Turnbaugh106

: Can't get Event Tracking To Work I'm trying to get an event to be tracked (user registration) as a goal. I DON'T want it to be tracked by an onclick, I want it to be tracked once a PHP

@Turnbaugh106

Posted in: #Analytics #AnalyticsApi #GoogleAnalytics

I'm trying to get an event to be tracked (user registration) as a goal. I DON'T want it to be tracked by an onclick, I want it to be tracked once a PHP event is finished. Here is my code:

if(USER REGISTRATION SUCCESSFUL):
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_trackEvent', 'SignUp', 'Registered', 'User Registered']);
</script>
endif;


The regular Google Analytics Code is in the footer just before the / body. On the register page that code is being triggered in the middle of the page.

But the completed goals aren't showing up in Google Analytics, any idea why?

Note: PHP simplified since it doesn't really pertain to this question.

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Turnbaugh106

1 Comments

Sorted by latest first Latest Oldest Best

 

@Sarah324

Try removing var _gaq = _gaq || []; - this line is obliterating your existing Google Analytics object and Events cannot be tracked without a call to trackPageView.

Edit: PHP Code Sample

Sorry, I missed the fact that your GA.js snippet appears after your Event tracking snippet - here is a solution which should resolve the issue:

<?php // start of document
if ( USER REGISTRATION SUCCESSFUL )
{
$analytics_addition = "_gaq.push(['_trackEvent', 'SignUp', 'Registered', 'User Registered']);";
}
?>

<!--
your regular HTML output
-->

<!-- ga.js snippet -->
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-X']);
_gaq.push(['_trackPageview']);
<?php
// append event tracking
if ( @isset ($analytics_addition) && $analytics_addition )
echo $analytics_addition;
?>
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<!-- eof ga.js snippet -->

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme