react-tag-commander Sample application
-The loading and configuration
-The main application configuration
--- -import
TC_Wrapper
from
'react-tag-commander'
;
-const
wrapper
=TC_Wrapper
.getInstance
();
-
-{'// you need to provide URIS to load containers script. You can add as many container as you like'}
-{'// addContainer (id, uri, node)'}
-wrapper
.addContainer
('a_name_for_the_container_id'
,'/the/path/to/tag-commander-container.js'
,'head'
);
-
-{'// but you can also remove them'}
-wrapper
.removeContainer
('my_tag_container_id'
);
-
-{'// you can set debug by setting this to true'}
-wrapper
.setDebug
(true
);
-
-{'// you can track the url of your app by setting this, it will reload the containers on each page change'}
-wrapper
.trackRoutes
(true
);
-
- In the provider's method 'addContainer', The "node" parameter can either be set to 'body' or 'head', by default the container will be placed in the head. -
- -The routes configuration
-- If you have set wrapper.trackRoutes(true); in your application configuration, - you can configure witch container will be reloaded on witch route, else what you need to do it in your controller. - the containers will be reloaded after the controller has been executed, - but if you change or set a varible in your controller methode you will need to call wrapper.reloadAllContainers(options) - to propagate the changes to your containers. -
- -- If you don't set the TagCommanderProvider.trackRoutes(true); (or you set it to false) you will have to reload your container manually -
--- -{'// reload a specifique container'}
-wrapper
.reloadContainer
(ids
,idc
,options
);
-
-{'// or you can reload all the containers'}
-wrapper
.reloadAllContainers
(options
);
-
How to set your Vars
-In a component
-- The setVar call allows to set your tc_vars. -
--- -wrapper
.setTcVars
({'{'}
-env_template
:"shop"
,
-env_work
:"dev"
,
-env_language
:"en"
,
-user_id
:"124"
,
-user_logged
:"true"
,
-user_age
:"32"
,
-user_newcustomer
:"false"
-{'}'});
-
-{'// you can also override some varible'}
-if
(isNewUser
) {'{'}
-wrapper
.setTcVars
({'{'}
-user_newcustomer
:"true"
-{'}'});
-
-{'// or set/update them individualy'}
-wrapper
.setTcVar
('env_template'
,'super_shop'
);
-
-{'// you can also remove a var'}
-wrapper
.removeTcVars
('env_template'
);
-
In render function(JSX)
-- You can set your tc_vars with the TcVars Component -
-- <-TcVars
env_language
="fr"
env_template
="super_shop"
/> -