Git Product home page Git Product logo

cordova-plugin-tag-manager's Introduction

Tag Manager


Tag Manager plugin for Android and iOS. It allows you to post usage information to your Google Tag Manager account.

This plugin defines a global TagManager Constructor.

Although in the global scope, it is not available until after the deviceready event.

document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
    console.log(TagManager);
}

When being used in combination with AngularJS, it is recommended to use Angulartics with the Cordova GTM plugin (angulartics-gtm-cordova).

Installation

cordova plugin add com.jareddickson.cordova.tag-manager

Supported Platforms

  • Android
  • iOS

TagManager

var tagManager = cordova.require('com.jareddickson.cordova.tag-manager.TagManager');

Methods

  • tagManager.init: Initialize Tag Manager with an account ID and the number of seconds between dispatching analytics.

  • tagManager.trackEvent: Log an event.

  • tagManager.trackPage: Log a page view.

  • tagManager.dispatch: Force an immediate dispatch to Tag Manager.

  • tagManager.exit: Exit the TagManager instance and stop setInterval.

tagManager.init

Initialize Tag Manager with an account ID and the number of seconds between dispatching analytics.

tagManager.init(success, error, id, [period]);

Parameters

  • success: (Optional) The callback to execute if successful.

  • error: (Optional) The callback to execute if an error occurs.

  • id: The GTM account ID of the form 'GTM-000000'.

  • period: The interval for sending tracking events if any exist in the queue.

Quick Example

// Tag Manager
var tagManager = cordova.require('com.jareddickson.cordova.tag-manager.TagManager');
var trackingId = 'GTM-000000';
var intervalPeriod = 30; // seconds

// Initialize Tag Manager
tagManager.init(null, null, trackingId, intervalPeriod);

tagManager.trackEvent

Log an event.

tagManager.trackEvent(success, error, map);

Parameters

  • success: (Optional) The callback to execute if successful.

  • error: (Optional) The callback to execute if an error occurs.

  • map: The event map that will be pushed into the DataLayer.

Quick Example

// Track a click-to-call event
tagManager.trackEvent(success, error, {});

tagManager.trackPage

Log a page view.

tagManager.trackPage(success, error, map);

Parameters

  • success: (Optional) The callback to execute if successful.

  • error: (Optional) The callback to execute if an error occurs.

  • map: The event map that will be pushed into the DataLayer.

Quick Example

// Track a pageview on a Contact Us page
tagManager.trackPage(success, error, {});

tagManager.dispatch

Force an immediate dispatch to Tag Manager.

tagManager.dispatch([success], [error]);

Parameters

  • success: (Optional) The callback to execute if successful.

  • error: (Optional) The callback to execute if an error occurs.

Quick Example

// Dispatch
tagManager.dispatch();

tagManager.exit

Exit the TagManager instance and stop setInterval.

tagManager.exit([success], [error]);

Parameters

  • success: (Optional) The callback to execute if successful.

  • error: (Optional) The callback to execute if an error occurs.

Quick Example

// Exit
tagManager.exit();

License

The MIT License

Copyright (c) 2014 Jared Dickson

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

cordova-plugin-tag-manager's People

Contributors

kraihn avatar

Watchers

James Cloos avatar Johnathan Hok 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.