1598286180
In this post, we will be looking into how we can add import aliases to our gatsby site step by step.
The reason why we are setting up import aliases is more to do about readability and the look of our code when importing components from the import tree.
What I mean by that, is if we look at the following example
import Subscribe from '../../../../../../../core/modules/newsletter/mixins/Subscribe'
This just looks downright ugly in my opinion, so how can we improve it?
We can do that by updating webpack config to include aliases for our main directories that we know are going to be the base for our components.
Once we go through all the steps from this post, the end results will look like the following below
import Subscribe from '@core/modules/newsletter/mixins/Subscribe'
Given that Gatsby uses Webpack as its core and does not expose the config by default, we can add custom Webpack config using Gatsby’s onCreateWebpackConfig
API, this will result in the custom configs being merged allowing you to modify the default webpack config.
To add the custom webpack config we need to edit (or create the file if it doesn’t exist in the root of our project) gatsby-node.js
and add the new configs into it.
const path = require("path");
exports.onCreateWebpackConfig = ({ actions }) => {
actions.setWebpackConfig({
resolve: {
alias: {
"@components": path.resolve(__dirname, "src/components"),
"@static": path.resolve(__dirname, "static")
}
}
});
}
As we can see in the above snippet, actions object give us the option to use setWebpackConfig
that takes our custom webpack config and merge it to Gatsby’s webpack config.
In order to add new aliases, we are going to use webpack’s resolve alias which will allow us to use the newly created import aliased inside our components.
As you can see below, the end result after adding the new alias will look like this
import Layout from '@components/Layout';
#gatsbyjs #react #programming #webpack #javascript
1629087600
WebEngage Flutter SDK
For more information checkout our website and documentation.
Add WebEngage Flutter Plugin
dependencies:
webengage_flutter: 1.0.3
WebEngagePlugin _webEngagePlugin = new WebEngagePlugin();
...
import com.webengage.sdk.android.WebEngageActivityLifeCycleCallbacks;
import io.flutter.app.FlutterApplication;
public class MainApplication extends FlutterApplication {
@Override
public void onCreate() {
super.onCreate();
WebEngageConfig webEngageConfig = new WebEngageConfig.Builder()
.setWebEngageKey("YOUR_LICENCSE_CODE")
.setAutoGCMRegistrationFlag(false)
.setLocationTrackingStrategy(LocationTrackingStrategy.ACCURACY_BEST)
.setDebugMode(true) // only in development mode
.build();
WebengageInitializer.initialize(this,webEngageConfig);
...
}
...
}
implementation platform('com.google.firebase:firebase-bom:25.12.0')
implementation 'com.google.firebase:firebase-analytics'
implementation 'com.google.firebase:firebase-messaging:20.2.1'
implementation 'com.google.android.gms:play-services-ads:15.0.1'
classpath 'com.google.gms:google-services:4.3.4'
import com.google.firebase.messaging.FirebaseMessagingService;
import com.webengage.sdk.android.WebEngage;
public class MyFirebaseMessagingService extends FirebaseMessagingService {
@Override
public void onNewToken(String s) {
super.onNewToken(s);
WebEngage.get().setRegistrationID(s);
}
}
It is also recommended that you pass Firebase token to WebEngage from onCreate of your Application class as shown below. This will ensure that changes in user’s Firebase token are communicated to WebEngage.
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.firebase.iid.FirebaseInstanceId;
import com.google.firebase.iid.InstanceIdResult;
import com.webengage.sdk.android.WebEngage;
public class MainApplication extends FlutterApplication {
@Override
public void onCreate() {
super.onCreate();
FirebaseMessaging.getInstance().getToken()
.addOnCompleteListener(new OnCompleteListener<String>() {
@Override
public void onComplete(@NonNull Task<String> task) {
if (!task.isSuccessful()) {
Log.w(TAG, "Fetching FCM registration token failed", task.getException());
return;
}
// Get new FCM registration token
String token = task.getResult();
WebEngage.get().setRegistrationID(token);
}
});
}
}
package your.application.package;
import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;
import com.webengage.sdk.android.WebEngage;
public class MyFirebaseMessagingService extends FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Map<String, String> data = remoteMessage.getData();
if(data != null) {
if(data.containsKey("source") && "webengage".equals(data.get("source"))) {
WebEngage.get().receive(data);
}
}
}
}
Next, register the service to the application element of your AndroidManifest.xml as follows.
<service
android:name=".MyFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
<dict>
<key>WEGLicenseCode</key>
<string>YOUR-WEBENGAGE-LICENSE-CODE</string>
<key>WEGLogLevel</key>
<string>VERBOSE</string>
...
</dict>
#import <WebEngage/WebEngage.h>
...
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary * launchOptions {
...
[[WebEngage sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions];
return [super application:application didFinishLaunchingWithOptions:launchOptions];
}
@end
Push Notification Callbacks
#import <WebEngagePlugin.h>
@property (nonatomic, strong) WebEngagePlugin *bridge;
self.bridge = [WebEngagePlugin new];
//For setting push click callback set pushNotificationDelegate after webengage SDK is initialised
[[WebEngage sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions notificationDelegate:self.bridge];
[WebEngage sharedInstance].pushNotificationDelegate = self.bridge;
void subscribeToPushCallbacks() {
//Push click stream listener
_webEngagePlugin.pushStream.listen((event) {
String deepLink = event.deepLink;
Map<String, dynamic> messagePayload = event.payload;
});
//Push action click listener
_webEngagePlugin.pushActionStream.listen((event) {
print("pushActionStream:" + event.toString());
String deepLink = event.deepLink;
Map<String, dynamic> messagePayload = event.payload;
});
}
//Close the streams in dispose()
@override
void dispose() {
_webEngagePlugin.pushSink.close();
_webEngagePlugin.pushActionSink.close();
super.dispose();
}
Universal Link
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray<id<UIUserActivityRestoring>> * _Nullable))restorationHandler {
[[[WebEngage sharedInstance] deeplinkManager] getAndTrackDeeplink:userActivity.webpageURL callbackBlock:^(id location){
[self.bridge trackDeeplinkURLCallback:location];
}];
return YES;
}
void subscribeToTrackUniversalLink() {
_webEngagePlugin.trackDeeplinkStream.listen((location) {
print("trackDeeplinkStream: " + location);
});
}
//Close the streams in dispose()
@override
void dispose() {
_webEngagePlugin.trackDeeplinkURLStreamSink.close();
super.dispose();
}
import 'package:webengage_flutter/webengage_flutter.dart';
...
// User login
WebEngagePlugin.userLogin('3254');
// User logout
WebEngagePlugin.userLogout();
// Set user first name
WebEngagePlugin.setUserFirstName('John');
// Set user last name
WebEngagePlugin.setUserLastName('Doe');
// Set user email
WebEngagePlugin.setUserEmail('john.doe@gmail.com');
// Set user hashed email
WebEngagePlugin.setUserHashedEmail('144e0424883546e07dcd727057fd3b62');
// Set user phone number
WebEngagePlugin.setUserPhone('+551155256325');
// Set user hashed phone number
WebEngagePlugin.setUserHashedPhone('e0ec043b3f9e198ec09041687e4d4e8d');
// Set user company
WebEngagePlugin.setUserCompany('WebEngage');
// Set user birth-date, supported format: 'yyyy-MM-dd'
WebEngagePlugin.setUserBirthDate('1994-05-24');
// Set user gender, allowed values are ['male', 'female', 'other']
WebEngagePlugin.setUserGender('male');
// Set user channel opt-in status
WebEngagePlugin.setUserOptIn('in_app', false);
// Set user location
WebEngagePlugin.setUserLocation(19.25, 72.45);
// Set User Attribute with String value
WebEngagePlugin.setUserAttribute("twitterusename", "saurav12994");
// Set User Attribute with Boolean value
WebEngagePlugin.setUserAttribute("Subscribed to email", true);
// Set User Attribute with Integer value
WebEngagePlugin.setUserAttribute("Points earned", 2626);
// Set User Attribute with Double value
WebEngagePlugin.setUserAttribute("Dollar Spent", 123.44);
// Set User Attribute with Map value
var details = {'Usrname':'tom','Passiword':'pass@123'};
WebEngagePlugin.setUserAttributes(details);
import 'package:webengage_flutter/webengage_flutter.dart';
...
// Track simple event
WebEngagePlugin.trackEvent('Added to Cart');
// Track event with attributes
WebEngagePlugin.trackEvent('Order Placed', {'Amount': 808.48});
import 'package:webengage_flutter/webengage_flutter.dart';
...
// Track screen
WebEngagePlugin.trackScreen('Home Page');
// Track screen with data
WebEngagePlugin.trackScreen('Product Page', {'Product Id': 'UHUH799'});
#import <WebEngagePlugin.h>
@property (nonatomic, strong) WebEngagePlugin *bridge;
self.bridge = [WebEngagePlugin new];
//For setting in-app click callback set notificationDelegate while initialising WebEngage SDK
[[WebEngage sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions notificationDelegate:self.bridge];
void _onInAppPrepared(Map<String, dynamic> message) {
print("This is a inapp Prepated callback from native to flutter. Payload " +
message.toString());
}
void _onInAppClick(Map<String, dynamic> message,String s) {
print("This is a inapp click callback from native to flutter. Payload " +
message.toString());
}
void _onInAppShown(Map<String, dynamic> message) {
print("This is a callback on inapp shown from native to flutter. Payload " +
message.toString());
}
void _onInAppDismiss(Map<String, dynamic> message) {
print("This is a callback on inapp dismiss from native to flutter. Payload " +
message.toString());
}
_webEngagePlugin.setUpInAppCallbacks(
_onInAppClick, _onInAppShown, _onInAppDismiss, _onInAppPrepared);
Reach out to our Support Team for further assistance.
Run this command:
With Flutter:
$ flutter pub add webengage_flutter
This will add a line like this to your package's pubspec.yaml (and run an implicit dart pub get):
dependencies:
webengage_flutter: ^1.0.3
Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.
Now in your Dart code, you can use:
import 'package:webengage_flutter/webengage_flutter.dart';
1625009220
The Python import system is pretty straightforward… to a point. Importing code present in the same directory you’re working in is very different from importing between multiple files present in multiple directories. Through this post, I try to analyse the different import scenarios that one might encounter, hopefully making it easier to create your own packages.
An Example
What Happens When You Import a Python File?
Terminology
Import Scenarios
Analysis
Building a Package
The Syntax of Your Import Statement
Notes and Resources
#machine-learning #python #software-development #how imports work in python #imports work #imports
1625057520
As 2021 initiates, customers have sky-high expectations with regards to their experiences with each business they associate with: retail brands, utility services, and even their banks. It’s anticipated that these organizations should envision our necessities, know what our identity is, and consistently be important. Basically, we need organizations to read our thoughts. While this is incomprehensible and unreasonable, organizations can make progress by enriching their customer data to improve their customer experience.
Having access to the same volunteered data your rivals have, you don’t have a lot of favorable advantages over them. To improve and get more profound information, you can utilize data enrichment.
Data enrichment is a process that can transform the data you have into a total profile that precisely maps the requirements of your leads.
#big data #latest news #the growing need and importance of data enrichment #data enrichment #importance #importance of data enrichment
1622608201
In this post i will show you Laravel 8 Import Export CSV/EXCEL File Example. We will simple create import data to xls, csv file and also we will import data to database using csv file in laravel 8 application.
Using this example we can easily import-export and download the csv & excel file from the database using the maatwebsite/excel composer package. maatwebsite/excel provide easy way to import and export csv file in laravel 8 using database model.
#laravel 8 import export csv/excel file example #laravel 8 #import #export #csv/excel #import and export csv file in laravel 8
1626645300
Setup Gatsby filesystem to make sure Gatsby is aware of application local files so you can access them via GraphQL.
This is a single video in a series of 26 lessons. Watch the entire course at this playlist here: https://www.youtube.com/playlist?list=PLW0RabRDhwwzVNhlOgQQgw6HJzXdM1MnT
Want to support the channel? We make our courses free to watch so anyone can access our content and level up their skills. For our larger courses, like this one, we sell the final code and design files for a small price to help support the creation of free educational content like this.
You can purchase the course files below–any support is greatly appreciated!
#WebDev #WebDesign #WebDevelopment
#gatsby js #gatsby #js #webdev