Analytics broken for Hubspot, Quantcast, Chartbeat, Comscore and KISSmetrics
I tried to setup analytics with Google Analytics and Hubspot through the analytics. But for some reason which I don't get it Google Analytics is not receiving any data anymore once Hubspot tracking code is also setup.
If I leave out the Hubspot code from the settings then Google is working like a charm. Has anybody had this issue as well and is there a solution or is there a way to find out what's going wrong?
Thanks for pointing me in the right direction! I will also ask the Hubspot support team to have a look at it.
We'll try and take a look, but it sounds like it's maybe an analytics.js issue. I'd also triple check your settings.json file too!
There seems to be a much bigger problem than I thought. Apparently the Hubspot code doesn't get initialized at all. The thing is that for quite a few libraries there is an option "assumesPageView". If this flag is set in the plugin code, like it is for HubSpot, initialization should happen when the first page call is made. This is implemented with the "after" package. This mechanism is written in wrapInitialize and wrapPage should cause the second initialize and final initialization.
But no page call is made in this case because initialization is not completed. Basically the problem is introduced with this commit: https://github.com/okgrow/analytics/commit/4de2fd2cdcf3b2b5acf580097507cacf300159d1
I could solve the issue for me by avoiding to use trackPageWhenReady, but this might introduce different problems. I don't know whether the changes with those on ready callbacks have been made out of another necessity?
I will update the issue title accordingly as this issue is much bigger than initially thought.
Not only the connections with these libraries get broken but everything gets stuck if you load any of these connectors and you don't do manual page tracking calls.
@derouck There is an open issue that I believe explains the behaviour you noticed with Google Analytics and Hubspot over on segment.io's analytics.js repo ?
Currently if one integration fails no .ready() is fired. A substantial rewrite might be required on our end, but we are currently investigating.
We are working to resolve a few of the open bugs on the okgrow:analytics repo over the next week. Hopefully we will have a fix for you soon.
@cfnelson That's fine, I have a fairly simple workaround by changing trackPageWhenReady like this, so for me there's no rush.
var trackPageWhenReady = function () {
var _args = arguments;
analytics.ready(function () {analytics.page.apply(this, _args);});
};
var trackPage = function () {
var _args = arguments;
analytics.page.apply(this, _args);
};
With this approach, there could be some information missing, but the point is that a lot of the analytics systems want to know the first page when they are initialized. Then again they only say they are ready when they receive have tracked a page. Thus the only way forward is to start tracking pages. Otherwise, the Meteor package keeps waiting for Godot.
So possible solutions for this package are:
- an option dontWaitForReady to start tracking immediately
- have this behavior built-in when packages in the title are configured. In this case, there might remain a problem for those that add other integrations themselves, but they would only need to add the name of their integration to that list. This would probably be the easiest solution for users.
If the segment package would allow indicating that you don't need to wait for a ready for these integrations it could work as well, but considering the age of that bug it doesn't look like anyone will pick it up soon.
If you need some more information, let me know.
Good luck and thanks for the package!
@derouck Thanks for your detailed response. Out of curosity are you using FlowRouter ?
I have worked on resolving a bug in our package where FlowRouter didn't log the intial page view. The fix is here #123 . I would be curious to know if this resolves your issue, though from reading your issue I suspect it is slightly different.
I like your 2nd solution. I will go check what libraries are using this assumesPageView and check these integrations behaviour. I am wanting to do a major refactor of this package which would hopefully enable the ability to users to use any of the segment.io's analytics-integrations. So your suggestion aligns nicely with this plan of mine. Hopefully I can incorporate them together.
I will keep you upto date on any progress I make.
Closing this issue as there has been no activity and believe it to be resolved. Please re-open if this bug comes back.
The proposed solution is not a fix for the problem. The problem is that some (a lot) of the tracking services require data when they get initialised. The function that will track a page, will only do that once the ready event has been returned from the analytics.js package. This event will never come in this case as e.g. the Hubspot package will only initialise once there is data
const trackPageWhenReady = (...args) => analytics.ready(() => { . *** This will only happen *** return analytics.page.apply(this, args) *** once this has been executed *** });
So if you want to solve it you need to at least have one call of analytics.page.apply before having the others inside the ready check.
I'm encountering the same issue.
If I have Google Analytics, Intercom and Mixpanel defined in settings.json it's working. If I add Hubspot to settings.json also, no analytics are getting through to Mixpanel.