npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

primo-explore-google-analytics

v1.2.5

Published

Google Analytics for Primo NUI packages

Downloads

3

Readme

primo-explore-google-analytics

CircleCI npm version Coverage Status

Google Analytics for Primo NUI packages

Description

Because the root index.html is not directly accessible from custom views, this dependency can inject custom script tags into the the DOM document <head>.

Installation

  1. Assuming you've installed and are using primo-explore-devenv.

  2. Navigate to your template/central package root directory. For example:

    cd primo-explore/custom/MY_VIEW_ID
  3. If you do not already have a package.json file in this directory, create one:

    npm init -y
  4. Install this package:

    npm install primo-explore-google-analytics --save-dev

Usage

Once installed, first add googleAnalytics as a dependency:

require('primo-explore-google-analytics');
// or, in a ESModules compatible environment:
// import 'primo-explore-google-analytics';

let app = angular.module('viewCustom', [
  'googleAnalytics'
])

Then, run the injection through a run block in your AnglularJS Application. This injection pattern follows "run block style" conventions, allowing for a finer control over the run order of your dependencies and better testing. See https://github.com/johnpapa/angular-styleguide/blob/master/a1/README.md#style-y171

  app.run(runBlock);

  runBlock.$inject = ['gaInjectionService'];
  function runBlock(gaInjectionService) {
    // other potential run operations...
    gaInjectionService.injectGACode();
  }

This will add the necessary script tags to the bottom of the head of your web document, loading the necessary Google Analytics functionality.

Config

You'll need to configure the module by passing it an object as an angular constant named googleAnalyticsConfig.

Optionally, you can also use an array of configurations if you need to add multiple tag managers to your page.

Required

| name | type | usage | |------|-------------|--------| | trackingId | string | Adds your GATM tracking id to default scripts ||

Configuration defaults

<head>
  <!-- ... -->
  <script async src="https://www.googletagmanager.com/gtag/js?id={trackingId}"></script>
  <script>
    window.dataLayer = window.dataLayer || [];
    function gtag(){dataLayer.push(arguments);}
    gtag('js', new Date());

    gtag('config', '{trackingId}');
  </script>
</head>

Optional

| name | type | usage | |------|-------------|--------| | externalScriptURL | string | If you are using an alternative URL, specify the source of the external script that is loaded. Use null if you don't want an external script to be loaded (especially for legacy Google Analytics using an inlineScript) | | inlineScript | string | Specify the inline script tag to be inserted below the external script tag. | | target | string | (default: 'head') What element on the document you would like to append the injected script to. E.g. body. Uses document.querySelector to find the first instance of the element. ||

Customization Example

app.constant('googleAnalyticsConfig', {
  trackingId: 'AB-123456789',
  // use null to specify an external script shouldn't be loaded
  externalScriptURL: null,
  // copy from script snippet from Google if you're running legacy Google Analytics
  inlineScript: `
    var _gaq = _gaq || [];
    _gaq.push(['_setAccount', 'AB-123456789']);
    _gaq.push(['_trackPageview']);

    (function() {
      var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
      ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
      var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
    })();
  `,
  target: 'body',
})

output:

<head>
  <!-- ... -->
  <!-- or, if included: <script async src="{externalScriptURL}"></script> -->
  <script>
  var _gaq = _gaq || [];
    _gaq.push(['_setAccount', 'AB-123456789']);
    _gaq.push(['_trackPageview']);

    (function() {
      var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
      ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
      var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
    })();
  </script>
</head>