• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

cofacts / rumors-site / 4050999257

pending completion
4050999257

Pull #500

github

GitHub
Merge 42bb5f89c into bf0362a6f
Pull Request #500: Initialize Typescript

386 of 603 branches covered (64.01%)

Branch coverage included in aggregate %.

36 of 36 new or added lines in 5 files covered. (100.0%)

924 of 1112 relevant lines covered (83.09%)

12.92 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/lib/gtm.ts
1
import { useEffect } from 'react';
2

3
/**
4
 * Google tag manager related utility functions
5
 */
6

7
/**
8
 * @param args - data to feed to dataLayer.push
9
 */
10
export function pushToDataLayer(...args: unknown[]) {
11
  if (typeof window === 'undefined') return; // Skip in SSR
×
12

13
  if (!('dataLayer' in window)) window['dataLayer'] = [];
×
14
  window['dataLayer'].push(...args);
×
15
}
16

17
/**
18
 * @param trigger - trigger useEffect() after trigger turns truthy
19
 * @param args - data to send to pushDataLayer on trigger change
20
 */
21
export function usePushToDataLayer(trigger: unknown, args: object) {
22
  const dontTrigger = !trigger;
×
23
  useEffect(() => {
×
24
    if (dontTrigger) return;
×
25
    pushToDataLayer(args);
×
26
  }, [dontTrigger, args]);
27
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc