angular-tag-commander
This service lets you integrate Tag Commander in your AngularJS applications easily.
Features
- automatic page tracking
- event catching
- multiple containers
Installation and Quick Start
The quick start is designed to give you a simple, working example for the most common usage scenario. There are numerous other ways to configure and use this library as explained in the documentation.
1- Installation:
You can install the module from a package manager of your choice directly from the command line
# Bower bower install angularjs-tag-commander # NPM npm i angularjs-tag-commander
Or alternatively, grab the dist/index.es5.min.js and include it in your project
In your application, declare the angularjs-tag-commander module dependency.
or if you are using es6, import it like so
;
2- In your application, declare dependency injection:
var myApp = angular;
3- add your Tag commander containers and start tracking:
import angularJsTagCommander from 'angularjs-tag-commander'; var myApp = angular.module('tag-commander-exemple-app', [angularJsTagCommander]); myApp.config(['TagCommanderProvider', (TagCommanderProvider) => { // you need to provide URIS to load containers script. // function addContainer (id, uri, node) TagCommanderProvider.addContainer('a_name_for_the_container_id', '/the/path/to/tag-commander-container.js', 'head'); // you can add as many container as you like // but you can also remove them TagCommanderProvider.removeContainer('my_tag_container_id'); // you can set debug by setting this to true TagCommanderProvider.setDebug(true); // you can track the url of your app by setting this TagCommanderProvider.trackRoutes(true); // you can also set the name of the event witch is triggered the page change, // the default is set to '$routeChangeSuccess' TagCommanderProvider.setPageEvent('$stateChangeSuccess');}]);
Congratulations! angularjs-tag-commander is ready
Declaring TagCommander in your Controller
// As an example, a simple controller to make calls from: app;
Set Vars
In a controller
The setVar
call allows to set your tc_vars
.
TagCommander;// you can also override some varibleif isNewUser TagCommander;// or set/update them individualyTagCommander; // you can also remove a varTagCommander;}
As a directive
You can use the directive tcSetVars direcly on any html node
<!-- other exemples -->
Get Var
In your controller
var myVar = TagCommander;
Capture Events
In a controller
var eventId = '1234';var data = '{"env_language": $ctrl.default_language}'; TagCommander;
As a directive
change to default language
How to reload your container
When you update your varible you also need to update your container to propagate the changes
var idc = '1234';var ids = '1234';var options = exclusions: "datastorage" "deduplication" "internalvars" "privacy" ;TagCommander;// or you can reload all the containersTagCommander;
Automatic reload of your containers by tracking Routes
The configuration
you need to set TagCommanderProvider.trackRoutes(true); to true in your app configuration
TagCommanderProvider;
then you can configure the your route by using the tcRealoadOnly option in your route configuration
const appRouteProvider = '$routeProvider' '$locationProvider' { $routeProvider };
If you don't set the TagCommanderProvider.trackRoutes(true); (or you set it to false) you will have to reload your container manually
// somewhere in your controller// reload a specifique containerTagCommander;// or you can reload all the containersTagCommander;
Sample app
To help you with your implementaiton we provided a sample application. to run it
cd tag-commander-sample-appyarn start
then go to http://localhost:8080
License
As AngularJS itself, this module is released under the permissive MIT License. Your contributions are always welcome.
Development
After forking you will need to run the following from a command line to get your environment setup:
yarn install
After install you have the following commands available to you from a command line:
gulp