yireo-magento1 / Yireo_GoogleTagManager

Implement Google Tag Manager in Magento 1 (deprecated)
Open Software License 3.0
56 stars 46 forks source link

Question on constant attributes within session #70

Closed gety9 closed 7 years ago

gety9 commented 7 years ago

We would like to add theme data layer attribute.

Since it is constant within session i wonder what's the most performant way to do this. For example theme variable can be get using: Mage::getSingleton('core/design_package')->getTheme('template'); But this way it will be run on every page within one session. (A PHP singleton is a single instance of a class per HTTP Request)

Would it be better to pass this variable to session and read from it? For example

$theme = Mage::getSingleton('core/design_package')->getTheme('template');
Mage::getSingleton('core/session')->setCurrentTheme($theme);

and than get theme variable using Mage::getSingleton('core/session')->getCurrentTheme();

This way it will be also run on every page, but i assume reading from session is more performant than using Mage::getSingleton('core/design_package')->getTheme('template');

Does it make sense?

jissereitsma commented 7 years ago

I'm not sure if I can actually advise you on this, as part of this free extension repository. But I would simply check up on the code of Magento with something like XDebug and see whether the theme is called upon on every page. I bet it is, because without a theme there is no themed output. And that theme is fetched through a singleton. Storing it in the session on top of this will decrease performance. But please take note that this is nothing to do with this extension, but everything to do with how Magento architecture fits together. I'm closing this issue, because it is not related to this extension.

gety9 commented 7 years ago

jissereitsma, thank you for your advice. It's very valuable. If you don't mind could i ask last question to be pointed in right direction?

If we are talking about functions that are not called on each page by default?

For example if would like to pass deviceType, and locationState,

to get first i will be using mobiledetect php library, and 2nd - GeoIP2 php library.

Since they are constant per session, and in fact per device/user i would like them to be called once per session. So after initial writing variables into session file, getting variables from session should be much more performant than recalculating them again.

Am i right here?

Ideally i would like if something like Singleton per session would exist - load variable once per session(not per http request/page), so you don't have to reload it again. But i don't think it exists.