A small utility library to programmatically insert analytics elements into the DOM.
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
dist
src
test
.gitignore
.travis.yml
LICENSE
README.md
package-lock.json
package.json
tsconfig.json

README.md

insert-analytics-elements

Build Status npm version

A small utility library to programmatically insert analytics elements into the DOM.

Installation

# npm
npm i insert-analytics-elements
# yarn
yarn add insert-analytics-elements

Included Providers

Usage

Google Analytics

// JavaScript
const googleAnalytics = require('insert-analytics-elements/googleAnalytics');
googleAnalytics.insertAnalyticsElements('UA-XXXXX-X')

// TypeScript
import { insertAnalyticsElements } from 'insert-analytics-elements/googleAnalytics';
insertAnalyticsElements('UA-XXXXX-X');

Google Analytics with Async

// JavaScript
const googleAnalyticsAsync = require('insert-analytics-elements/googleAnalytics/async');
googleAnalyticsAsync.insertAnalyticsElements('UA-XXXXX-X')

// TypeScript
import { insertAnalyticsElements } from 'insert-analytics-elements/googleAnalytics/async';
insertAnalyticsElements('UA-XXXXX-X');

Google Analytics with gtag

// JavaScript
const googleAnalyticsGtag = require('insert-analytics-elements/googleAnalytics/gtag');
googleAnalyticsGtag.insertAnalyticsElements('UA-XXXXX-X')

// TypeScript
import { insertAnalyticsElements } from 'insert-analytics-elements/googleAnalytics/gtag';
insertAnalyticsElements('UA-XXXXX-X');

Google Tag Manager

// JavaScript
const googleTagManager = require('insert-analytics-elements/googleTagManager');
googleTagManager.insertAnalyticsElements('GTM-XXXX')

// TypeScript
import { insertAnalyticsElements } from 'insert-analytics-elements/googleTagManager';
insertAnalyticsElements('GTM-XXXX');