Giter Club home page Giter Club logo

integration-angularjs's Introduction

Tealium AngularJS Integration

Installation

Using Bower

bower install angular-tealium

Using NPM

npm install https://github.com/Tealium/integration-angularjs

Using the /sample app

(1) After installation, navigate to your directory where the sample folder is located

cd ./myapp/node_modules/angular-tealium/sample

(2) Update the tealiumProvider.setConfig params for 'account' and 'profile' to your own Tealium account/profile combination

vi script.js
account: 'UPDATE_TO_YOUR_ACCOUNT',
profile: 'UPDATE_TO_YOUR_PROFILE',

(3) Start up a web server in this directory

python -m http.server 8000 --bind 127.0.0.1

(4) Load up http://localhost:8000/ in your web browser

(5) NOTE: Configure tags in Tealium iQ and publish to 'dev' environment if you haven't already

(6) Use proxy tool or Network tab in your browser Console to see your tags fire

Updated to use the Provider pattern

This repository was last modified to use the Provider pattern.

Contributors

Providers have the advantage of being available in an application's config block, meaning tealium.js and tealium_data.js do not need to be modified directly. For example:

app.config(function(tealiumProvider) {
  tealiumProvider.setConfig({
    account: 'tealiummobile',
    profile: 'demo',
    environment: 'dev',
    suppress_first_view: true
  });
  tealiumProvider.setViewIdMap({
    '/index': function () {
      return {
        data1: 1,
        data2: 2
      };
    }
  });
});

A directive has also been created. Specifying 'data-tealium' attribute on an element binds this data to Tealium's link function on click. Additional data can be passed to provide details for the specific event:

<button data-tealium='{"event":"button pressed", "button_name":"button2"}'>
  Button
</button>

Modules

This is a sample module to integrate Tealium iQ into your site easily. The main library for Tealium is tealium_angular.js which has the following parts

  • TealiumHelper - Loads the Tealium JavaScript (utag.js) file and sets up tracking function (tealium.track)

  • TealiumHelper.data - Returns the custom data layer for the specific view

  • TealiumHelper.directive - Add element-specific data to data layer from "data-tealium" element data attribute

Sample usage

In your app module add the 'TealiumHelper' dependency example:

var app = angular.module('app', ['TealiumHelper']);

Option 1

In your application controller add the following function to its scope example:

app.controller('appController',
    function($scope, tealium) {
     $scope.tealiumView = tealium.view;
    }
 );

You can then use tealiumView() anywhere thats within scope of your app controller to fire a tealium view, effectively simulating a page view event. example:

< body ng-app="App" >
...
   < div class="slide-animate-container" >
     < div ng-view class="slide-animate" >
     ...
       < div ng-include="template.url" onload= "tealiumView()" >< /div >
     < /div >
   < /div >
 < /div >
< /body >

Option 2

Alternatively you can include the TealiumHelper module in your route logic and call tealium.view() in your $includeContentLoaded callback example:

$scope.$on("$includeContentLoaded",
    function () {
      tealium.view();
    });

Configuring the Tealium Module

The follow configuration settings are required

  • account (String) Tealium iQ account
  • profile (String) Tealium iQ profile
  • environment (String) Tealium iQ environment ("dev", "qa", "prod")

The example in script.js shows how to configure

  tealiumProvider.setConfig({
      account: 'myaccount',
      profile: 'myprofile',
      environment: 'prod',
      suppress_first_view: true
  });

Example

  • For an example, see files in /sample folder. This sample app uses the Option 2 method described above.

  • Any element marked with "data-tealium" will be tracked as a link click event (using utag.link)

  • In the /sample/template1.html you can see how utag.link calls fire based on button clicks. To see the data layer with each call to utag.link, set debug cookie in console: document.cookie="utagdb=true"

  • Only a specific set of tags in Tealium's Tag Marketplace support the utag.link event tracking and some (i.e. Google Analytics) will require mapping

  • This module defines tealium.track which is a wrapper to utag.track.

    tealium.track( "view", {
      page_name : "my page",
      event_name : "my event",
      more_data : "any data"
    });

integration-angularjs's People

Contributors

evandam avatar reidbraswell avatar runfaj avatar tommaitland avatar tygavin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

integration-angularjs's Issues

npm support please

I see that you have included support for bower but as many developers are moving away from using it (as it's unnecessary and basically redundant) including this within the npm registry would be beneficial.

See this old post: https://gofore.com/stop-using-bower/

Even if you just include a compatible package.json without submitting to npm we could install via git url.

Completely destroys our test cases now..

With the latest update (worked fine on v1.1.1), Getting:

Error: [$injector:modulerr] Failed to instantiate module TealiumHelper due to:
Error: [$injector:nomod] Module 'TealiumHelper' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.

Script cs.js added on each "view" event

I noticed that each time I generate a view event, a new line is added in the header of my webpage :

<script type="text/javascript" async="" id="tealium-tag-3005" src="https://sb.scorecardresearch.com/c2/5641052/cs.js"></script>

So, after some time browsing the site, the header is filled up with hundreds of lines like that.

I found that this line is added by this function (in utag.8.js):

(function() {
  var id = "tealium-tag-3005";
  if (a === "link" && document.getElementById(id)) {
    return;
  }
  var t = document.createElement("script");
  t.type = "text/javascript";
  t.async = true;
  t.id = id;
  t.src = u.data.base_url;
  var s = document.getElementsByTagName("script")[0];
  s.parentNode.insertBefore(t, s);
})();

So, in case of a "link" event, the script addition is avoided when already present, but for a "view" event, the script is added every time.

Cannot Trigger the directive

I have<input type="button" value="try me" data-tealium='{"event":"button pressed", "try_me": "test"}'>
in my app.js.


tealiumProvider.setConfig({
            account: 'xxx',
            profile: 'xxxx',
            environment: 'xxxx',
            suppress_first_view: true
        });

        var home = function() {
            var data = {
                "page_type" : "home",
                "date"      : Date(),
                "key"       :"value"
              };
            return data;
        };
        var product = function() {
            var data = {
                "page_type" : "product",
                "key2"  : "value2"
              };
            return data;
        };
        var generic = function() {
            var data = {
                "page_type" : "generic",
                "key"  : "generic value"
            };
            return data;
        };

        tealiumProvider.setViewIdMap({
          '' : home,
          '/template1.html' : home,
          '/template2.html' : product,
          'generic'         : generic
        });

and event if i click on the input nothing is sent

Not able to use it in Cordova App

Hi,

I wanted to use this Tealium angularjs plugin for Cordova Hybrid application. I am working on iOS, Android and Windows Phone all three platform. When I try to integrate it I am getting below error

GET **file://tags.tiqcdn.com/utag/xxxcompanyxxx/xxtagxx/dev/utag.2.js?**utv=ut4.36.201504131642 utag.js:65
utag.ut.loader utag.js:65
utag.loader.AS utag.js:8
utag.loader.WQ utag.js:4
(anonymous function)

In cordova it add file:// protocol before the script call but it should add http://. Thats why I am getting below error. Please have a look and check this issue.

No error catching

We noticed a bug with the code.. Granted, it's edge case..

If you are running ghostery and have disabled Tealium, it will error out the page with "TypeError: utag.view is not a function", TypeError: utag.link is not a function" and "TypeError: utag.track is not a function".

This could probably be resolved with wrapping them in try/catch?

var track = function( ev, data ) {
        var data = data || tealiumData.getDataLayer( $location.path() );
        var ev = ev || "view";
        var src = config.script_src;

        if ( typeof utag == "undefined" ) {
          getScript( src, function(){
              try {
                  utag.track(ev, data)
              }
              catch(err){return false;}
          })
        } else {
            try {
                utag.track(ev, data)
            }
            catch(err){return false;}
        }

      };

Dennis

View call at run method

If i try to fire a view call at run method, though utag.js file is loaded , utag is returning undefined. Seems like utag.js will load and connect to utag_data only after angular loads. do u have any sample to call in angular run method

Update Readme

Hi

A tiny typo on your project readme here on github.
tealiumProvider.config({...})
should be
tealiumProvider.setConfig({...})

Unable to set the config.environment value after tealium has been created (which is required as soon as the platform cannot be hard coded, but comes from a config file or elsewhere in an asynchronous manner)

tealium_angular_fixed.js.zip
Here is the bug / issue we have faced:
"environment" value is supplied in a, asynchronous manner because comes from a config file (same problem if cpming from api server calls, with $http.get which is asyncchornous by nature

Therefor, in the .config of the tealium service (where tealimuProvider is available), this asynchronous value cannot be known at this step...)
But the problem is that the tealimu API has no setConfig nor setConfigValue method...

By angularJs spec, it is not possible to inject a service into a Povider (service provider), the only place where setConfig or setConfigValue can be set (same isssue if injecting $http ng service because it is by nature asynchronous. this men

Attached is a proposed fixed (which only expose a setEnvironment function on tealium object) , so that we can set this asynchronously , after tealium instantiation, not at the provider level.
So the usage is :
1 first , at tealiumProvider lelve, setConfig orSetConfig Value as you would do before.
2. after tealium instantiation, inside the contructor of your service using tealimu, get the env value (from another config service in general, qwhich is set as resolve dependency of this one), and cakl this new method like this "tealium.setEnvironment(myPlatform)" (where myPlatform is either dev, qa or prod.

Could you please fix this issue which is imo blocking for a majority of projects, since the env platform is dynamic (cannot be hard coded because depends upon the testbed / runtime environment)
tealium_angular_fixed.js.zip

Expose setViewIdMap

Can you expose the setViewIdMap method so this can be configured/updated from within a service?

It's not ideal to have to include lots of analytics within the main application config method and reduces scaleability.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.