Git Product home page Git Product logo

pw-ga-lite's Introduction

MarkupGALite, ProcessWire Markup module wrapper for ga-lite.

You can read the detailed blog post about how I built it.

MarkupGALite is a wrapper around ga-lite, a lightweight alternative to official Google Analytics client. It only includes pageview event. It's cacheable, and its small print allows it to be injected / linked into page without much load.

The module offers several features:

  • A configuration page for:
    • Setting up tracking ID and IP anonymization
    • Specifying pages to inject the script
    • Choosing where to place the script (before </head> or </body>)
    • Choosing whether to link or inject complete script into HTML
  • Hookable. By hooking MarkupGALite::renderTrackingCode, it's possible to change the rendered tracking code.
  • Translatable. All strings are marked as translatable.

Usage

  • Install the module from Modules > Install > Add New using one of the provided options. Or download and extract it to /site/modules/, then install.
  • On the configuration page, fill in the tracking code (otherwise script will not be included in page), and any other options.

You can use it manually without installing.

$ga = wire()->modules->MarkupGALite;

echo $ga->renderTrackingCode([
    'trackingId' => 'UA-123XX',
    'anonymizeIp' => true
]);

Hooks

You can hook into renderTrackingCode method.

  • Change the arguments

    wire()->addHookBefore('MarkupGALite::renderTrackingCode', function(HookEvent $e){
        $options = $e->arguments(0);
        $inject = $e->arguments(1);
    
        $options['trackingId'] = 'UA-ANOTHER';
        $inject = false;
        
        $e->setArgument(0, $options);
        $e->setArgument(1, $inject);
    });
  • Disable it altogether:

    wire()->addHookBefore('MarkupGALite::renderTrackingCode', function(HookEvent $e){
        // $someCondition = ...
        
        if ($someCondition) $e->cancelHooks = true;
    });

pw-ga-lite's People

Contributors

abdusco avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.