Untitled

mail@pastecode.io avatar
unknown
javascript
a year ago
1.0 kB
3
Indexable
Never
import 'angular-google-tag-manager';

const ptmApp = angular.module('ptmApp', [
  // other module dependencies
  'angular-google-tag-manager'
]);

const configApp = function configApp($stateProvider, $httpProvider, routerProvider, TagManagerProvider, $provide, $urlRouterProvider) {
  // Other configuration code

  TagManagerProvider.setGTMId('GTM-XXXXXX'); // Replace with your Google Tag Manager ID
};

ptmApp.config(configApp);

ptmApp.run(function (TagManager) {
  TagManager.initialize();
});

ptmApp.run(function ($rootScope, $location, TagManager) {
  $rootScope.$on('$stateChangeSuccess', function (event, toState, toParams) {
    TagManager.sendPageView({
      pageName: toState.name,
      location: $location.url(),
      // Add any other data you want to send with the page view event
    });
  });
});

angular.element(document).ready(function BootstrapApplication() {
  return angular.bootstrap(document.getElementById('app'), ['ptmApp'], { strictDi: true });
});

export default ptmApp;