Skip to content

Useful code snippets for web analytics & tracking implementation

Notifications You must be signed in to change notification settings

justusbluemer/tracking-snippets

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 

Repository files navigation

Useful tracking snippets

Useful code snippets for web analytics & tracking implementation

Google Tag Manager

Log pushed dataLayer events to console

(function(){
    const originalPush = window.dataLayer.push
    window.dataLayer.push = (msg) => {
        console.log(msg);
        originalPush(msg);
    }
})();

Bulk-select (e. g. to delete) variables

Go to the variables overview in Google Tag Manager and execute the following code in your browser's JS console after adding the list of variable names to the rowCaptions array.

const rowCaptions = [
    // Add list of variable names here
];

function clickCheckboxes() {
    let clickedCount = 0;

    rowCaptions.forEach(caption => {
        // Find the row containing the caption
        const row = Array.from(document.querySelectorAll('tr[gtm-table-row]')).find(row => 
            row.textContent.includes(caption)
        );

        if (row) {
            // Find the checkbox within the row
            const checkbox = row.querySelector('i[role="checkbox"]');
            if (checkbox) {
                checkbox.click();
                clickedCount++;
                console.log(`Clicked checkbox for: ${caption}`);
            } else {
                console.log(`Checkbox not found for: ${caption}`);
            }
        } else {
            console.log(`Row not found for: ${caption}`);
        }
    });

    console.log(`Finished. Clicked ${clickedCount} checkboxes.`);
}

// Run the function
clickCheckboxes();

Google Analytics

List all GA trackers

ga
.getAll()
.forEach(tracker =>
	console.log(
		`name: ${tracker.get("name")} trackingId: ${tracker.get(
			"trackingId"
		)} cookieDomain: ${tracker.get(
			"cookieDomain"
		)} allowLinker: ${tracker.get("allowLinker")}`
	)
);

About

Useful code snippets for web analytics & tracking implementation

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published