Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Importing tracking.js into an angular project

  1. I have downloaded tracking.js and added it to my /src/assets folder

  2. In my angular-cli.json file I have added to my scripts:

"scripts": [ "../src/assets/tracking/build/tracking-min.js" ],

  1. issue here - In my angular component, I import tracking as follows:

import tracking from 'tracking';

and in the chrome inspection window I can hover over 'tracking' and see all of the properties as shown:

enter image description here

I can even call the ColorImage constructor in the console window! :

enter image description here

However when it tries to execute the constructor in my code I get the error about tracking being undefined: enter image description here

I had assumed it was because I wasn't passing in the tracking object through the constructor in the traditional DI fashion, but when doing so I got the error that the namespace couldn't be used as a type: enter image description here

The only other thing I could think of was to try and add the external reference in the main index.html file, but I got an error about strict MIME checking.

To clarify: this is all happening in my angular component constructor (when the tracking methods get exercised)

Any ideas?

like image 701
asdf Avatar asked Jul 22 '26 19:07

asdf


1 Answers

go to your node_modules folder and find this file : "node_modules/tracking/build/tracking.js" . open the file and add this line of code to end of the file :

module.exports = window.tracking

save file and in use this code to import it :

import * as tracking from 'tracking';
like image 62
Soroush Avatar answered Jul 24 '26 07:07

Soroush