Load Evidence on Desktop Only using Google Tag Manager

There may be times when you wish to load the Evidence Pixel on desktop only. This guide will show you how to do that using Google Tag Manager.

Google Tag Manager by default doesn't allow you to use Device Type as a variable. We will be using a workaround by creating a custom JavaScript variable the runs a script depending on the resolution of the screen viewing the page.

NOTE: This article does not cover setting up Google Tag Manager or adding the Evidence pixel to your account. For instructions on how to add your pixel to your GTM account, read the article Install Evidence Pixel using Google Tag Manager.

Step 1: Create a New Variable

Log in to Google Tag Manager and click Variables from the menu on the right.

select variables from the menu on the left

Under User-Defined Variables, click the blue New button.

under user-defined variables click the blue new button on the right

Hover over the Variable Configuration box and click the pencil icon that appears in the top right.

hover and click pencil icon

Select Custom JavaScript from the menu.

select custom javascript from the menu on the right

Paste the following JavaScript code into the Custom JavaScript box.

function()
{
/// the minimum width for each device we're able to detect, from big to small
var deviceMinWidths = {
'desktop': 769,
'tablet': 321,
'mobile': 0       
}

/// find the device type
for(var device in deviceMinWidths)
{
if(window.screen.width >= deviceMinWidths[device])
{
return device;
}
}   
}
This function uses JavaScript to get the current width of your browser (in pixels) and translate that into an easy-to-read text string. If you want to apply this to your own website, make sure to put in the responsive break points that your site uses. For example, while we’re using 520 pixels or less to signify “mobile”, your website might break for mobile at 450px, 600px, or anything in between.
pasted code

Name the Variable Screen Resolution and click the blue save button in the top right.

name the variable screen resolution
click save

Step 2: Create a New Trigger

Click Triggers from the menu on the left.

select triggers from the menu on the left

Then Click the blue New button on the right.

click the blue new button on the right

After that click the Pencil icon when you hover over Trigger Configuration. Then select Page View.

click pencil icon
select page view

Click the Some Page Views radio button, then configure the condition as Screen Resolution >> contains >> desktop.

screen resolution contains desktop

Name your Trigger Desktop Only, and click Save on the right.

desktop only
save on the right

Step 3: Add the Trigger to your Evidence Tag

Now click Tags from the menu on the left.

click tags from the menu on  the left

Click the Name of the tag that you are using to fire the Evidence Script.

click the name of your tag with the evidence script

Under Triggering, click the pencil icon in the top right.

click the pencil icon under triggering

Click the Plus button. Then click the Desktop Only trigger we created earlier.

plus button
desktop only trigger

After that, click minus icon on the All Pages trigger. Then click Save.

click the minus button on all pages trigger
add desktop only trigger to tag
save on the right

Step 4: Submit and Publish

Click Submit in the top right of the screen.

submit in top right

Give your version a Name and Description. Then click Publish in the top right.

give your version a name and description
click publish in the top right

Relevant Articles

Create Your Free Evidence Account

Increasing your website's conversions isn't always black and white. With so many ways, it can be confusing where to start. Evidence makes this easy. Within a few minutes, you can have real-time social proof added to your site and boosting conversions from 10-15%. 

Social proof is the best way to build trust and increase buyer urgency. With a free trial to Evidence, you can add high-converting notifications to your website. Your free trial includes:

  • Unlimited Domains
  • Unlimited Notifications
  • Conversion Notifications
  • Hot Streak Notifications
  • Visitor Count Notifications
  • Offer Notifications
  • Announcement Notifications
  • Boomerang Tabs
  • Powerful Design Editor
  • Best-in Class Display Options

There is no long-term obligation. If you don't see results, simply cancel. Visit Evidence.io and create your trial account today.

If you ever need help sending data to Evidence, check out Parsey.com.

Tags: , ,

Was this helpful?