Go to Qubit

Opentag documentation

Web API – Examples

Below are some example uses of the Opentag Web API. These are all performed using the cURL command line utility.

The below examples assume you already have authentication details. For more information and examples, please see the Authentication page.

1. Retrieve client information

The client ID can be retrieved either by looking in the Opentag UI or using the ci cookie parameter returned when authenticating.

Request – Get client

curl -v https://opentag.qubitproducts.com/QDashboard/qtag/client/77354 \
--cookie 'si=9URGfSjAbLdfDIf1LaNfxjfkcwQ; sk=ijeVby2W6MiAa0xw9V2fkXbxJs8; ci=77354; cn="example_user@testing.com"; ui=83288; un="example_user@testing.com"'

Response

{
  "active": true,
  "name": "oliver.woodings@qubitdigital.com",
  "id": 77354
}

2. List client profiles

Request – Get client profiles

curl -v https://opentag.qubitproducts.com/QDashboard/qtag/client/77354/profile \
--cookie 'si=9URGfSjAbLdfDIf1LaNfxjfkcwQ; sk=ijeVby2W6MiAa0xw9V2fkXbxJs8; ci=77354; cn="example_user@testing.com"; ui=83288; un="example_user@testing.com"'

Response

[{
  "cookieDomain": "",
  "active": true,
  "zipped": true,
  "scriptName": "d3c3cq33003psk.cloudfront.net/opentag-77354-1279388.js",
  "invalidationToken": -1,
  "delayDocWrite": false,
  "showCommitFinishedPrompt": true,
  "maxCookieLength": 3000,
  "name": "Demo UAT",
  "id": 1279388,
  "dirty": true,
  "version": 30
}, {
  "cookieDomain": "",
  "active": true,
  "zipped": true,
  "scriptName": "d3c3cq33003psk.cloudfront.net/opentag-77354-1279364.js",
  "invalidationToken": -1,
  "delayDocWrite": false,
  "showCommitFinishedPrompt": false,
  "maxCookieLength": 3000,
  "name": "Demo",
  "id": 1279364,
  "dirty": true,
  "version": 30
}]

3. Add new profile (container)

Request – Add profile to client

curl -v -X POST https://opentag.qubitproducts.com/QDashboard/qtag/client/77354/profile \
-d "name=Testing%20Account&cookieDomain=.mywebsite.com&zipped=true&delayDocWrite=false" \
-H "Content-Type: application/x-www-form-urlencoded" \
--cookie 'si=9URGfSjAbLdfDIf1LaNfxjfkcwQ; sk=ijeVby2W6MiAa0xw9V2fkXbxJs8; ci=77354; cn="example_user@testing.com"; ui=83288; un="example_user@testing.com"'

Response

{
  "cookieDomain": ".mywebsite.com",
  "active": true,
  "zipped": true,
  "scriptName": "d3c3cq33003psk.cloudfront.net/opentag-77354-1398886.js",
  "invalidationToken": -1,
  "delayDocWrite": false,
  "showCommitFinishedPrompt": true,
  "maxCookieLength": 3000,
  "name": "Testing Account",
  "id": 1398886,
  "dirty": true,
  "version": 30
}

4. Add a variable to the profile

Let’s say we want to set up a re-usable variable for use in several scripts, for example, a Google Analytics profile ID. We can do this by adding a new custom variable to the profile.

Request – Add custom variable

curl -v -X POST https://opentag.qubitproducts.com/QDashboard/qtag/client/77354/profile/1398886/customvar \
-d "valueName=GA%20Account%20ID&value=UA-1029383283&typeId=1" \
-H "Content-Type: application/x-www-form-urlencoded" \
--cookie 'si=9URGfSjAbLdfDIf1LaNfxjfkcwQ; sk=ijeVby2W6MiAa0xw9V2fkXbxJs8; ci=77354; cn="example_user@testing.com"; ui=83288; un="example_user@testing.com"'

Response

{
  "typeId": 1,
  "name": "GA Account ID",
  "value": "UA-1029383283",
  "id": 2098449,
  "usageCount": 0
}

5. Add library script to profile

For this example we are going to be adding a GA tag to our newly created profile. This involves several stages:

  1. Retrieve library categories
  2. Retrieve library vendors
  3. Look up GA tag in library
  4. Create new filter group
  5. Add GA library tag to the filtergroup
  6. Add any parameters to the script as required

Request – Get category

First, we look up the library categories (full list omitted here)

curl -v https://opentag.qubitproducts.com/QDashboard/qtag/category \
--cookie 'si=9URGfSjAbLdfDIf1LaNfxjfkcwQ; sk=ijeVby2W6MiAa0xw9V2fkXbxJs8; ci=77354; cn="example_user@testing.com"; ui=83288; un="example_user@testing.com"'

Response

The GA tag is going to be inside Web Analytics

[{
  "name": "Web Utilities / JavaScript Tools",
  "id": 1
}, {
  "name": "Web Analytics",
  "id": 2
}, {
  "name": "Social",
  "id": 3
}, {
...
]

Request – Get vendor

Next we list the vendors to find Google Universal Analytics

curl -v https://opentag.qubitproducts.com/QDashboard/qtag/vendor \
--cookie 'si=9URGfSjAbLdfDIf1LaNfxjfkcwQ; sk=ijeVby2W6MiAa0xw9V2fkXbxJs8; ci=77354; cn="example_user@testing.com"; ui=83288; un="example_user@testing.com"'

Response

[
...
}, {
  "name": "Google Universal Analytics",
  "id": 10101,
  "description": "Universal Analytics introduces a set of features that change the way data is collected and organised in your Google Analytics account, so you can get a better understanding of how visitors interact with your organisation."
}, {
...
]

Request – Get scripts

Now, armed with the script category and vendor ID we can find the tag in the library.

curl -v https://opentag.qubitproducts.com/QDashboard/qtag/script?category=2 \
--cookie 'si=9URGfSjAbLdfDIf1LaNfxjfkcwQ; sk=ijeVby2W6MiAa0xw9V2fkXbxJs8; ci=77354; cn="example_user@testing.com"; ui=83288; un="example_user@testing.com"'

Response

For this example we will be using the Generic Page View script.

[
...
}, {
  "vendorId": 10101,
  "imageUrl": "https://s3-eu-west-1.amazonaws.com/opentag-images/GoogleAnalytics.png",
  "name": "Generic Page View",
  "id": 35660,
  "description": "This tag registers a pageview, and is intended for any page other than confirmation pages."
}, {
...
]

Request – Add filter group

In Opentag, all scripts have to exist under a filter group, even if it is empty. Therefore we need to create a new one for the GA tag. It is a good idea to give the filter group the same name as the script.

curl -v -X POST https://opentag.qubitproducts.com/QDashboard/qtag/client/77354/profile/1398886/filtergroup \
-d "name=GA%20Generic%20Pageview&priority=1" \
-H "Content-Type: application/x-www-form-urlencoded" \
--cookie 'si=9URGfSjAbLdfDIf1LaNfxjfkcwQ; sk=ijeVby2W6MiAa0xw9V2fkXbxJs8; ci=77354; cn="example_user@testing.com"; ui=83288; un="example_user@testing.com"'

Response

{
  "name": "GA Generic Pageview",
  "priority": 1,
  "id": 28716247
}

Request – Add script to filter group

Finally we can add the library script to the filter group. For the params field please see the specification for a description of its contents.

curl -v -X POST https://opentag.qubitproducts.com/QDashboard/qtag/client/77354/profile/1398886/filtergroup/28716247/script \
-d "name=GA%20Generic%20Pageview&active=true&scriptId=35660&dedupe=false&needsConsent=false&scriptTimeout=5000┬Âms=%7B%2234707%22:%7B%22id%22:34707,%22defaultValue%22:%22%22,%22customVarId%22:%222098449%22%7D,%2235229%22:%7B%22id%22:35229,%22defaultValue%22:%22%22,%22customVarId%22:%222092314%22%7D%7D" \
--cookie 'si=9URGfSjAbLdfDIf1LaNfxjfkcwQ; sk=ijeVby2W6MiAa0xw9V2fkXbxJs8; ci=77354; cn="example_user@testing.com"; ui=83288; un="example_user@testing.com"'

Response

{
  "pre": "",
  "url": "",
  "post": "",
  "html": "\n(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){\n(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),\nm=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)\n})(window,document,'script','//www.google-analytics.com/analytics.js','ga');\n\nga('create', '${web_property_id}', '${url}');\nga('require', 'displayfeatures');\nga('send', 'pageview');\n",
  "locationId": 1,
  "positionId": 1,
  "locationDetail": "",
  "scriptTemplateId": 35660,
  "substitutedUrl": "",
  "substitutedPre": "",
  "substitutedPost": "",  "substitutedHtml": "\n(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){\n(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),\nm=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)\n})(window,document,'script','//www.google-analytics.com/analytics.js','ga');\n\nga('create', '${web_property_id}', '${url}');\nga('require', 'displayfeatures');\nga('send', 'pageview');\n\n",
  "params": [{
    "paramName": null,
    "scriptParam": {
      "customVarId": 2098449,
      "customVarTypeId": -1,
      "valueName": null,
      "value": null,
      "universalVarId": -1,
      "hasDefault": true,
      "description": null,
      "token": null,
      "paramName": null,
      "id": 34707
    },
    "valueName": null,
    "id": 3296273,
    "defaultValue": "",
    "token": null
  }, {
    "paramName": null,
    "scriptParam": {
      "customVarId": 2092314,
      "customVarTypeId": -1,
      "valueName": null,
      "value": null,
      "universalVarId": -1,
      "hasDefault": true,
      "description": null,
      "token": null,
      "paramName": null,
      "id": 35229
    },
    "valueName": null,
    "id": 3296274,
    "defaultValue": "",
    "token": null
  }],
  "usesDocWrite": false,
  "scriptTimeout": 5000,
  "active": true,
  "async": true,
  "dedupe": false,
  "needsConsent": false,
  "parentDependencies": [],
  "masterId": -1,
  "childDependencies": [],
  "name": "GA Generic Pageview",
  "id": 27944394
}

6. Commit profile

Finally we can commit the new tag by making a request to the save profile route.

Request – Save profile

curl -v -X PUT https://opentag.qubitproducts.com/QDashboard/qtag/client/77354/profile/1398886/scriptwriter \
--cookie 'si=9URGfSjAbLdfDIf1LaNfxjfkcwQ; sk=ijeVby2W6MiAa0xw9V2fkXbxJs8; ci=77354; cn="example_user@testing.com"; ui=83288; un="example_user@testing.com"'

Response

111376

Was this helpful?