Creating a custom metric with GTM

I am new to GTM V2.

I would like to track PDF downloads using a custom metric. I can create my own size for the same, but cannot create my own metric.

I need a report similar to below:

PDFname        no. of download
xyx                   1
abc                   5

      

  • xyz pdf Downloaded 1 times abc 5
  • PDF name and no. loads - column header, other values ​​-

I want to create a metric using GTM v2. I don't want to write JavaScript for the same. I made the above report using event tracking but want to do the same with custom metric

Please explain in detail how to create a custom metric using GTM.

Please help me as soon as possible.

0


source to share


1 answer


In the new version of Google Tag Manager, Macros have been renamed to Variables, so I will refer to them as such.

I have implemented a tag that tracks when a PDF is loaded on my site. I did this by creating a custom variable. Follow the steps to create the variables needed to track the PDF download.

1) Create a new variable named "element", make this variable the variable "auto-event". Select "Item" from the "Variable Type" drop-down menu. Click "Save Variable"

2) Create a new variable called 'Click Link File Name'. Make this variable a Javascript Variable. Paste the following code into the configure variable field.

function() {
    var filepath = {{element}}.pathname.split("/");
    var filename = filepath.pop();
    return filename.indexOf(".")>-1?filename:'n/a';
}

      

Click "Save Variable"



3) Create a trigger - Name the trigger "PDF Download"

  • Event: click
  • Configuration: Just Links
  • Include When: [Page URL] [matches RegEx]. *
  • FireOn: [Click URL] [Corresponds to RegEx]. (pdf) $

4) Create a tag

  • Product: Google Analytics
  • Tag type: universal analytics
  • Customize tag:
    • Tracking ID: "Your tracking code is here"
    • Track type: "Event"
    • Category: "Click"
    • Action: "Download"
    • Shortcut: "{{Click link filename}}"
  • Fire On: "Download PDF"

What will happen with this set of instructions for you to set up variables that can record the name of your PDF file, as well as the ability to track it as an event. The trigger we set up in step 3 tells GTM to activate the tag on every page (. *) AND FIRE tag when the user CLIKS a link that ends with the string ".pdf". The set tag tells GTM to send an event to your GA account with the category, action, and tag listed above. The event label will contain the name of the uploaded PDF file.

If you want more customization than this, let me know and I will provide you with a solution to keep track of things like - Which page the PDF was loaded from

0


source







All Articles