When a user visits my site, I need to immediately grab a tracking ID from their cookies, and access a TrackingIds
collection.
Template.layout.onRendered(function () {
debugger;
let trackingId = Cookie.get('trackingId');
if (trackingId) {
let trackingInfo = TrackingIds.findOne(trackingId);
if (trackingInfo) {
Session.set('limitProductsTo', {
slug: {
$in: trackingInfo.slugs
}
});
}
}
[...]
TrackingIds.findOne
keeps returning null
, even though I have this in /client/lib
:
Meteor.startup(function () {
Meteor.subscribe('trackingIds');
});
I thought things in lib
were executed first, before everything else. I’m confused about where I need to subscribe to this publication so that all my templates can access it very early on, possibly even in onCreated
.
Thanks!