Skip to content

Commit 72c9285

Browse files
authored
Merge pull request #195 from narusevic/master
Update Analytics pull request
2 parents 2cff2f6 + e2f1657 commit 72c9285

25 files changed

+334
-618
lines changed

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ NativeScript : Facebook SDK ![apple](https://cdn3.iconfinder.com/data/icons/pico
4646
- [Hide Custom Button If Can't share](#hide-custom-button-1)
4747
- [Login Response](#login-response)
4848
- [Get Current Access Token](#get-current-access-token)
49+
- [Basic Analytics](#basic-analytics)
4950
- [Graph API Example](#graph-api-example)
5051
- [Release notes](#release-notes)
5152
- [FAQ](#faq)
@@ -595,6 +596,34 @@ The callback that have to be provided to Facebook.login method receives 2 argume
595596
## Get Current Access Token
596597
The plugin allows to get the current access token, if any, via getCurrentAccessToken() method.
597598

599+
## Basic Analytics
600+
The plugin allows to log analytics events. At the initialization of the application you need to init analytics:
601+
602+
```Typescript
603+
application.on(application.launchEvent, function (args) {
604+
nsFacebook.init("{facebook_app_id}");
605+
nsFacebook.initAnalytics();
606+
});
607+
```
608+
609+
Events logging:
610+
611+
```Typescript
612+
nsFacebook.logEvent('Lead');
613+
```
614+
615+
Logging event with parameters:
616+
617+
```Typescript
618+
const value = 5;
619+
const parameters = [{
620+
key: 'value',
621+
value: value.toString(),
622+
}];
623+
624+
nsFacebook.logEvent(FundsAdded, parameters);
625+
```
626+
598627
## Graph API Example
599628
Once the Facebook access token is retrieved you can execute Graph API requests. In the example below after successful login, the access token is stored in application settings. And then on the home view it is retrieved and 2 Graph API calls are executed.
600629
1. Get Facebook id of the logged in user

demo-angular/app/app.module.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@ import { NgModule, NO_ERRORS_SCHEMA } from "@angular/core";
22
import { NativeScriptModule } from "nativescript-angular/nativescript.module";
33
import { NativeScriptRouterModule } from "nativescript-angular/router";
44
import { AppComponent } from "./app.component";
5-
import { LoginModule } from "./pages/login/login.module";
6-
import { HomeModule } from "./pages/home/home.module";
75
import { NativeScriptFacebookModule } from "nativescript-facebook/angular";
86
import * as application from 'tns-core-modules/application';
97
import { routes } from "./app.routing";
108
import { NavigationService } from "./services/navigation.service";
11-
import { init, LoginBehavior } from "nativescript-facebook";
9+
import { init, initAnalytics } from "nativescript-facebook";
1210

1311
application.on(application.launchEvent, function (args) {
14-
init("1771472059772879", LoginBehavior.LoginBehaviorWeb);
12+
init("1771472059772879");
13+
initAnalytics();
1514
});
1615

1716
@NgModule({

demo-vue/app/app.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Login from "./components/Login";
44

55
import {
66
init,
7-
LoginBehavior
7+
initAnalytics,
88
} from 'nativescript-facebook';
99

1010
import FacebookPlugin from "nativescript-facebook/vue";
@@ -13,7 +13,8 @@ Vue.use(FacebookPlugin);
1313
Vue.config.silent = true;
1414

1515
application.on(application.launchEvent, function (args) {
16-
init("1771472059772879", LoginBehavior.LoginBehaviorWeb);
16+
init("1771472059772879");
17+
initAnalytics();
1718
});
1819

1920
new Vue({

demo-vue/app/components/Home.vue

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@
1212
<FacebookLoginButton @logout="onLogout"></FacebookLoginButton>
1313
<Button @tap="logout" text="Log out (Custom)"></Button>
1414
<Button @tap="getAccessToken" text="Get current access token"></Button>
15+
<Button @tap="logEventAction" text="Log event"></Button>
1516
</StackLayout>
1617
</StackLayout>
1718
</Page>
1819
</template>
1920

2021
<script>
21-
import { logout as fbLogout, getCurrentAccessToken } from "nativescript-facebook";
22+
import { logout as fbLogout, getCurrentAccessToken, logEvent } from "nativescript-facebook";
2223
import Login from "./Login";
2324
let appSettings = require("tns-core-modules/application-settings");
2425
let http = require("tns-core-modules/http");
@@ -64,6 +65,12 @@
6465
getAccessToken: function() {
6566
let accessToken = getCurrentAccessToken();
6667
alert("Current access token: " + JSON.stringify(accessToken, null, '\t'));
68+
},
69+
logEventAction() {
70+
logEvent('Initial', [{
71+
key: 'number',
72+
value: '',
73+
}]);
6774
}
6875
}
6976
};

demo-vue/app/components/Login.vue

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<Button @tap="onShareDialogPhotos" text="Open Share dialog (photos)" :visibility="canShowPhotosShareDialog ? 'visible' : 'collapsed'"></Button>
1616
<Button @tap="onSendDialog" text="Share Message (link)" :visibility="canShowLinksMessageDialog ? 'visible' : 'collapsed'"></Button>
1717
<Button @tap="onSendGenericDialog" text="Share Message (generic)" :visibility="canShowGenericMessageDialog ? 'visible' : 'collapsed'"></Button>
18+
<Button @tap="logEventAction" text="Log event"></Button>
1819
</StackLayout>
1920
</Page>
2021
</template>
@@ -34,7 +35,8 @@
3435
showShareDialog,
3536
showMessageDialog,
3637
canShareDialogShow,
37-
canMessageDialogShow
38+
canMessageDialogShow,
39+
logEvent
3840
} from 'nativescript-facebook';
3941
let appSettings = require('tns-core-modules/application-settings');
4042
@@ -139,6 +141,12 @@
139141
},
140142
onSendGenericDialog: function() {
141143
showMessageDialog(this.genericContent);
144+
},
145+
logEventAction() {
146+
logEvent('Initial', [{
147+
key: 'number',
148+
value: '',
149+
}]);
142150
}
143151
}
144152
};

demo-vue/e2e/test.e2e.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ describe("Facebook tests", async function () {
7777
await driver.wait(1000);
7878
await allFields[0].sendKeys(USERNAME);
7979
} else {
80+
const continueBtn = await driver.findElementByText("Continue");
81+
await continueBtn.click();
82+
8083
const passField = await driver.findElementByClassName(driver.locators.getElementByName("securetextfield"));
8184
await passField.click();
8285
await passField.sendKeys(PASSWORD);

demo/app/app.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import * as application from 'tns-core-modules/application';
2-
import { init, LoginBehavior } from "nativescript-facebook";
2+
import { init, initAnalytics } from "nativescript-facebook";
33

44
application.on(application.launchEvent, function (args) {
5-
init("1771472059772879", LoginBehavior.LoginBehaviorWeb);
5+
init("1771472059772879");
6+
initAnalytics();
67
});
78

89
application.run({ moduleName: "app-root" });

demo/app/home-page.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<Facebook:LoginButton logout="{{ onLogout }}"></Facebook:LoginButton>
1414
<Button automationText="customLogOut" tap="{{ logout }}" text="Log out (Custom)"></Button>
1515
<Button automationText="getCurrentAccessToken" tap="{{ getCurrentAccessToken }}" text="Get current access token"></Button>
16+
<Button tap="{{ logEventAction }}" text="Log Event"></Button>
1617
</StackLayout>
1718
</StackLayout>
1819
</Page>

demo/app/home-view-model.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Observable } from 'tns-core-modules/data/observable';
2-
import { LoginEventData, logout as fbLogout, getCurrentAccessToken } from "nativescript-facebook";
2+
import { LoginEventData, logout as fbLogout, logEvent, getCurrentAccessToken } from "nativescript-facebook";
33

44
let frameModule = require("tns-core-modules/ui/frame");
55
let appSettings = require("tns-core-modules/application-settings");
@@ -56,4 +56,11 @@ export class HomeViewModel extends Observable {
5656

5757
alert("Current access token: " + JSON.stringify(accessToken, null, '\t'));
5858
}
59+
60+
public logEventAction() {
61+
logEvent('Initial', [{
62+
key: 'number',
63+
value: '',
64+
}]);
65+
}
5966
}

demo/app/login-page.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@
1212
<Button tap="{{ onShareDialogPhotos }}" text="Open Share dialog (photos)" visibility="{{ canShowPhotosShareDialog ? 'visible' : 'collapsed' }}"></Button>
1313
<Button tap="{{ onSendDialog }}" text="Open Message Share dialog" visibility="{{ canShowLinksMessageDialog ? 'visible' : 'collapsed' }}"></Button>
1414
<Button tap="{{ onSendGenericDialog }}" text="Share Message Generic Template" visibility="{{ canShowGenericMessageDialog ? 'visible' : 'collapsed' }}"></Button>
15+
<Button tap="{{ logEventAction }}" text="Log Event"></Button>
1516
</StackLayout>
1617
</Page>

0 commit comments

Comments
 (0)