Giter VIP home page Giter VIP logo

wordpress-partytown's Introduction

Integrating Party Town with WordPress

To get quickly started follow this guide to learn how you should separate your files.

From that guide you should have the /lib/ directory, rename this to "~partytown" and place this into the root of your WordPress site.

Once the directory is in the root of your WordPress site you are ready to setup the header file. Firstly you must make sure that you call the partytown script at the very top of your header.php file.

<head>
    <script src="~partytown/partytown.js"></script>

    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <?php wp_head(); ?>
</head>

Party Town has to be the first script to run in order to run any other scripts inside a web worker.

Next you will need to set up your forwarding events. This is an important step as normally the script, that you are running from a web worker, will add code to the head but now is unable to since it's runing from a web worker. Forwarding will allow the scripts to run as intended. Take a look at the following example:

<head>
    <script src="~partytown/partytown.js"></script>

    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <?php wp_head(); ?>

    <!-- Add forwarding event for Google Tag Manager -->
    <script>
        partytown = {
            forward: ['dataLayer.push'],
        };
    </script>
</head>

Once you have added your forwarding events you are ready to be adding your scripts, take a look at the following example:

<head>
    <script src="~partytown/partytown.js"></script>

    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <?php wp_head(); ?>


    <script>
        partytown = {
            forward: ['dataLayer.push'],
        };
    </script>

    <script type="text/partytown">
        /*

            google tag manager

        */
    </script>
</head>

You will know your script is working correctly by seeing if the script you added with the type="text/partytown" attribute has -x added to the end of it.

All of the code and directory structure can be seen in this repository for reference.

wordpress-partytown's People

Watchers

Will Clarke 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.