@@ -8,6 +8,7 @@ var plugin = require('../lib/');
88// GA saves arrays as argument objects and `assert.deepEquals` fails when comparing
99// argument objects against arrays!
1010var toArray = require ( 'to-array' ) ;
11+ var _ = require ( 'lodash' ) ;
1112
1213describe ( 'Google Analytics' , function ( ) {
1314 var GA = plugin . Integration ;
@@ -64,7 +65,7 @@ describe('Google Analytics', function() {
6465 siteSpeedSampleRate : 42 ,
6566 sampleRate : 15 ,
6667 trackingId : 'UA-27033709-12' ,
67- useGoogleAmpClientId : false
68+ useGooleAmpClientId : false
6869 } ;
6970
7071 beforeEach ( function ( ) {
@@ -129,7 +130,14 @@ describe('Google Analytics', function() {
129130 if ( window . location . hostname !== 'localhost' ) expectedOpts . cookieDomain = 'auto' ;
130131 analytics . initialize ( ) ;
131132 analytics . page ( ) ;
132- analytics . deepEqual ( toArray ( window . ga . q [ 0 ] ) , [ 'create' , settings . trackingId , expectedOpts ] ) ;
133+
134+ // some workaround for useGoogleAmpClientId as the name passed to GA needed to change to useAMPclientID
135+ // but the tests expect the option name to == the parameter passed
136+ var expectedOptsOmitAmp = _ . omit ( expectedOpts , [ 'useGoogleAmpClientId' ] ) ;
137+ var gaOptsOmitAmp = _ . omit ( window . ga . q [ 0 ] [ 2 ] , 'useAMPclientID' ) ;
138+ window . ga . q [ 0 ] [ 2 ] = gaOptsOmitAmp ;
139+
140+ analytics . deepEqual ( toArray ( window . ga . q [ 0 ] ) , [ 'create' , settings . trackingId , expectedOptsOmitAmp ] ) ;
133141 } ) ;
134142
135143 it ( 'should name ga tracker if opted in' , function ( ) {
@@ -144,22 +152,35 @@ describe('Google Analytics', function() {
144152 ga . options . nameTracker = true ;
145153 analytics . initialize ( ) ;
146154 analytics . page ( ) ;
147- analytics . deepEqual ( toArray ( window . ga . q [ 0 ] ) , [ 'create' , settings . trackingId , expectedOpts ] ) ;
155+
156+ // some workaround for useGoogleAmpClientId as the name passed to GA needed to change to useAMPclientID
157+ // but the tests expect the option name to == the parameter passed
158+ var expectedOptsOmitAmp = _ . omit ( expectedOpts , [ 'useGoogleAmpClientId' ] ) ;
159+ var gaOptsOmitAmp = _ . omit ( window . ga . q [ 0 ] [ 2 ] , 'useAMPclientID' ) ;
160+ window . ga . q [ 0 ] [ 2 ] = gaOptsOmitAmp ;
161+
162+ analytics . deepEqual ( toArray ( window . ga . q [ 0 ] ) , [ 'create' , settings . trackingId , expectedOptsOmitAmp ] ) ;
148163 } ) ;
149164
150165 it ( 'should use AMP Id as the Client Id if the setting is enabled' , function ( ) {
151- ga . options . useAmpClientId = true ;
166+ ga . options . useAMPclientID = true ;
152167 var expectedOpts = {
153168 cookieDomain : 'none' ,
169+ useGoogleAmpClientId : true ,
154170 siteSpeedSampleRate : settings . siteSpeedSampleRate ,
155171 sampleRate : settings . sampleRate ,
156- allowLinker : true ,
157- useGoogleAmpClientId : true
172+ allowLinker : true
158173 } ;
159174
160175 analytics . initialize ( ) ;
161176 analytics . page ( ) ;
162- analytics . deepEqual ( toArray ( window . ga . q [ 0 ] ) , [ 'create' , settings . trackingId , expectedOpts ] ) ;
177+ // some workaround for useGoogleAmpClientId as the name passed to GA needed to change to useAMPclientID
178+ // but the tests expect the option name to == the parameter passed
179+ var expectedOptsOmitAmp = _ . omit ( expectedOpts , [ 'useGoogleAmpClientId' ] ) ;
180+ var gaOptsOmitAmp = _ . omit ( window . ga . q [ 0 ] [ 2 ] , 'useAMPclientID' ) ;
181+ window . ga . q [ 0 ] [ 2 ] = gaOptsOmitAmp ;
182+
183+ analytics . deepEqual ( toArray ( window . ga . q [ 0 ] ) , [ 'create' , settings . trackingId , expectedOptsOmitAmp ] ) ;
163184 } ) ;
164185
165186 it ( 'should call window.ga.require for optimize if enabled' , function ( ) {
0 commit comments