- TLC Home Home
- Discussions Discussions
- Documentation Documentation
- Knowledge Base Knowledge Base
- Education Education
- Blog Blog
- Support Desk Support Desk
08-07-2017 08:34 AM
Hello,
has anyone had experience with the onHandler in conjunction with require.js?
We are trying to use the jQuery onHandler extension in TiQ, but it is silently failing. When trying a command on the console, it fails (as is expected) with "Uncaught TypeError: $ is not a function" when not using require().
Probably, some kind of call such as this would be needed outside of the code generated by the onHandler Extension:
require(['jquery'], function($) { ... })
As of now, the only solution seems to be to write a Javascript extension to trigger tracking. Is there a way to get the standard onHandler Extension to work with require.js so that people without JavaScript permissions will again be able to implement Event Tracking?
Thanks in advance,
Michael
Solved! Go to Solution.
08-08-2017 12:07 PM
Michael:
What do you mean by this statement?
so that people without JavaScript permissions will again be able to implement Event Tracking?
This would be tough. I'm assuming that:
1. You're trying to prevent jQuery from populating the global namespace so you've required your own build? And in this build you've disabled the global exports of $ and jQuery?
08-09-2017 12:59 AM - last edited on 08-09-2017 08:25 AM by kathleen_jo
Hello @Mauricio,
exactly, the global exports are not visible, so the onHandler extension fails. Without the onHandler extension, only people with JavaScript permission can then enable tracking by creating a DOM Ready JavaScript extension that wraps the calls in something like "require(['jquery'], function($) {" .
I assume this line is fairly standard, so I think it could work if the onHandler extension where modified to have an optional configuration parameter like "use require.js" with an String parameter "require library name" where one could input the "jquery" and then the generated code would have to have the onHandler-code wrapped in a line like above.
This would give the possibilty to use the onHandler by configuration only, therefore also to people not authorized to inject JavaScript.
Is that a possibility, or is there another way to achieve this goal?
08-09-2017 12:07 PM - last edited on 08-09-2017 12:29 PM by kathleen_jo
@michael_sievers, I'm sorry to say that without permissions for you to use a javascript code extension I cannot propose any workarounds for your problem. If you don't have those permissions, and the site owner has decided not to export jQuery then there's not much you can do from TIQ.
The on handler extension relies on the jQuery variable, not $ by the way. you might want to suggest they export jQuery so you can use the onhandler extension if they are not going to give you access to the javascript code extension.
08-10-2017 12:25 AM
Copyright All Rights Reserved © 2008-2023