Code Monkey home page Code Monkey logo

aio-lib-analytics's Introduction

Version Downloads/week Node.js CI License Codecov Coverage

Adobe I/O Adobe Analytics SDK

Node Javascript Core SDK wrapping Adobe Analytics 2.0 APIs.

Installing

$ npm install

Usage

  1. Initialize the SDK
var sdk = require('@adobe/aio-lib-analytics');

async function sdkTest() {
  //initialize sdk
  const analyticsClient = await sdk.init('<companyID>', 'x-api-key', '<valid auth token>')
}

Init method returns an Instance of Class AnalyticsCoreAPI

  1. Call methods using initialized sdk
var sdk = require('@adobe/aio-lib-analytics');

async function sdkTest() {
    //initialize sdk
    const analyticsClient = await sdk.init('<companyID>', '<x-api-key>', '<valid auth token>')

    //get report suites
    const collections = await analyticsClient.getCollections({limit:5, page:0})

    //get metrics
    const metrics = await analyticsClient.getMetrics(rsid)

    //generate report
    const report = await analyticsClient.getReport(queryJSON)
}

All Methods available under sdk are documented here

Classes

AnalyticsCoreAPI

This class provides methods to call Adobe Analytics APIs. Before calling any method initialize the instance by calling init method on it with valid company id, apiKey and auth token

Functions

init(companyId, apiKey, token)Promise.<AnalyticsCoreAPI>

Returns a Promise that resolves with a new AnalyticsCoreAPI object.

AnalyticsCoreAPI

This class provides methods to call Adobe Analytics APIs. Before calling any method initialize the instance by calling init method on it with valid company id, apiKey and auth token

Kind: global class

analyticsCoreAPI.init(companyId, apiKey, token) ⇒ AnalyticsCoreAPI

Initialize sdk.

Kind: instance method of AnalyticsCoreAPI

Param Type Description
companyId string company ID to be used with Adobe Analytics.
apiKey string Your api key
token string Valid auth token

analyticsCoreAPI.getCalculatedMetrics(options)

Retrieve many calculated metrics. A calculated metric response will always include these default items: id, name, description, rsid, owner, polarity, precision, type Other attributes can be optionally requested through the 'expansion' field:\n\n modified: Date that the metric was last modified (ISO 8601) definition: Calculated metric definition as JSON object compatibility: Products that the metric is compatible with reportSuiteName*: Also return the friendly Report Suite name for the RSID tags*: Gives all existing tags associated with the calculated metric

For more information about calculated metrics go here

Kind: instance method of AnalyticsCoreAPI

Param Type Description
options Object to control calculated metrics search.
options.calculatedMetricFilter Filter list to only include calculated metrics in the specified list\n(comma-delimited list of IDs).
options.expansion Comma-delimited list of additional metadata fields\nto include on response.
options.limit Number of results per page. Default 10.
options.locale Locale.
options.name Filter list to only include calculated metrics that contains the Name.
options.ownerId Filter list to only include calculated metrics owned by the\nspecified loginId.
options.page Page number (base 0 - first page is "0"). Default 0.
options.rsids Filter list to only include calculated metrics tied to specified\nRSID list (comma-delimited).
options.tagNames Filter list to only include calculated metrics that contains one of\nthe tags.

analyticsCoreAPI.getCalculatedMetricById(id, options)

Retrieve a single calculated metric by id. A calculated metric response will always include these default items: id, name, description, rsid, owner, polarity, precision, type Other attributes can be optionally requested through the 'expansion' field:\n\n modified: Date that the metric was last modified (ISO 8601) definition: Calculated metric definition as JSON object compatibility: Products that the metric is compatible with reportSuiteName*: Also return the friendly Report Suite name for the RSID tags*: Gives all existing tags associated with the calculated metric

For more information about calculated metrics go here

Kind: instance method of AnalyticsCoreAPI

Param Type Description
id string The calculated metric ID to retrieve.
options Object to control calculated metric result
options.expansion Comma-delimited list of additional metadata fields\nto include on response.
options.locale Locale.

analyticsCoreAPI.getCollections(options)

Retrieves report suites that match the given filters. Returns all report suite types in a single collection.

Kind: instance method of AnalyticsCoreAPI

Param Type Description
options Object to control report suites search.
options.expansion Comma-delimited list of additional metadata fields to include on\nresponse.
options.limit Number of results per page. Default 10.
options.page Page number (base 0 - first page is "0"). Default 0.
options.rsids Filter list to only include suites in this RSID list\n(comma-delimited).
options.rsidContains Filter list to only include suites whose rsid contains rsidContains.

analyticsCoreAPI.getCollectionById(rsid, options)

Retrieves report suite by id. Returns all report suite types in a single collection.

Kind: instance method of AnalyticsCoreAPI

Param Type Description
rsid string The rsid of the suite to return.
options Object to control eport suites search.
options.expansion Comma-delimited list of additional metadata fields to include on\nresponse.

analyticsCoreAPI.getDateRanges(options)

Returns a list of dateranges for the user. This function allows users to store commonly used date ranges so that they\ncan be reused throughout the product.

Kind: instance method of AnalyticsCoreAPI

Param Type Description
options Object to control date range search.
options.expansion Comma-delimited list of additional metadata fields to include on\nresponse.
options.filterByIds Filter list to only include date ranges in the specified list\n(comma-delimited list of IDs).
options.limit Number of results per page. Default 10.
options.locale Locale.
options.page Page number (base 0 - first page is "0"). Default 0.

analyticsCoreAPI.getDateRangeById(dateRangeId, options)

Retrieves configuration for a DateRange..

Kind: instance method of AnalyticsCoreAPI

Param Type Description
dateRangeId string The DateRange id for which to retrieve information.
options Object to control date range result.
options.expansion Comma-delimited list of additional metadata fields to include on\nresponse.
options.locale Locale.

analyticsCoreAPI.getDimensions(rsid, options)

Returns a list of dimensions for a given report suite.

Kind: instance method of AnalyticsCoreAPI

Param Type Description
rsid string A Report Suite ID.
options Object to control dimensions search.
options.classifiable Only include classifiable dimensions.
options.expansion Comma-delimited list of additional metadata fields\nto include on response.
options.locale Locale.
options.reportable Only include dimensions that are valid within a report.
options.segmentable Only include dimensions that are valid within a segment.

analyticsCoreAPI.getDimensionById(dimensionId, rsid, options)

Returns a dimension for the given report suite and dimension Id.

Kind: instance method of AnalyticsCoreAPI

Param Type Description
dimensionId string The dimension ID. For example a valid id is a value like 'evar1'.
rsid string A Report Suite ID.
options Object to control dimension result.
options.expansion Comma-delimited list of additional metadata fields\nto include on response.
options.locale Locale.

analyticsCoreAPI.getMetrics(rsid, options)

Returns a list of metrics for the given report suite. This returns the metrics list primarily for the Analytics product. The platform identity API Returns a list of all possible metrics for the supported systems.

Kind: instance method of AnalyticsCoreAPI

Param Type Description
rsid string A Report Suite ID.
options Object to control dimension result.
options.expansion Comma-delimited list of additional metadata fields\nto include on response.
options.locale Locale that system named metrics should be returned in.
options.segmentable Filter the metrics by if they are valid in a segment.

analyticsCoreAPI.getMetricById(id, rsid, options)

Returns a metric for the given report suite. This returns the metrics list primarily for the Analytics product. The platform identity API Returns a list of all possible metrics for the supported systems.

Kind: instance method of AnalyticsCoreAPI

Param Type Description
id string The id of the metric for which to retrieve info. Note ids are values\nlike pageviews, not metrics/pageviews.
rsid string A Report Suite ID.
options Object to control dimension result.
options.expansion Comma-delimited list of additional metadata fields\nto include on response.
options.locale Locale that system named metrics should be returned in.

analyticsCoreAPI.getReport(body)

Runs a report for the request. See the Reporting User\nGuide for details.

Kind: instance method of AnalyticsCoreAPI

Param Type Description
body Object report query.

analyticsCoreAPI.getSegments(options)

Retrieve All Segments.

Kind: instance method of AnalyticsCoreAPI

Param Type Description
options Object to control segments search.
options.expansion Comma-delimited list of additional metadata fields\nto include on response.
options.includeType Include additional segments not owned by user. The "all" option\ntakes precedence over "shared".
options.limit Number of results per page. Default 10.
options.locale Locale that system named metrics should be returned in.
options.name Filter list to only include segments that contains the Name.
options.page Page number (base 0 - first page is "0"). Default 0.
options.rsids Filter list to only include segments tied to specified RSID list\n(comma-delimited).
options.segmentFilter Filter list to only include segments in the specified list\n(comma-delimited list of IDs).
options.tagNames Filter list to only include segments that contains one of the tags.

analyticsCoreAPI.validateSegment(rsid, body)

Validate a Segment. Returns a segment validation for the segment contained in the post body of the report.

Kind: instance method of AnalyticsCoreAPI

Param Type Description
rsid string A Report Suite ID.
body Object JSON Segment Definition.

analyticsCoreAPI.getUsers(options)

Returns a list of users for the current user's login company. Retrieves a list of all users for the company designated by the auth\ntoken.

Kind: instance method of AnalyticsCoreAPI

Param Type Description
options Object to control user search.
options.limit Number of results per page. Default 10.
options.page Page number (base 0 - first page is "0"). Default 0.

analyticsCoreAPI.getCurrentUser()

Get the current user.

Kind: instance method of AnalyticsCoreAPI

analyticsCoreAPI.getUsageLogs(startDate, endDate, options)

Retrieves usage and access logs for the search criteria provided. This API returns the usage and access logs for a given date range within a 3 month period. This API authenticates with an IMS user token.

Kind: instance method of AnalyticsCoreAPI

Param Type Description
startDate string Start date in ISO-8601 format for the maximum of a 3 month period.
endDate string End date in ISO-8601 format for the maximum of a 3 month period.
options Object options to filter logs.
options.login string The login value of the user you want to filter logs by.
options.ip string The IP address you want to filter logs by.
options.rsid string The report suite ID you want to filter logs by.
options.eventType string The numeric id for the event type you want to filter logs by.
options.event string The event description you want to filter logs by. No wildcards permitted.
options.limit number Number of results per page. Default 10.
options.page number Page number (base 0 - first page is "0"). Default 0.

init(companyId, apiKey, token) ⇒ Promise.<AnalyticsCoreAPI>

Returns a Promise that resolves with a new AnalyticsCoreAPI object.

Kind: global function

Param Type Description
companyId string company ID to be used with Adobe Analytics.
apiKey string Your api key
token string Valid auth token

Debug Logs

LOG_LEVEL=debug <your_call_here>

Contributing

Contributions are welcome! Read the Contributing Guide for more information.

Licensing

This project is licensed under the Apache V2 License. See LICENSE for more information.

aio-lib-analytics's People

Contributors

amulyakashyap09 avatar dependabot[bot] avatar greenkeeper[bot] avatar himavanth avatar meryllblanchet avatar michaelgoberling avatar michaelmarth avatar moritzraho avatar purplecabbage avatar sandeep-paliwal avatar sbellone avatar shazron avatar snyk-bot avatar ursboller avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aio-lib-analytics's Issues

An in-range update of fetch-mock is breaking the build 🚨


☝️ Important announcement: Greenkeeper will be saying goodbye 👋 and passing the torch to Snyk on June 3rd, 2020! Find out how to migrate to Snyk and more at greenkeeper.io


The devDependency fetch-mock was updated from 9.3.1 to 9.4.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

fetch-mock is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details

Commits

The new version differs by 10 commits.

  • 3cdc7ba fixed broken tests
  • b1f33ec fix linting
  • 87a2758 Merge pull request #532 from chet-manley/feat-return-node-fetch-interface
  • d7a6577 feat: mock node-fetch's export pattern
  • 3500688 Merge pull request #526 from pabloosso/patch-1
  • 8c231ac Fixed typo
  • e25f30a Merge pull request #525 from willheslam/patch-1
  • 5817bbf Fix typo in mock_response.md
  • 41b238f Update cheatsheet.md
  • aa8311e Update cheatsheet.md

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Add badges

Build badges etc, as required via the internal wiki checklist

AnalyticsSDKError is missing the actual error

Expected Behaviour

In case of an error, we should see the complete response body in the stacktrace of the AnalyticsSDKError, to know what needs to be fixed in the request.

Actual Behaviour

The response object is not stringified when passed to the ErrorWrapper of aio-lib-core-errors, resulting in only having response: [Object] in the stacktrace, hiding the important info.

Reproduce Scenario (including but not limited to)

  • call the getReport method with a body containing an invalid dateRange (e.g. without striping the timezone char Z)

(the problem is present on all methods)

Steps to Reproduce

  • Run the script provided below

Platform and Version

2.1.0

Sample Code that illustrates the problem

const auth = require('@adobe/jwt-auth');
const analyticsCoreAPI = require('@adobe/aio-lib-analytics');

// Complete those info before running the script
const credentials = {
  clientId: '',
  technicalAccountId: '@techacct.adobe.com',
  orgId: '@AdobeOrg',
  clientSecret: '',
  metaScopes: 'ent_analytics_bulk_ingest_sdk',
  privateKey: `-----BEGIN PRIVATE KEY----- -----END PRIVATE KEY-----`,
};
const companyId = '';
const rsid = '';

async function getReport() {
  const authResponse = await auth(credentials);
  const analyticsClient = await analyticsCoreAPI.init(
    companyId,
    credentials.clientId,
    authResponse.access_token
  );
  const today = new Date();
  const ndaysago = new Date(Date.now() - 7 * 24 * 60 * 60 * 1000);
  const dateRange = `${ndaysago.toISOString()}/${today.toISOString()}`;
  const body = {
    rsid,
    globalFilters: [{ type: 'dateRange', dateRange }],
    metricContainer: {
      metrics: [{ id: 'metrics/pageviews' }],
    },
    dimension: 'variables/page',
  };
  try {
    await analyticsClient.getReport(body);
  } catch (e) {
    console.log(e);
  }
}

getReport();

Logs taken while reproducing problem

AioCoreSDKError [AnalyticsSDKError]: [AnalyticsSDK:ERROR_GET_REPORT] Error: Bad Request
    at http (/tmp/node_modules/swagger-client/lib/http.js:106:19)
    at processTicksAndRejections (internal/process/task_queues.js:93:5) {
  status: 400,
  statusCode: 400,
  response: [Object]
}
    at new <anonymous> (/tmp/node_modules/@adobe/aio-lib-core-errors/src/AioCoreSDKErrorWrapper.js:33:9)
    at /tmp/node_modules/@adobe/aio-lib-analytics/src/index.js:358:18
    at processTicksAndRejections (internal/process/task_queues.js:93:5) {
  code: 'ERROR_GET_REPORT',
  sdk: 'AnalyticsSDK',
  sdkDetails: {
    rsid: 'somereportsuiteid',
    globalFilters: [ [Object] ],
    metricContainer: { metrics: [Array] },
    dimension: 'variables/page'
  }
}

Possible solution

An quick fix is to stringify the response when rejecting the error:
https://github.com/adobe/aio-lib-analytics/blob/master/src/index.js#L357

- reject(new codes.ERROR_GET_REPORT({ sdkDetails, messageValues: err }))
+ const messageValues = {
+   ...err,
+   response: JSON.stringify(err.response),
+ }
+ reject(new codes.ERROR_GET_REPORT({ sdkDetails, messageValues }))

An in-range update of eslint-plugin-jest is breaking the build 🚨

The devDependency eslint-plugin-jest was updated from 23.1.0 to 23.1.1.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

eslint-plugin-jest is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details

Release Notes for v23.1.1

23.1.1 (2019-11-30)

Bug Fixes

  • no-focused-tests: detect table format uage of .only.each (#489) (d03bcf4)
Commits

The new version differs by 2 commits.

  • 6ffb998 chore(release): 23.1.1 [skip ci]
  • d03bcf4 fix(no-focused-tests): detect table format uage of .only.each (#489)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Analytics SDK get calls failing with swagger client update

Error for GET calls - ' Request with GET/HEAD method cannot have body'
This is because of swagger client update to 3.10.12

Expected Behaviour

Actual Behaviour

Reproduce Scenario (including but not limited to)

Steps to Reproduce

Platform and Version

Sample Code that illustrates the problem

Logs taken while reproducing problem

Analytics client initialization issue

Expected Behaviour

Ability to make a call using the aio-lib-analytics and establish connectivity to Analytics via that library.

Actual Behaviour

When running the code below (in the sample code), we both receive a "Swagger is not a constructor" error:
image

Reproduce Scenario (including but not limited to)

We can consistently reproduce the issue by calling the default sdk.init function. Since that step is unsuccessful we cannot get any further with it.

Steps to Reproduce

We can consistently replicate this by simply loading the sample code in our sample Firefly app - we were adding it to the Home.js. The same issue happens if we load this same code in our more well-developed prototype.

Environment Info

  System:
    OS: Windows 10 10.0.19042
    CPU: (8) x64 Intel(R) Core(TM) i7-1065G7 CPU @ 1.30GHz
    Memory: 3.73 GB / 15.60 GB
  Binaries:
    Node: 14.16.0 - C:\Bitnami\wampstack8\apache2\node.EXE
    Yarn: 1.22.10 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 7.10.0 - C:\Bitnami\wampstack8\apache2\npm.CMD
  Virtualization:
    Docker: 20.10.5 - C:\ProgramData\DockerDesktop\version-bin\docker.EXE
  npmGlobalPackages:
    @adobe/aio-cli: Not Found

Sample Code that illustrates the problem

import React from 'react'
import { Heading, View } from '@adobe/react-spectrum'
const sdk = require('@adobe/aio-lib-analytics')
const company = 'test'
const apiKey = 'test key'
const token = 'test token'
const rsid = 'test rsid'
async function initAnalyticsSDK (){
    sdkClient = await sdk.init(company, apiKey, token)
    // any sdk call here
}
initAnalyticsSDK()
.then(res => {
  console.log(res)
})
.catch(e => {
  console.log(e)
})

export const Home = () => (

  <View width='size-6000'>
    <Heading level={1}>Welcome to gcoeProjectHexagon!</Heading>
  </View>
)

Logs taken while reproducing problem

I don't have any logs at the moment by can try and retrieve them later if necessary.

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.