I'm using Google Analytics for goal tracking and I need to run a custom script when Goal is complete. Does GA/GTM have any way to solve this? Thanks.
-
2Can you supplement your question with things that you've attempted, or other resources you looked into?nyuen– nyuen2015-09-17 18:37:07 +00:00Commented Sep 17, 2015 at 18:37
-
For example, when user visit two specific pages (it will complete the goal) I need to send some data by CURL request to third party service.codekote– codekote2015-09-18 18:23:09 +00:00Commented Sep 18, 2015 at 18:23
1 Answer
The goal conversion is recorded serverside, so to be nitpicky you cannot track goal conversions on the client. However you can track the pageviews or events that are defined as goals in GA (this is not purely semantical, events and pageviews will happen once per hit, goal conversions happen once per session).
To track if the condition for a goal is met you can use a hit callback, a function that is executed once the tracking call has finished.
<script>
ga('send', 'event', {
'eventCategory': 'Category',
'eventAction': 'Action',
'eventLabel': 'This is set as a goal!',
'hitCallback': function() {
alert("I'm a user function hear me roar!");
}
});
</script>
The alert will be triggered once the event tracking is complete (obviously you would replace the alert with a call to your custom function).