Skip to content

Commit edca719

Browse files
committed
A fullish suite of tests.
1 parent 0678462 commit edca719

23 files changed

Lines changed: 770 additions & 83 deletions

features/404_tracking.feature

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Feature: DAP modifies page_location for 404 pages
2+
3+
Background:
4+
Given I load an empty browser
5+
And DAP is configured for agency "GSA"
6+
7+
Scenario: Page title containing "404" sets page_location to a vpv404 path
8+
When I load the test page "404.html"
9+
Then the config call for the DAP property has "page_location" containing "/vpv404/"
10+
11+
Scenario: Page title containing "not found" sets page_location to a vpv404 path
12+
When I load the test page "not-found.html"
13+
Then the config call for the DAP property has "page_location" containing "/vpv404/"
14+
15+
Scenario: 404 page without a referrer does not append a referrer to page_location
16+
When I load the test page "404.html"
17+
Then the config call for the DAP property has "page_location" containing "/vpv404/404.html"
18+
19+
Scenario: 404 page with a referrer appends the referrer to page_location
20+
When I load the test site
21+
And I load the test page "404.html"
22+
Then the config call for the DAP property has "page_location" containing "/vpv404/"
23+
And the config call for the DAP property has "page_location" containing "http://localhost:8080/"

features/beacon_payload.feature

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Feature: GA4 beacon contains expected parameters
2+
3+
Background:
4+
Given I load an empty browser
5+
And I set the browser to intercept outbound requests
6+
And DAP is configured for agency "GSA"
7+
8+
Scenario: GA4 beacon includes the page URL and title
9+
When I load the test site
10+
And I wait 5 seconds
11+
Then there is a GA4 request with parameters
12+
| dl | http://localhost:8080/ |
13+
| dt | DAP test site |
14+
15+
Scenario: GA4 beacon includes the document referrer when navigating from another page
16+
When I load the test site
17+
And I load the test page "404.html"
18+
And I wait 5 seconds
19+
Then there is a GA4 request with parameters
20+
| dl | http://localhost:8080/404.html |
21+
| dr | http://localhost:8080/ |

features/configuration.feature

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,21 @@ Feature: A site can load the DAP code with varying levels of customization
1919
Then DAP will set custom dimensions for the DAP property
2020
| agency | GSA |
2121
| site_topic | analytics |
22-
| site_platform | cloud.gov |
22+
| site_platform | cloud.gov |
23+
24+
Scenario: Load a DAP-enabled page and check the built-in customer dimensions
25+
Given DAP is configured for agency "GSA"
26+
When I load the test site
27+
Then DAP will set custom dimensions for the DAP property
28+
| protocol | http: |
29+
| hostname_dimension | localhost |
30+
| using_parallel_tracker | no |
31+
And the DAP property config has script_source set to the DAP script URL
32+
And the DAP property config has version matching "\d{8} v\d+\.\d+ - ga4"
33+
34+
Scenario: Setting cto configures the cookie expiration in the config call
35+
Given DAP is configured for agency "GSA"
36+
And DAP is configured with cookie timeout of 1 months
37+
When I load the test site
38+
Then DAP will set custom dimensions for the DAP property
39+
| cookie_expires | 2628000 |

features/gapim.feature

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Feature: gapim is not a supported API
2+
3+
Background:
4+
Given I load an empty browser
5+
And DAP is configured for agency "GSA"
6+
7+
Scenario: Calling gapim() to send a virtual pageview without a title throws a ReferenceError
8+
When I load the test site
9+
Then executing script "gapim('send', 'pageview', '/virtual/page')" throws a ReferenceError
10+
11+
Scenario: Calling gapim() to send a virtual pageview with a title throws a ReferenceError
12+
When I load the test site
13+
Then executing script "gapim('send', 'pageview', '/virtual/page', 'My Title')" throws a ReferenceError
14+
15+
Scenario: Calling gapim() to send an event throws a ReferenceError
16+
When I load the test site
17+
Then executing script "gapim('send', 'event', 'category', 'action')" throws a ReferenceError

features/gas4_functions.feature

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
Feature: gas4() custom event API
2+
3+
Background:
4+
Given I load an empty browser
5+
And DAP is configured for agency "GSA"
6+
7+
Scenario: gas4() with a page_view event name sends a page_view event
8+
When I load the test site
9+
And I execute script "window.gas4('page_view', {page_location: '/virtual/page', page_title: 'Virtual Page'})"
10+
Then a "page_view" event is sent to DAP with parameters
11+
| page_location | http://localhost/virtual/page |
12+
| page_title | Virtual Page |
13+
14+
Scenario: gas4() with a valid GA4 event name sends the event
15+
When I load the test site
16+
And I execute script "window.gas4('file_download', {file_name: '/test.pdf', file_extension: 'pdf', link_text: 'Download Test PDF', link_id: 'download-link', link_url: 'https://example.gov/test.pdf', link_domain: 'example.gov', interaction_type: 'Mouse Click'})"
17+
Then a "file_download" event is sent to DAP with parameters
18+
| file_name | /test.pdf |
19+
| file_extension | pdf |
20+
| link_text | Download Test PDF |
21+
| link_id | download-link |
22+
| link_url | https://example.gov/test.pdf |
23+
| link_domain | example.gov |
24+
| interaction_type | Mouse Click |
25+
26+
Scenario: gas4() with an invalid event name falls back to dap_event
27+
When I load the test site
28+
And I execute script "window.gas4('not_a_valid_event', {some_param: 'value'})"
29+
Then a "dap_event" event is sent to DAP with parameters
30+
| some_param | value |
31+
32+
Scenario: gas4() sends a form_start event
33+
When I load the test site
34+
And I execute script "window.gas4('form_start', {form_id: 'contact-form', form_name: 'Contact Form', form_destination: '/thank-you', section: 'body'})"
35+
Then a "form_start" event is sent to DAP with parameters
36+
| form_id | contact-form |
37+
| form_name | Contact Form |
38+
| form_destination | /thank-you |
39+
| section | body |
40+
41+
Scenario: gas4() sends a form_progress event
42+
When I load the test site
43+
And I execute script "window.gas4('form_progress', {form_id: 'contact-form', percent_scrolled: '50'})"
44+
Then a "form_progress" event is sent to DAP with parameters
45+
| form_id | contact-form |
46+
| percent_scrolled | 50 |
47+
48+
Scenario: gas4() sends a form_submit event
49+
When I load the test site
50+
And I click on element with selector ".column:first-child input[type=submit]"
51+
Then a "form_submit" event is sent to DAP with parameters
52+
| form_name | <form_name> |
53+
| form_id | <form_id> |
54+
| form_destination | <form_destination> |
55+
| section | <section> |
56+
| form_submit_text | <form_submit_text> |
57+
58+
Scenario: gas4() sends a content_view event
59+
When I load the test site
60+
And I execute script "window.gas4('content_view', {content_type: 'article', content_id: '123'})"
61+
Then a "content_view" event is sent to DAP with parameters
62+
| content_type | article |
63+
| content_id | 123 |
64+
65+
Scenario: gas4() sends a share event
66+
When I load the test site
67+
And I execute script "window.gas4('share', {method: 'twitter', content_type: 'page', item_id: '123'})"
68+
Then a "share" event is sent to DAP with parameters
69+
| method | twitter |
70+
| content_type | page |
71+
| item_id | 123 |
72+
73+
Scenario: gas4() sends a social_click event
74+
When I load the test site
75+
And I execute script "window.gas4('social_click', {link_url: 'https://twitter.com', social_network: 'twitter'})"
76+
Then a "social_click" event is sent to DAP with parameters
77+
| link_url | https://twitter.com |
78+
| social_network | twitter |
79+
80+
Scenario: gas4() sends an image_click event
81+
When I load the test site
82+
And I execute script "window.gas4('image_click', {link_id: 'hero-image', link_url: '/about'})"
83+
Then a "image_click" event is sent to DAP with parameters
84+
| link_id | hero-image |
85+
| link_url | /about |
86+
87+
Scenario: gas4() sends a cta_click event
88+
When I load the test site
89+
And I click on element with selector "::-p-text(Learn More)"
90+
Then a "cta_click" event is sent to DAP with parameters
91+
| link_text | <link_text> |
92+
| link_domain | <link_domain> |
93+
| link_url | <link_url> |
94+
| link_id | <link_id> |
95+
| link_classes | <link_classes> |
96+
| outbound | <outbound> |
97+
| section | <section> |
98+
99+
Scenario: gas4() falls back to dap_event when cta event name is invalid
100+
When I load the test site
101+
And I click on element with selector "button[onclick*=\"gas4('cta',\"]"
102+
Then a "dap_event" event is sent to DAP with parameters
103+
| link_text | <link_text> |
104+
| link_domain | <link_domain> |
105+
| link_url | <link_url> |
106+
| link_id | <link_id> |
107+
| link_classes | <link_classes> |
108+
| outbound | <outbound> |
109+
| section | <section> |
110+
111+
Scenario: gas4() sends a navigation_click event
112+
When I load the test site
113+
And I click on element with selector "a[href='#home']"
114+
Then a "navigation_click" event is sent to DAP with parameters
115+
| link_text | <link_text> |
116+
| link_domain | <link_domain> |
117+
| link_url | <link_url> |
118+
| link_id | <link_id> |
119+
| link_classes | <link_classes> |
120+
| outbound | <outbound> |
121+
| section | <section> |
122+
| menu_type | <menu_type> |
123+
124+
Scenario: gas4() sends a was_this_helpful_submit event
125+
When I load the test site
126+
And I execute script "window.gas4('was_this_helpful_submit', {selection: 'yes', section: 'footer'})"
127+
Then a "was_this_helpful_submit" event is sent to DAP with parameters
128+
| selection | yes |
129+
| section | footer |
130+
131+
Scenario: gas4() sends a faq_click event
132+
When I load the test site
133+
And I click on element with selector "button::-p-text(FAQ)"
134+
Then a "faq_click" event is sent to DAP with parameters
135+
| selection | selection 1 |
136+
| section | <section> |
137+
138+
Scenario: gas4() sends an accordion_click event
139+
When I load the test site
140+
And I click on element with selector "button::-p-text(Accordion)"
141+
Then a "accordion_click" event is sent to DAP with parameters
142+
| selection | selection 1 |
143+
| section | <section> |
144+
145+
Scenario: gas4() sends an error event
146+
When I load the test site
147+
And I execute script "window.gas4('error', {type: '404', url: '/missing-page'})"
148+
Then a "error" event is sent to DAP with parameters
149+
| type | 404 |
150+
| url | /missing-page |
151+
152+
Scenario: gas4() sends a filter event
153+
When I load the test site
154+
And I execute script "window.gas4('filter', {filter_selection: 'date', section: 'results'})"
155+
Then a "filter" event is sent to DAP with parameters
156+
| filter_selection | date |
157+
| section | results |
158+
159+
Scenario: gas4() sends a sort event
160+
When I load the test site
161+
And I execute script "window.gas4('sort', {sort_selection: 'newest', section: 'results'})"
162+
Then a "sort" event is sent to DAP with parameters
163+
| sort_selection | newest |
164+
| section | results |

features/gas_functions.feature

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
Feature: gas() custom event API
2+
3+
Background:
4+
Given I load an empty browser
5+
And DAP is configured for agency "GSA"
6+
7+
Scenario: gas() sends a virtual pageview
8+
When I load the test site
9+
And I execute script "window.gas('send', 'pageview', '/virtual/page')"
10+
Then a "page_view" event is sent to DAP with parameters
11+
| page_location | http://localhost/virtual/page |
12+
| page_title | DAP test site |
13+
14+
Scenario: gas() sends a virtual pageview with a custom title
15+
When I load the test site
16+
And I execute script "window.gas('send', 'pageview', '/virtual/page', 'My Custom Title')"
17+
Then a "page_view" event is sent to DAP with parameters
18+
| page_location | http://localhost/virtual/page |
19+
| page_title | My Custom Title |
20+
21+
Scenario: gas() sends a custom event
22+
When I load the test site
23+
And I execute script "window.gas('send', 'event', 'test_category', 'test_action', 'test_label', 1)"
24+
Then a "dap_event" event is sent to DAP with parameters
25+
| event_category | test_category |
26+
| event_action | test_action |
27+
| event_label | test_label |
28+
| event_value | 1 |
29+
| non_interaction | false |
30+
31+
Scenario: gas() sends a custom event with only category and action
32+
When I load the test site
33+
And I execute script "window.gas('send', 'event', 'only_category', 'only_action')"
34+
Then a "dap_event" event is sent to DAP with parameters
35+
| event_category | only_category |
36+
| event_action | only_action |
37+
| event_label | |
38+
| event_value | 0 |
39+
| non_interaction | false |

features/link_tracking.feature

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
Feature: Link click tracking with autotracker
2+
3+
Background:
4+
Given I load an empty browser
5+
And DAP is configured for agency "GSA"
6+
And DAP is configured with autotracking enabled
7+
8+
Scenario: Clicking the USA banner button fires official_usa_site_banner_click
9+
When I load the test site
10+
And I click on element with selector "#banner-button"
11+
Then a "official_usa_site_banner_click" event is sent to DAP with parameters
12+
| link_text | Heres how you know |
13+
| section | header |
14+
15+
Scenario: Clicking an external email link fires email_click
16+
When I load the test site
17+
And I click on element with selector "a[href='mailto:test@domain.com']"
18+
Then a "email_click" event is sent to DAP with parameters
19+
| link_text | mailto:[REDACTED_EMAIL] |
20+
21+
Scenario: Clicking a telephone link fires telephone_click
22+
When I load the test site
23+
And I click on element with selector "a[href='tel:+1437-925-1855']"
24+
Then a "telephone_click" event is sent to DAP with parameters
25+
| link_text | Telephone [REDACTED_TEL] |
26+
27+
Scenario: Clicking a file download link reports the download
28+
When I load the test site
29+
And I click on a file to download it
30+
Then the file download is reported to DAP with interaction type "Mouse Click"
31+
32+
Scenario: Pressing Enter on a file download link reports the download
33+
When I load the test site
34+
And I highlight and press Enter on a file to download it
35+
Then the file download is reported to DAP with interaction type "Keyboard"
36+
37+
Scenario: File downloads are not tracked when autotracking is disabled
38+
Given DAP is configured with autotracking disabled
39+
When I load the test site
40+
And I click on a file to download it
41+
Then the file download is not reported to DAP

features/parallel_tracker.feature

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
Feature: A site can use the DAP code with their own parallel GA4 property
2+
3+
Background:
4+
Given I load an empty browser
5+
6+
Scenario: Load a page with parallel GA4 property configured but no custom dimensions
7+
Given DAP is configured for agency "HHS"
8+
And DAP is configured for subagency "CDC"
9+
And DAP is configured with parallel GA4 property "G-111111"
10+
When I load the test site
11+
Then DAP will set custom dimensions for the DAP property
12+
| agency | HHS |
13+
| subagency | CDC |
14+
| using_parallel_tracker | pga4 |
15+
And DAP will configure parallel property "G-111111" without custom dimensions
16+
17+
Scenario: Load a page with parallel GA4 property configured and custom dimensions enabled
18+
Given DAP is configured for agency "HHS"
19+
And DAP is configured for subagency "CDC"
20+
And DAP is configured with parallel GA4 property "G-111111"
21+
And DAP is configured to set custom dimensions on the parallel tracker
22+
When I load the test site
23+
Then DAP will set custom dimensions for the DAP property
24+
| agency | HHS |
25+
| subagency | CDC |
26+
| using_parallel_tracker | pga4 |
27+
And DAP will set custom dimensions for the parallel property "G-111111"
28+
| agency | HHS |
29+
| subagency | CDC |
30+
| script_source | http://localhost:8080/universal-federated-analytics-min.js |
31+
| version | 20250702 v8.7 - ga4 |
32+
| protocol | http: |
33+
| hostname_dimension | localhost |
34+
| using_parallel_tracker | pga4 |
35+
36+
Scenario: Load a page with parallel GA4 property configured with site topic and site platform
37+
Given DAP is configured for agency "HHS"
38+
And DAP is configured with site topic "Health"
39+
And DAP is configured with site platform "Cloud.gov"
40+
And DAP is configured with parallel GA4 property "G-111111"
41+
And DAP is configured to set custom dimensions on the parallel tracker
42+
When I load the test site
43+
Then DAP will set custom dimensions for the parallel property "G-111111"
44+
| site_topic | health |
45+
| site_platform | cloud.gov |
46+
47+
Scenario: Load a page with invalid measurement ID for parallel GA4 property
48+
Given DAP is configured for agency "HHS"
49+
And DAP is configured with parallel GA4 property "GTM-ABCDE"
50+
When I load the test site
51+
Then DAP will set custom dimensions for the DAP property
52+
| agency | HHS |
53+
| using_parallel_tracker | no |
54+
And DAP will not configure parallel property "GTM-ABCDE"
55+
56+

0 commit comments

Comments
 (0)