@@ -10,7 +10,8 @@ describe('Google Tag Manager', function() {
1010 var analytics ;
1111 var gtm ;
1212 var options = {
13- containerId : 'GTM-M8M29T'
13+ containerId : 'GTM-M8M29T' ,
14+ environment : ''
1415 } ;
1516
1617 beforeEach ( function ( ) {
@@ -33,6 +34,7 @@ describe('Google Tag Manager', function() {
3334 . assumesPageview ( )
3435 . global ( 'dataLayer' )
3536 . option ( 'containerId' , '' )
37+ . option ( 'environment' , '' )
3638 . option ( 'trackNamedPages' , true )
3739 . option ( 'trackCategorizedPages' , true ) ) ;
3840 } ) ;
@@ -45,6 +47,10 @@ describe('Google Tag Manager', function() {
4547
4648 describe ( 'after loading' , function ( ) {
4749 beforeEach ( function ( done ) {
50+ options = {
51+ containerId : 'GTM-M8M29T' ,
52+ environment : ''
53+ } ;
4854 analytics . once ( 'ready' , done ) ;
4955 analytics . initialize ( ) ;
5056 analytics . page ( ) ;
@@ -169,4 +175,19 @@ describe('Google Tag Manager', function() {
169175 } ) ;
170176 } ) ;
171177 } ) ;
178+
179+ describe ( 'environment options' , function ( ) {
180+ it ( 'should use the right tag if the environment option is set' , function ( ) {
181+ gtm . options = {
182+ containerId : 'GTM-M8M29T' ,
183+ environment : 'test'
184+ } ;
185+
186+ var tag = '<script src="http://www.googletagmanager.com/gtm.js?id=' + gtm . options . containerId + '&l=dataLayer>m_preview=' + gtm . options . environment + '">' ;
187+ analytics . spy ( gtm , 'load' ) ;
188+ analytics . initialize ( ) ;
189+ analytics . page ( ) ;
190+ analytics . loaded ( tag ) ;
191+ } ) ;
192+ } ) ;
172193} ) ;
0 commit comments