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

Callback after tracking goal #13679

Closed
tschallacka opened this issue Nov 7, 2018 · 5 comments · Fixed by #13680
Closed

Callback after tracking goal #13679

tschallacka opened this issue Nov 7, 2018 · 5 comments · Fixed by #13680
Assignees
Labels
Enhancement For new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc.
Milestone

Comments

@tschallacka
Copy link

https://developer.matomo.org/guides/tracking-javascript-guide#manually-trigger-goal-conversions

Is it possible to have a callback function? if so how?
I found https://forum.matomo.org/t/callback-after-tracking-a-goal-with-javascript/3190, which leads to #10337 which leads to #10467 which leads to 04d0c74

but I have no clue after all this what i'm supposed to insert into the _paq.push(['trackGoal', 1]) to get a callback event working after the request has been sent to matomo and received back.

Is this a feature that is present but undocumented? If so, how can I use it in goal tracking?

@tsteur tsteur added the Enhancement For new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc. label Nov 7, 2018
@tsteur
Copy link
Member

tsteur commented Nov 7, 2018

it's not possible yet but added a pull request for this in #13680 . Will be available with Matomo 3.8 (not 3.7). Just out of curiosity, do you mind more explaining your use case what you do in the callback?

@tsteur tsteur added this to the 3.8.0 milestone Nov 7, 2018
@tschallacka
Copy link
Author

tschallacka commented Nov 7, 2018

On our website we have a lot of javascript functionality. We want to track the usage of some features.

One of the simpler features is a whatsapp contact button, when the button is pressed and the javascript magic has happened we wish to send the people to their destination so the whatsapp window will open.

Unfortunately if you send someone directly to a third party site a lot of browsers will drop pending requests and those may not be adequately tracked.

By having a callback at the end you can queue up several requests that should happen before sending the user on it's way.
Google Analytics for example uses this wonderfully, if you look at the documentation https://developers.google.com/analytics/devguides/collection/analyticsjs/sending-hits#knowing_when_the_hit_has_been_sent you can chain several requests.

In our app for example we have analytics, adwords and want to chain motomo too for experimenting with the features of motomo.

How our chain currently works:

click whatsapp >
handle graphcis; 
log_motomo(_paq.push());
log_goal_analytics(callback log_goal_adwords) >
log_goal_adwords(callback move_to_whatsapp) >
move_to_whatsapp > window.location=whatsappurl.

Right now, the motomo push get's dropped a lot because the google analytics callbacks are handled much faster than the piwik response on our server, which causes the browser to move to whatsapp before motomo is ready to accep/log.

By having a callback features, one can chain motomo in any other request and make sure everything is logged properly.

@tsteur
Copy link
Member

tsteur commented Nov 8, 2018

Cheers, that helped 👍 FYI: In Matomo 3.8 we will also have an option to use sendBeacon when it is available in the browser see #13451 and eventually it'll become the default: #13681

You may want to consider enabling this once it is available and then you wouldn't need to wait for the requests to finish and end up having bit faster UI there. It's supported in most browsers: https://caniuse.com/#search=sendbeacon

Unfortunately, sendBeacon does not let us know when the request is finished so you wouldn't be able to use the callback for other browsers unless you really checked whether sendBeacon is being used or not.

@tschallacka
Copy link
Author

From MDN
https://developer.mozilla.org/en-US/docs/Web/API/Navigator/sendBeacon

The sendBeacon() method returns true if the user agent is able to successfully queue the data for transfer, Otherwise it returns false.

You can use this in a callback feature. call the callback when it returns true, throw an error if it fails, even better, use a promise for easy handling all cases.

@tsteur
Copy link
Member

tsteur commented Nov 8, 2018

True we could just assume the request worked when sendBeacon works. I just see I've implemented that actually already in #13451 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement For new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants