How to install the ProfitWell.js Snippet with Google Tag Manager

Updated 2 days ago by Matias Barriento

If your company uses Google Tag Manager you can add our wonderful snippet too.

The first thing you need to know is if you have the current user email available before loading your tags from GTM. That should be above this lines.

<!-- Google Tag Manager (noscript) -->
          <noscript>
              <iframe ...>
              </iframe>
          </noscript>
          <!-- End Google Tag Manager (noscript) -->

If you have the user email before the tag, you could use a JavaScript Variable. If not, you should use a Data Layer Variable.

Using JavaScript Variable

Check if you have any variable inside GTM that references the customer's email, if not create one with the type JavaScript Variable and called pw_user_email

Using Data Layer Variable

Check if you have any data layer variable inside GTM that references the customer's email, if not create one with the type Data Layer Variable and called pw_user_email

Also, for this kind of variable you need a custom trigger. Create one Custom Event called pw_trigger.

PW Tag

Add a New Tag, select Custom HTML and paste this while replacing your token

<script>
          (function(i,s,o,g,r,a,m){i['ProfitWellObject']=r;i[r]=i[r]||function(){
           (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
           m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m);
           })(window,document,'script','https://dna8twue3dlxq.cloudfront.net/js/profitwell.js','profitwell');
           profitwell('auth_token', 'PUBLIC_API_TOKEN_HERE'); // Your unique Profitwell public API token
           profitwell('user_email', '{{pw_user_email}}');
          </script>

When it asks you for a trigger, select All pages if you are using variables or pw_trigger if you are using a data layer

How to use it

For variables, just make sure you have a global variable with the email called pw_user_email (or the same name you use in the PW Tag)

<script>
              pw_user_email = 'user_email@domain.com'
          </script>

For data layer is more tricky.

Make sure you declared the dataLayer before calling Google Tag Manager

<script>
            dataLayer = [];
          </script>
          

Whenever you get the user's email, just call

dataLayer.push({'event': 'pw_trigger', 'pw_user_email': user_email})
          

If you have any questions at all, please reach out to product@profitwell.com


How Did We Do?