@@ -2628,7 +2628,7 @@ describe('Google Analytics 4 Event', function () {
2628
2628
done ( ) ;
2629
2629
} ) ;
2630
2630
2631
- it ( 'should merge Consent Setting Defaults with User Consent State to construct a Default Consent State' , ( done ) => {
2631
+ it ( 'should construct a Default Consent State Payload from Default Settings and construct an Update Consent State Payload from Mappings ' , ( done ) => {
2632
2632
mParticle . forwarder . init (
2633
2633
{
2634
2634
conversionId : 'AW-123123123' ,
@@ -2643,9 +2643,20 @@ describe('Google Analytics 4 Event', function () {
2643
2643
true
2644
2644
) ;
2645
2645
2646
- var expectedDataLayer = [
2646
+ var expectedDataLayer1 = [
2647
2647
'consent' ,
2648
2648
'default' ,
2649
+ {
2650
+ ad_personalization : 'granted' , // From Consent Settings
2651
+ ad_user_data : 'granted' , // From Consent Settings
2652
+ ad_storage : 'granted' , // From Consent Settings
2653
+ analytics_storage : 'granted' , // From Consent Settings
2654
+ } ,
2655
+ ] ;
2656
+
2657
+ var expectedDataLayer2 = [
2658
+ 'consent' ,
2659
+ 'update' ,
2649
2660
{
2650
2661
ad_personalization : 'denied' , // From User Consent State
2651
2662
ad_user_data : 'denied' , // From User Consent State
@@ -2656,10 +2667,13 @@ describe('Google Analytics 4 Event', function () {
2656
2667
2657
2668
// Initial elements of Data Layer are setup for gtag.
2658
2669
// Consent state should be on the bottom
2659
- window . dataLayer . length . should . eql ( 4 ) ;
2670
+ window . dataLayer . length . should . eql ( 5 ) ;
2660
2671
window . dataLayer [ 3 ] [ 0 ] . should . equal ( 'consent' ) ;
2661
2672
window . dataLayer [ 3 ] [ 1 ] . should . equal ( 'default' ) ;
2662
- window . dataLayer [ 3 ] [ 2 ] . should . deepEqual ( expectedDataLayer [ 2 ] ) ;
2673
+ window . dataLayer [ 3 ] [ 2 ] . should . deepEqual ( expectedDataLayer1 [ 2 ] ) ;
2674
+ window . dataLayer [ 4 ] [ 0 ] . should . equal ( 'consent' ) ;
2675
+ window . dataLayer [ 4 ] [ 1 ] . should . equal ( 'update' ) ;
2676
+ window . dataLayer [ 4 ] [ 2 ] . should . deepEqual ( expectedDataLayer2 [ 2 ] ) ;
2663
2677
2664
2678
done ( ) ;
2665
2679
} ) ;
@@ -2877,7 +2891,18 @@ describe('Google Analytics 4 Event', function () {
2877
2891
true
2878
2892
) ;
2879
2893
2880
- var expectedDataLayerBefore = [
2894
+ var expectedDataLayerBefore1 = [
2895
+ 'consent' ,
2896
+ 'default' ,
2897
+ {
2898
+ ad_personalization : 'granted' , // From Consent Settings
2899
+ ad_user_data : 'granted' , // From Consent Settings
2900
+ ad_storage : 'granted' , // From Consent Settings
2901
+ analytics_storage : 'granted' , // From Consent Settings
2902
+ } ,
2903
+ ] ;
2904
+
2905
+ var expectedDataLayerBefore2 = [
2881
2906
'consent' ,
2882
2907
'update' ,
2883
2908
{
@@ -2889,11 +2914,15 @@ describe('Google Analytics 4 Event', function () {
2889
2914
] ;
2890
2915
2891
2916
// Initial elements of Data Layer are setup for gtag.
2892
- // Consent state should be on the bottom
2893
- window . dataLayer . length . should . eql ( 4 ) ;
2917
+ // Default Consent payload from default settings should be index 3
2918
+ // Update Consent payload from mappings should be on the bottom (index 4)
2919
+ window . dataLayer . length . should . eql ( 5 ) ;
2894
2920
window . dataLayer [ 3 ] [ 0 ] . should . equal ( 'consent' ) ;
2895
2921
window . dataLayer [ 3 ] [ 1 ] . should . equal ( 'default' ) ;
2896
- window . dataLayer [ 3 ] [ 2 ] . should . deepEqual ( expectedDataLayerBefore [ 2 ] ) ;
2922
+ window . dataLayer [ 3 ] [ 2 ] . should . deepEqual ( expectedDataLayerBefore1 [ 2 ] ) ;
2923
+ window . dataLayer [ 4 ] [ 0 ] . should . equal ( 'consent' ) ;
2924
+ window . dataLayer [ 4 ] [ 1 ] . should . equal ( 'update' ) ;
2925
+ window . dataLayer [ 4 ] [ 2 ] . should . deepEqual ( expectedDataLayerBefore2 [ 2 ] ) ;
2897
2926
2898
2927
mParticle . forwarder . process ( {
2899
2928
EventName : 'Homepage' ,
@@ -2950,12 +2979,13 @@ describe('Google Analytics 4 Event', function () {
2950
2979
2951
2980
// Initial elements of Data Layer are setup for gtag.
2952
2981
// Consent Default is index 3
2953
- // Consent Update is index 4
2954
- // Event is index 5
2955
- window . dataLayer . length . should . eql ( 6 ) ;
2956
- window . dataLayer [ 4 ] [ 0 ] . should . equal ( 'consent' ) ;
2957
- window . dataLayer [ 4 ] [ 1 ] . should . equal ( 'update' ) ;
2958
- window . dataLayer [ 4 ] [ 2 ] . should . deepEqual ( expectedDataLayerAfter [ 2 ] ) ;
2982
+ // Initial Consent Update from mappings is index 4
2983
+ // Consent Update #2 is index 5
2984
+ // Event is index 6
2985
+ window . dataLayer . length . should . eql ( 7 ) ;
2986
+ window . dataLayer [ 5 ] [ 0 ] . should . equal ( 'consent' ) ;
2987
+ window . dataLayer [ 5 ] [ 1 ] . should . equal ( 'update' ) ;
2988
+ window . dataLayer [ 5 ] [ 2 ] . should . deepEqual ( expectedDataLayerAfter [ 2 ] ) ;
2959
2989
2960
2990
mParticle . forwarder . process ( {
2961
2991
EventName : 'Homepage' ,
@@ -3022,14 +3052,15 @@ describe('Google Analytics 4 Event', function () {
3022
3052
3023
3053
// Initial elements of Data Layer are setup for gtag.
3024
3054
// Consent Default is index 3
3025
- // Consent Update is index 4
3026
- // Event is index 5
3027
- // Consent Update #2 is index 6
3028
- // Event #2 is index 7
3029
- window . dataLayer . length . should . eql ( 8 ) ;
3030
- window . dataLayer [ 6 ] [ 0 ] . should . equal ( 'consent' ) ;
3031
- window . dataLayer [ 6 ] [ 1 ] . should . equal ( 'update' ) ;
3032
- window . dataLayer [ 6 ] [ 2 ] . should . deepEqual ( expectedDataLayerFinal [ 2 ] ) ;
3055
+ // Initial Consent Update from mappings is index 4
3056
+ // Consent Update #2 is index 5
3057
+ // Event is index 6
3058
+ // Consent Update #3 is index 7
3059
+ // Event #2 is index 8
3060
+ window . dataLayer . length . should . eql ( 9 ) ;
3061
+ window . dataLayer [ 7 ] [ 0 ] . should . equal ( 'consent' ) ;
3062
+ window . dataLayer [ 7 ] [ 1 ] . should . equal ( 'update' ) ;
3063
+ window . dataLayer [ 7 ] [ 2 ] . should . deepEqual ( expectedDataLayerFinal [ 2 ] ) ;
3033
3064
done ( ) ;
3034
3065
} ) ;
3035
3066
0 commit comments