# CONCORD WEB ANALYTICS DATA TAGGING #

The purpose of this repository is to maintain source code for attaching listeners that call Google Tag Manager's dataLayer to be used for data tagging and analytics on Concord's site.

### Process For Development ###

To create new scripts:
- Add a new script file (with a .ts file type) to the /scripts directory under either the /pages directory (if the script should be triggered based on URL change) or the /events directory (if the script should be triggered based on any other event (i.e. click, form events, etc))
- IF A PAGE SCRIPT:
    - Add the path string to the dataLayerPageDetails method in data-layer-methods.ts and follow the pattern to include your imported method from your newly created script file. 
- IF A EVENT SCRIPT:
    - Add the exported method from your event related script into the addCustomEventHandlers method in data-layer-methods.ts

To test locally:
- Search for the comments that say 'UNCOMMENT FOR TESTING' in main.ts
- Make sure these two pieces of code are uncommented 
    - The page scripts you can test using the console.log with the 'DataLayer' object
    - Other events can be tracked via inputting the DataLayer object into the  Local Storage 


To run build process locally:
- In command line input 'npm run build'
- This will distill all scripts imported into src/main.ts into a single file inside the /dist directory called analytics-bundle.js
- Search the output to ensure your script is in the file

To deploy:
- Commit and push code up to your branch
** NEED TO FIX THIS PIPELINE FLOW (as of 9/26/24) **
- Merge code into main branch
    - This will kick off a pipeline that will build, publish, and make your code accessible via this script: `<script src="https://cdn.jsdelivr.net/npm/@concord-consulting/concord-web-analytics/dist/analytics-bundle.js"></script>`
    - note: This may take a few minutes after publishing to NPM to be available via jsdelivr

** ALTERNATIVE DEPLOYMENT PROCESS **
- Run the script 'npm run release' in order to update package version and trigger a publish to NPM.
- It may error if you're not authenticated with NPM, if this is case run npm login and follow the output in the terminal to login.
    - You may need to be added as a user in Concord's NPM account - contact Jerry Hill for access
    - You can also contact Reese Kling for publishing help.